通过媒体响应实现获取尝试播放播客剧集MP3的错误消息

问题描述 投票:0回答:1

我正在尝试播放播客的mp3剧集,并根据此页面上有关媒体响应的说明添加图片。 https://developers.google.com/actions/assistant/responses#media_responses

错误与云功能有关,如下所示。

    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上的炬新手,我不知道从哪里开始排除故障。我的理解是,我可以使用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);
google-cloud-functions dialogflow actions-on-google
1个回答
1
投票

如堆栈跟踪所示:

Detailed stack trace: ReferenceError: conv is not defined

conv作为对象仅存在于app.intent的范围内,作为回调的一部分。

作为初始webhook设置的一部分,您在该范围之外调用conv.ask。任何会话位都应该封装在app.intent中,这样它们只有在触发给定意图时才会运行。在这里,您可以看到您的代码段已移至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',
         }),
     }));
})
© www.soinside.com 2019 - 2024. All rights reserved.