google-cloud-functions - 尝试通过媒体响应履行来播放播客剧集的 MP3 时收到错误消息
问题描述
我正在尝试播放我的播客的 mp3 剧集,并根据此页面上有关媒体响应的说明包含图形。 https://developers.google.com/actions/assistant/responses#media_responses
这些错误与 Cloud Function 有关,如下所示。
The deployment of your Cloud Function failed:
Function load error: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: ReferenceError: conv is not defined
at Object.<anonymous> (/user_code/index.js:8:6)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at getUserFunction (/var/tmp/worker/worker.js:391:24)
at loadUserCode (/var/tmp/worker/worker.js:447:18)
我是 Actions on Google 的新手,不知道从哪里开始解决此问题。据我了解,我可以使用 Fulfillment 中的内联编辑器调用和播放此文件。
下面是我目前在内联编辑器中的代码。
非常感谢任何关于从这里去哪里的意见。谢谢道格
'use strict';
const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');
const app = dialogflow({debug: true});
if (!conv.surface.capabilities.has('actions.capability.MEDIA_RESPONSE_AUDIO')) {
conv.ask('Sorry, this device does not support audio playback.');
return;
}
conv.ask(new MediaObject({
name: 'The Wiggins Personality Model',
url: 'https://storage.googleapis.com/voicemarketing-assets02/v01/media/Ep001-VoiceMarketing-WigginsPersonalityModel.mp3',
description: 'How Clifford Nass used the Wiggins Personality Model for voice.',
icon: new Image({
url: 'https://storage.googleapis.com/voicemarketing-assets02/v01/media/Ep001-VoiceMarketing-EpKeyart-1400x933-brain.png',
alt: 'Media icon',
}),
}));
app.intent('play.episode', (conv) => {
const mediaStatus = conv.arguments.get('MEDIA_STATUS');
let response = 'Unknown media status received.';
if (mediaStatus && mediaStatus.status === 'FINISHED') {
response = 'Hope you enjoyed the tunes!';
}
conv.ask(response);
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
解决方案
如堆栈跟踪所示:
Detailed stack trace: ReferenceError: conv is not defined
conv
as 对象仅存在于您的 , 范围内app.intent
,作为回调一部分的对象。
作为初始 webhook 设置的一部分,您正在调用conv.ask
该范围之外的内容。任何对话位都应封装在app.intent
其中,以便它们仅在触发给定意图时运行。在这里,您可以看到您的代码段已移至意图处理程序中。
app.intent('play-media', conv => {
if (!conv.surface.capabilities.has('actions.capability.MEDIA_RESPONSE_AUDIO')) {
conv.ask('Sorry, this device does not support audio playback.');
return;
}
conv.ask(new MediaObject({
name: 'The Wiggins Personality Model',
url: 'https://storage.googleapis.com/voicemarketing-assets02/v01/media/Ep001-VoiceMarketing-WigginsPersonalityModel.mp3',
description: 'How Clifford Nass used the Wiggins Personality Model for voice.',
icon: new Image({
url: 'https://storage.googleapis.com/voicemarketing-assets02/v01/media/Ep001-VoiceMarketing-EpKeyart-1400x933-brain.png',
alt: 'Media icon',
}),
}));
})
推荐阅读
- php - 将 Woocommerce 订阅更新和同步到自定义日期
- javascript - 如何在 createPortal 函数中将道具传递给孩子
- sql - SQL INNER JOIN 错误 - 无法连接两个表:“获取表的架构时出现问题。再试一次。”
- discord.py - 如何将 3 个 on_message 函数组合成 1 个 on_message 函数
- c - 我不知道如何链接多个文件
- kotlin - 类头中的属性与类主体中的属性
- python - 替换元组字典的最佳结构
- php - get_users 不会搜索 users.php 上的所有用户
- python-3.x - 分句不分域名
- reactjs - 在 NestJS 中连接后,Socket.io 客户端正在断开连接