简体   繁体   中英

How to close conversation from the webhook in @assistant/conversation

I want to close the conversation after the media started playing in @assistant/conversation. As I am doing here

app.intent("media", conv => {
    conv.ask(`Playing your Radio`);
    conv.ask(
        new MediaObject({
            url: ""
        })
    );
    return conv.close(new Suggestions(`exit`));
});

As Jordi had mentioned, suggestion chips cannot be used to close a conversation. Additionally, the syntax of the @assistant/conversation is different from actions-on-google . As you're using the tag dialogflow-es-fulfillment but also actions-builder , I really don't know which answer you want. As such, I'm going to put two answers depending on which you're using.

Dialogflow

If you are using Dialogflow, you are pretty much set. You should switch to using actions-on-google and instantiate the dialogflow constant.

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

Actions Builder

The syntax of the @assistant/conversation lib is different. Some method names are different. Additionally, you will need to go through Actions Builder to canonically close the conversation.

In your scene, you will need to transition the scene to End Conversation to close, rather than specifying it as part of your response. Still, your end transition should not have suggestion chips.

在此处输入图像描述

You will need to refactor your webhook:

const {conversation} = require('@assistant/conversation')
const app = conversation()

app.handle("media", conv => {
    conv.add(`Playing your Radio`);
    conv.add(
        new MediaObject({
            url: ""
        })
    );
    conv.add(new Suggestions(`exit`));
});

As it seems you are trying to have a media control and after that to end the conversation, you should refer to the doc ( https://developers.google.com/assistant/conversational/prompts-media ) to check the available events as you have the chance to control each one for the media playback.

For example

// Media status
app.handle('media_status', (conv) => {
  const mediaStatus = conv.intent.params.MEDIA_STATUS.resolved;
  switch(mediaStatus) {
    case 'FINISHED':
      conv.add('Media has finished playing.');
      break;
    case 'FAILED':
      conv.add('Media has failed.');
      break;
    case 'PAUSED' || 'STOPPED':
      if (conv.request.context) {
        // Persist the media progress value
        const progress = conv.request.context.media.progress;
      }
      // Acknowledge pause/stop
      conv.add(new Media({
        mediaType: 'MEDIA_STATUS_ACK'
        }));
      break;
    default:
      conv.add('Unknown media status received.');
  }
});

Once you get the FINISHED status you can offer the suggestion chip to exit the conversation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM