我正在实现一个通过 Twilio 与 WhatsApp 集成的聊天机器人。该机器人使用 V2 API,我已经在 Google 云上实现了集成,因为它们将被关闭。
当我从 WhatsApp 触发机器人时,会触发正确的意图并执行正确的功能。
但当我检查 Twilio 时,它返回“14103 Invalid Body”错误,并注意到 Dialogflow 没有向 Twilio 返回任何内容。
然而,当我只是给出默认响应时,它会被返回到 Twilio,并且类似地在 WhatsApp 上作为回复给出。因此,集成工作正常。这只是回应。
在我的履行代码中,一切都正确执行,除了
conv.ask('Response'); //The actual message that needs to be sent back
Update
当我从对话流控制台和 WhatsApp 向机器人发送消息时,我检查了响应
从控制台触发时的响应 -
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"
}
}
从 WhatsApp 触发时的响应 -
Response {
"status": 200,
"headers": {
"content-type": "application/json;charset=utf-8"
},
"body": {
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Outbound message"
}
}
]
}
}
}
}
}
这是代码片段(如果有帮助的话)
'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
});
履行文本响应未发送到 Twilio - 因此出现“无效正文”错误。我仍然很困惑为什么它不向 Twilio 发送文本响应。
如果我遗漏了什么,有人可以帮我知道吗?如果有特定的格式我需要写响应。
提前致谢