Ak11
Ak11

Reputation: 43

Facebook messenger integration - bot does not provide the responses

I had integrated the Dialogflow with Facebook messenger integration. I had followed the steps in the dialogflow docs.

I am not getting any output /message from the messenger.

I had used conv.ask() to respond to the Intents, is that the issue?

Do I need to update the surface capabilities section in actions?

'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>`);

    });

Update

If I make changes to use the dialogflow-fulfillment library, how do I add two default handler functions - one for Actions on Google and one for other integrations? I'm doing something like

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. 

Upvotes: 3

Views: 925

Answers (1)

Prisoner
Prisoner

Reputation: 50701

You indicated you're trying to integrate this with Facebook, but you're using the actions-on-google library, which is tailored to respond with messages specifically for the Google Assistant.

If you want to write code that responds for both the Assistant, as well as other platform that Dialogflow supports, you may want to look into the dialogflow-fulfillment library.

You do not need to do anything with the surface configuration on the Action console.

Update

You can use the same Intent definitions - that is an important aspect of developing for multiple platforms. And many things (such as text) work exactly the same between the two. For some things (such as wanting to add some RichResponse objects), you may want to check which platform you're running on with code such as

if (agent.requestSource === agent.ACTIONS_ON_GOOGLE) {
  intentMap.set(null, googleAssistantOther);
} else {
  intentMap.set(null, other);
}

Upvotes: 3

Related Questions