定时响应不工作信使机器人

Timed response not working 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 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);
  }

}

问题已通过使用不同的定时响应发送函数解决。