node.js - Facebook Messenger Bot wait to respond after many request and resume -


when write alphabet on facebook bot, bot wait respond.

i write example : write "a"... bot respond "a", write "b"... bot respond "b", etc...

but, example on letter "l", bot waits respond, , resume after minutes :

enter image description here

after minutes, bot responds :

enter image description here

i use official code, https://developers.facebook.com/docs/messenger-platform/guides/quick-start/

app.js

app.get('/webhook', function(req, res) {     if (req.query['hub.mode'] === 'subscribe' &&         req.query['hub.verify_token'] === configuration.webhook_token) {         console.log("validating webhook");         res.status(200).send(req.query['hub.challenge']);     } else {         console.error("failed validation. make sure validation tokens match.");         res.sendstatus(403);     } });  app.post('/webhook', function (req, res) {     let data = req.body;      // make sure page subscription     if (data.object === 'page') {          // iterate on each entry - there may multiple if batched         data.entry.foreach(function(entry) {             let pageid = entry.id;             let timeofevent = entry.time;              // iterate on each messaging event             entry.messaging.foreach(function(event) {                 if (event.message) {                     receivedmessage(event);                 } else {                     console.log("webhook received unknown event: ", event);                 }             });         });          // assume went well.         //         // must send 200, within 20 seconds, let know         // you've received callback. otherwise, request         // time out , keep trying resend.         res.sendstatus(200);     } });  function receivedmessage(event) {     let senderid = event.sender.id;     let recipientid = event.recipient.id;     let timeofmessage = event.timestamp;     let message = event.message;      console.log("received message user %d , page %d @ %d message:",         senderid, recipientid, timeofmessage);     console.log(json.stringify(message));      let messageid = message.mid;      let messagetext = message.text;     let messageattachments = message.attachments;      if (messagetext) {          // if receive text message, check see if matches keyword         // , send example. otherwise, echo text received.         switch (messagetext) {             case 'generic':                 sendgenericmessage(senderid);                 break;              default:                 sendtextmessage(senderid, messagetext);         }     } else if (messageattachments) {         sendtextmessage(senderid, "message attachment received");     } }  function sendgenericmessage(recipientid) {     let messagedata = {         recipient: {             id: recipientid         },         message: {             attachment: {                 type: "template",                 payload: {                     template_type: "generic",                     elements: [{                         title: "rift",                         subtitle: "next-generation virtual reality",                         item_url: "https://www.oculus.com/en-us/rift/",                         image_url: "http://messengerdemo.parseapp.com/img/rift.png",                         buttons: [{                             type: "web_url",                             url: "https://www.oculus.com/en-us/rift/",                             title: "open web url"                         }, {                             type: "postback",                             title: "call postback",                             payload: "payload first bubble",                         }],                     }, {                         title: "touch",                         subtitle: "your hands, in vr",                         item_url: "https://www.oculus.com/en-us/touch/",                         image_url: "http://messengerdemo.parseapp.com/img/touch.png",                         buttons: [{                             type: "web_url",                             url: "https://www.oculus.com/en-us/touch/",                             title: "open web url"                         }, {                             type: "postback",                             title: "call postback",                             payload: "payload second bubble",                         }]                     }]                 }             }         }     };      callsendapi(messagedata); }  function sendtextmessage(recipientid, messagetext) {     let messagedata = {         recipient: {             id: recipientid         },         message: {             text: messagetext         }     };      callsendapi(messagedata); }  function callsendapi(messagedata) {     request({         uri: 'https://graph.facebook.com/v2.6/me/messages',         qs: { access_token: configuration.access_token },         method: 'post',         json: messagedata      }, function (error, response, body) {         if (!error && response.statuscode == 200) {             let recipientid = body.recipient_id;             let messageid = body.message_id;              console.log("successfully sent generic message id %s recipient %s",                 messageid, recipientid);         } else {             console.error("unable send message.");             console.error(response);             console.error(error);         }     }); }  let server = app.listen(port, function () {     interfacelogin.process();      console.log('app listening on port 8080!'); });  server.timeout = 1000; 

in console, during last respond see :

received message user xxx , page xxx @ xxx message: {"mid":"mid.$xxx","seq":xxxx,"text":"k"} sent generic message id mid.$xxx recipient xxxxx 

the bot don't respond, , after minutes see :

received message user xxx , page xxx @ xxx message: {"mid":"mid.$xxx","seq":xxxx,"text":"l"} sent generic message id mid.$xxx recipient xxxx webhook received unknown event:  { sender: { id: 'xxx' },   recipient: { id: 'xxx' },   timestamp: xxx,   delivery:     { mids: [ 'mid.$xxx' ],      watermark: xxx,      seq: 0 } } 

the bots responds

my last respond :

received message user xxx , page xxx @ xxx message: {"mid":"mid.$xxx","seq":xx,"text":"k"} sent generic message id mid.$xxx recipient xxx received message user xxx , page xxx @ xxx message: {"mid":"mid.$xxx","seq":xx,"text":"l"} sent generic message id mid.$xxx recipient xxxx webhook received unknown event:  { sender: { id: 'xxx' },   recipient: { id: 'xxx' },   timestamp: xxx,   delivery:     { mids: [ 'mid.$xxx' ],      watermark: xxx,      seq: 0 } } 


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -