-
Notifications
You must be signed in to change notification settings - Fork 1
/
sendMessage.js
101 lines (61 loc) · 1.8 KB
/
sendMessage.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Sends the data to the call API
// Contains sendTextMessage, callSendAPI, sendTypingIndicator, and sendText
var request = require('request');
var sendTextMessage = function (recipientId, messageText) {
var 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: "EAAFT3pkXjN0BAJv0B10wSwANrRqmZAh9fGhwyVBLEkq6yhyMhsZCldC3VyQ6Q7IbyJcq0udhfuUTn9DJ3TBHiG7N9hcKYrYTZCZCvxC2JNxt1V5tJBN1ex5rTID5S5a8bOdA4glR8L2gZACJmc6wiSxdEldp4omSkCwn7cpsvjgZDZD"},
method: 'POST',
json: messageData
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
var recipientId = body.recipient_id;
var messageId = body.message_id;
console.log("Successfully sent generic message with id %s to recipient %s",
messageId, recipientId);
} else {
console.error("Unable to send message.");
console.error(response);
console.error(error);
}
});
};
var sendTypingIndicator = function(recipientID, typing) {
var typingData = {
"recipient":{
"id":recipientID
},
"sender_action": typing
}
callSendAPI(typingData);
}
var sendLocationOption = function(recipientID) {
var LocationData = {
"recipient":{
"id":recipientID
},
"message":{
"text":"Please share your location:",
"quick_replies":[
{
"content_type":"location",
}
]
}
}
callSendAPI(LocationData)
}
module.exports.sendLocationOption = sendLocationOption;
module.exports.sendTextMessage = sendTextMessage;
module.exports.sendTypingIndicator = sendTypingIndicator;