2

I am implementing a chat bot that is integrated with WhatsApp via Twilio. The bot is on V2 API and I have implemented the integrations on Google cloud as they would be shut.

When I trigger the bot from WhatsApp, the right intent is triggered and the right functions in fulfillment are being executed.

But when I check Twilio, it returns a '14103 Invalid Body' error and notice that nothing is being returned from Dialogflow to Twilio.

However, when I just give a Default Response, it is being returned to Twilio and similarly is given as a reply on WhatsApp. Therefore the integration is working fine. It's just the response.

In my fulfillment code too, everything is being rightly executed except

conv.ask('Response'); //The actual message that needs to be sent back

Update

I have checked the responses when I send to message to the bot from dialogflow console and from WhatsApp

Response when triggered from console -

Response {
  "status": 200,
  "headers": {
    "content-type": "application/json;charset=utf-8"
  },
  "body": {
    "payload": {
      "google": {
        "expectUserResponse": true,
        "richResponse": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "Outbound message"
              }
            }
          ]
        }
      }
    },
    "fulfillmentText": "Outbound message"
  }
}

Response when triggered from WhatsApp -

Response {
  "status": 200,
  "headers": {
    "content-type": "application/json;charset=utf-8"
  },
  "body": {
    "payload": {
      "google": {
        "expectUserResponse": true,
        "richResponse": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "Outbound message"
              }
            }
          ]
        }
      }
    }
  }
}

Here's the code snippet if it helps

'use strict';
const fetch = require('node-fetch');
const functions = require('firebase-functions');
const vision = require('@google-cloud/vision');
const https = require("https");
const admin = require('firebase-admin');
const {dialogflow} = require('actions-on-google');
const app = dialogflow({clientId: 'My_Client_Id', debug:true});

//initialise DB connection
admin.initializeApp({
credential:admin.credential.applicationDefault(),
databaseURL:'My_Firebase_Link',
});


exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

const welcome = 'Default Welcome Intent';

app.intent(welcome, (conv) => {
  //Function for Default Welcome Intent
    //console.log(conv); 
    var testNumber = 10;
    testNumber = testNumber + 10;
    console.log(testNumber);//When I trigger the bot, everything until this get's executed and I can see 20 in log 
    conv.ask('Outbound message');//This gets executed too but the reply that seems to be returned to Twilio is empty
});

The fulfillment text response is the one that is not being sent to Twilio - Therefore the 'Invalid Body' error. I'm still stumped as though why it doesn't send the text response to Twilio.

Can anyone help in letting me know if I'm missing something? If there's a specific format I need to write the response.

Thanks in advance

AceDullur
  • 61
  • 8
  • conv.ask() format I believe is specifically for Google actions. Please try using agent.add() format. Please refer to these videos for more details. – Anshul May 08 '20 at 13:53
  • Here are the videos: 1. https://www.youtube.com/watch?v=s257V2l-7SU 2. https://www.youtube.com/watch?v=3KSitm7X6rA 3. https://www.youtube.com/watch?v=r_iUzAWfC6E – Anshul May 08 '20 at 15:44
  • @Anshul So, what exactly are the changes that are to be made in the fulfillment code when moving from API v1 to v2 ? Most of the sources seem to indicate that everything is moving to actions-on-google library. So, you basically work with `conv.ask()` – AceDullur May 09 '20 at 07:26
  • Can you please share the link to the resources which say everything is moving to the actions-on-google library? – Anshul May 11 '20 at 14:33
  • @Anshul By sources I meant, example codes, questions posted on sites. I'm still a beginner to dialogflow, so please ignore my ignorance – AceDullur May 11 '20 at 15:07
  • Alright, so I believe there is no such official announcement. Therefore you can use agent.add() without worrying about everything moving to the actions-on-google library. – Anshul May 13 '20 at 07:28

0 Answers0