我正在使用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);
}
}
答案 0 :(得分:0)
使用针对计时响应的其他发送功能解决了问题。