Comparing version 1.1.1 to 1.1.2
@@ -83,2 +83,22 @@ 'use strict'; | ||
Botly.prototype.getPSID = function (accountLinkingToken, callback) { | ||
const USER_URL = `${FB_URL}me`; | ||
request.get( | ||
{ | ||
url: USER_URL, | ||
qs: { | ||
fields: 'recipient', | ||
account_linking_token: accountLinkingToken, | ||
access_token: this.accessToken | ||
}, | ||
json: true | ||
}, (err, res, body) => { | ||
if (callback) { | ||
callback(err, body); | ||
} | ||
}); | ||
}; | ||
Botly.prototype.getUserProfile = function (userId, callback) { | ||
@@ -306,2 +326,3 @@ const USER_URL = `${FB_URL}${userId}`; | ||
_handlePostback.call(this, message); | ||
_handleAccountLinking.call(this, message); | ||
_handleUserMessage.call(this, message); | ||
@@ -333,2 +354,9 @@ }, this); | ||
function _handleAccountLinking(message) { | ||
if (message.account_linking) { | ||
let link = message.account_linking; | ||
this.emit('account_link', message.sender.id, message, link); | ||
} | ||
} | ||
function _handleUserMessage(message) { | ||
@@ -335,0 +363,0 @@ var value; |
{ | ||
"name": "botly", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Simple Facebook Messenger Bot API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -29,2 +29,3 @@ <img src="https://raw.githubusercontent.com/Askrround/botly/master/botly_logo.png" width="250" height="250" /> | ||
- [getUserProfile (userId[, callback])](#getuserprofile-userid-callback) | ||
- [getPSID (accountLinkingToken[, callback])](#getpsid-accountlinkingtoken-callback) | ||
- [createWebURLButton (title, url)](#createweburlbutton-title-url) | ||
@@ -218,2 +219,10 @@ - [createAccountLinkButton (url)](#createaccountlinkbutton-url) | ||
#### getPSID (accountLinkingToken[, callback]) | ||
Used to retrieve the user page-scoped ID (PSID) during the linking flow. | ||
```javascript | ||
botly.getUserProfile(accountLinkingToken, function (err, info) { | ||
//cache it | ||
}); | ||
``` | ||
#### createWebURLButton (title, url) | ||
@@ -283,2 +292,8 @@ | ||
}); | ||
botly.on("account_link", (sender, message, link) => { | ||
/** | ||
* where link is the the object containing the status and authorization code | ||
*/ | ||
}); | ||
``` | ||
@@ -285,0 +300,0 @@ |
@@ -753,2 +753,27 @@ var expect = require('chai').expect; | ||
it('should get user profile', done => { | ||
request.get.yields( | ||
{ | ||
"id": "111", | ||
"recipient": "222" | ||
} | ||
); | ||
var botly = new Botly({ | ||
accessToken: 'myToken', | ||
verifyToken: 'myVerifyToken', | ||
webHookPath: '/webhook', | ||
notificationType: Botly.CONST.NOTIFICATION_TYPE.NO_PUSH | ||
}); | ||
botly.getPSID('333', (data) => { | ||
expect(request.get.calledOnce).to.be.true; | ||
expect(data).to.eql({ | ||
"id": "111", | ||
"recipient": "222" | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should set welcome screen', () => { | ||
@@ -755,0 +780,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
85584
1319
316