【发布时间】:2016-08-16 13:42:30
【问题描述】:
我使用 facebook messenger api 和 wit.ai 操作编写了示例回显消息机器人。
收到我来自 facebook 页面的消息,并且使用 wit api 定义的正确操作函数也被调用。然而 在返回响应时,我收到以下错误 -
哎呀!将响应转发到:错误:(#100)参数消息[文本]必须是UTF-8编码的字符串 在 fetch.then.then.json (/app/index.js:106:13) 在 process._tickCallback (internal/process/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],这就是 我从机器人得到的回应。所以它不起作用。
【问题讨论】:
标签: encoding utf-8 facebook-messenger wit.ai facebook-chatbot