twilio - Dialogflow webhook 响应未发送到 Twilio - 在 Twilio 调试器上出现 14103 Invalid Body 错误
问题描述
我正在实现一个通过 Twilio 与 WhatsApp 集成的聊天机器人。该机器人在 V2 API 上,我已经在谷歌云上实现了集成,因为它们将被关闭。
当我从 WhatsApp 触发机器人时,会触发正确的意图并执行正确的功能。
但是当我检查 Twilio 时,它返回一个“14103 Invalid Body”错误,并注意到 Dialogflow 没有返回任何内容到 Twilio。
但是,当我只是给出一个默认响应时,它会被返回给 Twilio,并且同样会在 WhatsApp 上作为回复给出。因此集成工作正常。这只是回应。
在我的履行代码中,除了
conv.ask('Response'); //The actual message that needs to be sent back
更新
当我从 dialogflow 控制台和 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 发送文本响应。
任何人都可以帮助我知道我是否遗漏了什么?如果有特定的格式,我需要编写响应。
提前致谢
解决方案
推荐阅读
- c# - 无法将类型字符串隐式转换为 Autodesk.Revit.BD.DisplayUnitType
- swift - 带有文本和图像的 SwiftUI 表单选择器
- firebase - Ionic 4 和 Firebase 集成
- docker - Docker - 为什么运行 ubuntu 的 50 个容器占用与 50x alpine 类似的 RAM?
- jquery-ui - 如何使用 Jquery ui 在 DataTable 中放置模态框
- python - 如何在python中使用函数作为参数
- python - 如何跨多个工作表对相同的列进行排序?
- python - 在 read_pickle 之后追加
- ruby - Ruby / Redmine:从问题主题和适当的自定义字段编译哈希
- python - AttributeError:“历史”对象没有属性“predict_classes”