Javascript 定时响应不工作messenger bot

Javascript 定时响应不工作messenger bot,javascript,node.js,settimeout,facebook-messenger,facebook-messenger-bot,Javascript,Node.js,Settimeout,Facebook Messenger,Facebook Messenger Bot,我正在使用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 re

我正在使用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
之后触发。不,它没有显示错误。@标记\M settimeout函数应该将响应发送给发送消息的人。我知道该函数可以工作,但它不会向用户发送响应。“其他一切都很好。”马克编辑了一下。