From 0baeda0d0b614023c58c673d12f2ae55f543f81f Mon Sep 17 00:00:00 2001 From: junedmunshi Date: Thu, 17 Aug 2017 01:08:52 +0530 Subject: [PATCH] added support to handle nlp key and function to send actions like typing on,typing off and mark seen. --- index.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index d2b54e4..a6f163d 100644 --- a/index.js +++ b/index.js @@ -80,8 +80,43 @@ FBBotFramework.prototype.send = function (recipient, messageData, notificationTy }); }; +FBBotFramework.prototype.sendAction = function (recipient, action, cb) { + var req = { + url: FB_MESSENGER_ENDPOINT, + qs: {access_token: this.page_token}, + method: "POST", + json: { + recipient: {id: recipient}, + sender_action: action, + } + }; + request(req, function (err, res, body) { + if (cb) { + if (err) return cb(err); + if (body.error) return cb(body.error); + cb(null, body); + } + }); + +}; + +FBBotFramework.prototype.sendActionTypeingOn =function(recipient,cb) +{ + console.log("here") + this.sendAction(recipient,"typing_on",cb); +} + +FBBotFramework.prototype.sendActionTypeingOff =function(recipient,cb) +{ + this.sendAction(recipient,"typing_off",cb); +} +FBBotFramework.prototype.sendActionMarkseen =function(recipient,cb) +{ + this.sendAction(recipient,"mark_seen",cb); +} + FBBotFramework.prototype.sendTextMessage = function (recipient, text, notificationType, cb) { var messageData = {text: text}; this.send(recipient, messageData, notificationType, cb); @@ -250,7 +285,15 @@ FBBotFramework.prototype.middleware = function () { // Trigger onMessage Listener if (event.message && event.message.text) { - bot.emit('message', sender, event.message.text); + //handle nlp key + if(event.message.nlp !== undefined) + { + bot.emit('message', sender, event.message.text,event.message.nlp); + } + else + { + bot.emit('message', sender, event.message.text); + } } // Trigger onPostback Listener