【问题标题】:Timed response not working messenger bot定时响应不工作的信使机器人
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-06
    相关资源
    最近更新 更多