Facebook Messenger集成-机器人不提供响应

时间:2018-09-11 17:19:16

标签: dialogflow actions-on-google

我已经将Dialogflow与Facebook Messenger集成在一起   积分。我遵循了dialogflow文档中的步骤。

我没有从Messenger收到任何输出消息。

我曾经用conv.ask()来回答意图,这是问题吗?

我需要在动作中更新表面能力部分吗?

'use strict';

  // Import the Dialogflow module and response creation dependencies
  // from the Actions on Google client library.
  const {
    dialogflow,
    BasicCard,

  } = require('actions-on-google');

  // Import the firebase-functions package for deployment.
  const functions = require('firebase-functions');

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


  function getRandomInt(max) {
    return Math.floor(Math.random() * Math.floor(max));
  }

  const swamiMessages = require('./messages');

  const swamiQuotes =require('./quotes');
  // Intent Mapping 

  //INTENT: 'Default Welcome Intent'.

  app.intent('Default Welcome Intent', (conv) => {
    conv.ask(
        `<speak> <emphasis level="moderate" >   `+
        `Do you want to hear an Inspiring  <break/> Quote or a Message from Swami <break/> Sukhabodhananda ` +
        `Do you want to know about Prasanna Trust <break/>`+
        //`Do you want to know about the upcoming programs` +
      ` </emphasis> </speak>`);
    });

  //INTENT: 'quote'
  //Should get triggered when the user request for an inspiring thought
  // asks for motivation 

  app.intent('quote', (conv) => {
    // when the welcome intent is triggered recite a random quote

    //let quoteNumber= getRandomInt(5);
    //let quote = quotes[quoteNumber].quote; //
      let quote =swamiQuotes.getQuote();

    if (quote) {
        conv.ask(
            `<speak> <emphasis level="moderate" >   `+
            `Let us hear  an Inspiring quote \n` +
            `<break strength="strong"> </break>  `+
            `${quote}` +
            `<break strength="strong"> </break>  `+
            `\nDo you want to hear another quote or message ` +
            ` </emphasis> </speak>`);
        } else
        {
          conv.ask(
            `<speak> <emphasis level="moderate" >   `+
            `Let us hear  an Inspiring quote ` +
            `<break strength="strong"> </break>  `+
            `quotes` +
            `\nDo you want to hear another quote or message ` +
            ` </emphasis> </speak>`);
        }
  });

  // INTENT: message 
  //Should get triggered when the user request for an inspiring message


  app.intent('message', (conv) => {
    // when the welcome intent is triggered recite a random message
    let message =swamiMessages.getMessage();
    //let formattedMessage=swamiMessages.formattedMessage(message);

    conv.ask(
        `<speak> <emphasis level="moderate" >   `+
        `Let us hear  an Inspiring Message ` +
        `<break strength="strong"> </break>  `+
        `${message}`+
        `\nDo you want to hear another quote or message ` +
        ` </emphasis> </speak>`);

    });

更新

如果我更改了使用dialogflow-fulfillment库的功能,如何添加两个默认处理程序功能-一个用于Google上的Actions,另一个用于其他集成?我正在做类似的事情

intentMap.set(null, googleAssistantOther);
intentMap.set(null, other);
//In place of null should i update the Intent Name and 
// googleAssitantOther and other are callback functions. 

1 个答案:

答案 0 :(得分:2)

您表示您正在尝试将其与Facebook集成,但您使用的是Google行动库,该库专门用于响应专门针对Google助手的消息。

如果您想编写对助手以及Dialogflow支持的其他平台都响应的代码,则可能需要研究dialogflow-fulfillment library

您无需在操作控制台上对曲面配置进行任何操作。

更新

您可以使用相同的Intent定义-这是针对多个平台进行开发的重要方面。两者之间的许多工作(例如文本)完全相同。对于某些事情(例如想要添加一些RichResponse对象),您可能需要使用诸如

这样的代码来检查您正在哪个平台上运行
if (agent.requestSource === agent.ACTIONS_ON_GOOGLE) {
  intentMap.set(null, googleAssistantOther);
} else {
  intentMap.set(null, other);
}