nodejs Dialogflow v2从实现中关闭对话

时间:2019-01-24 01:10:40

标签: node.js dialogflow actions-on-google

我如何从Webhook结束对话?

在Dialogflow中标记它没有任何作用,基本上不会停止它,因为我正在使用webhook来实现。

如果我将其添加到下面的代码中,则它将无法播放媒体。

// Import the Dialogflow module from the Actions on Google client library.
// https://github.com/actions-on-google/actions-on-google-nodejs
const {dialogflow, Suggestions, MediaObject, Image} = require('actions-on-google');
// Import the firebase-functions package for Cloud Functions for Firebase fulfillment.
const functions = require('firebase-functions');
// Node util module used for creating dynamic strings
const util = require('util');

// Instantiate the Dialogflow client with debug logging enabled.
const app = dialogflow({
  debug: true
});

// Do common tasks for each intent invocation
app.middleware((conv, framework) => {
  console.log(`Intent=${conv.intent}`);
  console.log(`Type=${conv.input.type}`);
  //kng
  console.log(`Arguments=${conv.arguments}`);
  console.log(`Arguments=${typeof(conv.arguments)}`);
  // Determine if the user input is by voice
  conv.voice = conv.input.type === 'VOICE';
  if (!(conv.intent === 'Default Fallback Intent' || conv.intent === 'No-input')) {
    // Reset the fallback counter for error handling
    conv.data.fallbackCount = 0;
  }
});

app.intent('Play Sound', (conv, {SoundType,duration}) => {

    const suggestions1 = new Suggestions('do this ', 'do that', 'do nothing');

    simple_response = 'this is a response from the webhook'

    conv.ask(simple_response)
    conv.ask(new MediaObject({
      name: SoundType,
      url: some_mp3file_url,
      icon: new Image({
        url: some_image_url,
        alt: 'Media icon'
      })
    }));


    conv.ask( suggestions1);

    //if I close from the code it doesnot play the sound
    conv.close();
    //if I comment out the close statement above then it does not close and toggling on the "set this intent as the end of  convesation does not seem to help."

  }
)

1 个答案:

答案 0 :(得分:0)

我可以重复这个问题,但这似乎是一个错误-播放音频作为响应的一部分,并在音频使用正常工作后关闭它。显然应该得到支持-文档和模拟器指出,如果这是最终答复,则不需要“建议”。

解决方法是创建一个附加的Intent,用于处理操作actions_intent_MEDIA_STATUS。然后,此Intent将关闭对话。