我已经使用 facebook messenger api 和 wit.ai 操作编写了示例回显消息机器人。
我收到了来自 facebook 页面的消息,并且使用 wit api 定义的正确操作函数也被调用。但是,在返回响应时,我收到以下错误 -
哎呀!将响应转发到:错误:(#100)Param message[text] must be an UTF-8 encoding string at fetch.then.then.json (/app/index.js:106:13) at process ._tickCallback (内部/进程/next_tick.js:103:7)
这是用于返回响应的函数 -
const fbMessage = (id, text) => {
const body = JSON.stringify({
recipient: { id },
message: { text },
});
const qs = 'access_token=' + encodeURIComponent(FB_PAGE_ACCESS_TOKEN);
return fetch('https://graph.facebook.com/v2.6/me/messages?' + qs, {
method: 'POST',
headers: {'Content-Type': 'application/json; charset=UTF-8'},
body
})
.then(rsp => rsp.json())
.then(json => {
if (json.error && json.error.message) {
throw new Error(json.error.message);`enter code here`
}
return json;
});
};
我已经从文档中的 messenger.js 文件中复制了这个函数,因为我只是在尝试 POC。我在这个函数中检查了 text 和 id 的值,并使用 console.log 语句进行了验证,这些语句都正常运行。
一些专家可以帮助我解决这个错误吗?
注意 - 我尝试使用 text.toString("utf8"); 对文本进行编码 但它将编码字符串作为 [object object] 返回,这就是我从 bot 得到的响应。所以它不起作用。