尝试使用媒体响应实现播放播客剧集的 MP3 时收到错误消息

Getting error messages trying to play MP3 of podcast episode with a Media Response Fulfillment

我正在尝试播放我播客的 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)

我是 Google 上的 Actions 新手,不知道从哪里开始解决这个问题。据我了解,我可以使用 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 作为对象仅存在于您的 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',
         }),
     }));
})