Comparing version 1.0.4 to 1.1.0
@@ -35,2 +35,8 @@ 'use strict'; | ||
const ACTION_TYPES = { | ||
MARK_SEEN: 'mark_seen', | ||
TYPING_ON: 'typing_on', | ||
TYPING_OFF: 'typing_off', | ||
}; | ||
function Botly(options) { | ||
@@ -169,2 +175,22 @@ if (!(this instanceof Botly)) { | ||
Botly.prototype.sendAction = function (options, callback) { | ||
request.post( | ||
{ | ||
url: FB_MESSENGER_URL, | ||
json: true, | ||
qs: { | ||
access_token: this.accessToken | ||
}, | ||
body: { | ||
recipient: {id: options.id}, | ||
sender_action: options.action | ||
} | ||
}, (err, res, body) => { | ||
if (callback) { | ||
callback(err, body); | ||
} | ||
}); | ||
}; | ||
Botly.prototype.sendAttachment = function (options, callback) { | ||
@@ -294,3 +320,3 @@ options.message = options.message || { | ||
if (message.postback || (message.message && message.message.quick_reply)) { | ||
let postback = (message.postback &&message.postback.payload) || message.message.quick_reply.payload; | ||
let postback = (message.postback && message.postback.payload) || message.message.quick_reply.payload; | ||
this.emit('postback', message.sender.id, message, postback); | ||
@@ -328,5 +354,6 @@ } | ||
ATTACHMENT_TYPE: ATTACHMENT_TYPE, | ||
NOTIFICATION_TYPE: NOTIFICATION_TYPE | ||
NOTIFICATION_TYPE: NOTIFICATION_TYPE, | ||
ACTION_TYPES: ACTION_TYPES | ||
}; | ||
module.exports = Botly; |
{ | ||
"name": "botly", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "Simple Facebook Messenger Bot API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -24,2 +24,3 @@ <img src="https://raw.githubusercontent.com/Askrround/botly/master/botly_logo.png" width="250" height="250" /> | ||
- [sendGeneric (options[, callback])](#sendgeneric-options-callback) | ||
- [sendAction (options[, callback])](#sendaction-options-callback) | ||
- [sendReceipt (options[, callback])](#sendreceipt-options-callback) | ||
@@ -50,3 +51,3 @@ - [setGetStarted (options[, callback])](#setgetstarted-options-callback) | ||
webHookPath: yourWebHookPath, //defaults to "/", | ||
notificationType: Botly.CONST.REGULAR //already the default (optional) | ||
notificationType: Botly.CONST.REGULAR //already the default (optional), | ||
}); | ||
@@ -132,2 +133,9 @@ | ||
#### sendAction (options[, callback]) | ||
```javascript | ||
botly.sendAction({id: userId, action: Botly.CONST.ACTION_TYPES.TYPING_ON}, function (err, data) { | ||
//log it | ||
}); | ||
``` | ||
#### sendReceipt (options[, callback]) | ||
@@ -277,2 +285,5 @@ ```javascript | ||
#### version 1.1.0 | ||
- added support for sender actions using `sendAction` (mark seen/ typing on/ typing off) | ||
#### version 1.0.3 | ||
@@ -279,0 +290,0 @@ - added send event - useful for tracking |
@@ -426,2 +426,24 @@ var expect = require('chai').expect; | ||
it('should send sender action', () => { | ||
request.post.yields(null, {}); | ||
var botly = new Botly({ | ||
accessToken: 'myToken', | ||
verifyToken: 'myVerifyToken', | ||
webHookPath: '/webhook', | ||
notificationType: Botly.CONST.NOTIFICATION_TYPE.NO_PUSH | ||
}); | ||
botly.sendAction({id: USER_ID, action: Botly.CONST.ACTION_TYPES.TYPING_ON}, ()=> { | ||
}); | ||
expect(request.post.calledOnce).to.be.true; | ||
expect(request.post.args[0][0].body).to.eql({ | ||
'sender_action': 'typing_on', | ||
'recipient': { | ||
'id': '333' | ||
} | ||
}); | ||
}); | ||
it('should send text messages with quick replies', () => { | ||
@@ -428,0 +450,0 @@ request.post.yields(null, {}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
83158
1262
298