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