如何使用Dialogflow实施媒体响应

时间:2019-01-03 23:40:29

标签: dialogflow actions-on-google google-home

我正在使用Dialogflow,并希望在我的项目中实现媒体响应。我尝试使用以下链接进行此操作:https://developers.google.com/actions/assistant/responses,但未成功。如何执行?

const functions = require('firebase-functions')
const {dialogflow} = require('actions-on-google')

const TEST = 'test'

const app = dialogflow({
    debug: true,
})

app.intent('test', (conv) =>{
    conv.ask('we will now play a song for you');

    conv.ask(new MediaObject({
        name: 'Jazz in Paris',
        url: 'https://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3',
    }));
    conv.ask(new MediaResponse({
        mediaObject: 'Jazz in Paris',
        mediaType: AUDIO,
    }));
});


exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app)

1 个答案:

答案 0 :(得分:0)

您只需要添加MediaObject。您不需要添加MediaResponse对象,因为库会为您添加它。

但是,您需要确保在调用MediaObject的过程中加载require()对象。您还需要加载Suggestions对象,因为如果用户选择中断您的音频,则需要提供建议以推进对话。

因此您的代码可以如下所示:

const functions = require('firebase-functions')
const {
  dialogflow,
  MediaObject,
  Suggestions
} = require('actions-on-google')

const app = dialogflow({
    debug: true,
})

app.intent('test', (conv) =>{
    conv.ask('we will now play a song for you');

    conv.ask(new MediaObject({
        name: 'Jazz in Paris',
        url: 'https://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3',
    }));

    conv.ask(new Suggestions(['suggestion 1', 'suggestion 2']));

});


exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app)