【发布时间】:2018-06-29 23:22:40
【问题描述】:
我正在使用 node.js 开发一个 facebook messenger 机器人。我试图让我的代码向用户发送定时响应,但它不起作用。代码如下:
function handlePostback(sender_psid, received_postback) {
let response;
let subscribe;
// Get the payload for the postback
let payload = received_postback.payload;
// Set the response based on the postback payload
if (payload === 'yes') {
response = { "text": "Thanks! Here's your first task : Hold the door for someone. " };
subscribe = true;
} else if (payload === 'no') {
response = {"text":"That's unfortunate" };
subscribe = false;
}
// Send the message to acknowledge the postback
callSendAPI(sender_psid, response);
if (subscribe===true) {
response = {"text":"Today's task will be:"};
setTimeout(sendTask(), 5000);
}
}
【问题讨论】:
-
如果您详细说明“它不起作用”会很有帮助。有错误吗?目前尚不清楚应该发生什么。你在
payload == yes的时候设置了两次response,但是第二次是超时的,也就是说会在callSendAPI之后触发。 -
不,它没有显示错误。
-
@Mark_M setTime out 函数应该将响应发送给发送消息的人。我知道该功能有效,但它没有向用户发送响应。其他一切正常。
-
@Mark_M 进行了编辑。
标签: javascript node.js settimeout facebook-messenger facebook-messenger-bot