Handle audio play completion callback in dialogflow (Media responses)

假如想象 提交于 2019-12-10 18:38:51

问题


I'm handling an intent by playing a MediaObject. I want to create an intent handler that will catch the callback of media play completion, the documentation shows an example on how to write fulfillment code to handle it.

Building your fulfillment

The code snippet below shows how you might write the fulfillment code for your Action. If you're using Dialogflow, replace actions.intent.MEDIA_STATUS with the action name specified in the intent which receives the actions_intent_MEDIA_STATUS event, (for example, "media.status.update“).

I am confused with the part of the dialogflow instructions. The intent that I handle and return a MediaObject is called smoothie-02 and I have a fallback for it which what gets handled after the media finishes being played, but I want to create another intent and handle it there instead. What I want to do is to create a new intent that would handle it, instead of it going to the fallback intent of smoothie-02 intent.

smoothie-02 handler

app.dialogFlow.intent('smoothie-02', (conv) => {
    const welcomeContext = getConvContext(conv, AppContexts.WELCOME);

    givenName = welcomeContext.parameters['given-name'];
    fruitTypes = welcomeContext.parameters['FruitTypes'];

    if (!conv.surface.capabilities.has('actions.capability.MEDIA_RESPONSE_AUDIO')) {
        conv.ask('Sorry, this device does not support audio playback.');
        return;
    }

    conv.contexts.set("actions_capability_media_response_audio", 5);

    // Zoe says something
    let response = `Ooh good choice ${givenName} ! `;
    response += fruitTypes.length > 1 ? `${fruitTypes[0]} and ${fruitTypes[1]}` : `${fruitTypes[0]} `;
    response += `${drinkType} ` ;
    response +=  'coming right up. But will you first turn me on?';
    console.log(response);

    conv.ask(response);

    conv.ask(new Suggestions("Don't be shy"));

    // Blender plays
    conv.ask(new MediaObject({
        name: 'Blender Sound',
        url: 'https://storage.googleapis.com/zoe-mortimer.appspot.com/blender.wav',
    }));
});

回答1:


What I needed to do is create a new intent and add actions_intent_MEDIA_STATUS in the Events, and that will be the intent that would handle the media playback finished callback. Credits to this article!



来源:https://stackoverflow.com/questions/52736247/handle-audio-play-completion-callback-in-dialogflow-media-responses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!