-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfacebook.js
52 lines (48 loc) · 1.08 KB
/
facebook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
const request = require('request-promise');
const tokens = require('./token.js');
/**
* Get user's page info
* @param {String} psid
* @return {Promise}
*/
const getUserInfo = (psid) => {
return request({
uri: 'https://graph.facebook.com/v2.8/' + psid,
method: 'GET',
json: true, headers: {
'Content-Type': 'application/json'
},
qs: {
access_token: tokens.FB_PAGE_TOKEN
}
}).then((response) => {
console.log('GET', 'https://graph.facebook.com/v2.8/' + psid + '?access_token=FB_PAGE_TOKEN');
return response;
});
};
/**
* Get user's first name
* @param {Object} context
* @return {Object}
*/
const getFirstName = (context) => {
// Finding user's first name
return getUserInfo(context.psid).then((response) => {
const name = response['first_name'];
if (name) {
context.name = name;
delete context.noName;
} else {
context.noName = true;
}
return context;
}).catch((e) => {
context.noName = e;
return context;
});
};
module.exports = {
user: getUserInfo,
name: getFirstName
};