处理对话流中的音频播放完成回调(媒体响应)

Handle audio play completion callback in dialogflow (Media responses)

我正在通过播放 MediaObject 来处理意图。我想创建一个意图处理程序来捕获媒体播放完成的回调,documentation 显示了一个关于如何编写实现代码来处理它的示例。

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“).

我对 dialogflow 说明的部分感到困惑。我处理的意图和 return 一个 MediaObject 被称为 smoothie-02 并且我有一个回退它在媒体完成播放后处理什么,但我想创建另一个意图并在那里处理它.我想要做的是创建一个新的意图来处理它,而不是它进入 smoothie-02 意图的后备意图。

smoothie-02 处理程序

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',
    }));
});

我需要做的是创建一个新的意图并在事件中添加 actions_intent_MEDIA_STATUS,这将是处理媒体播放完成回调的意图。归功于 this article!