-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathsetWelcome.js
73 lines (64 loc) · 1.86 KB
/
setWelcome.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
/**
* Created by jakob on 25/06/16.
*/
var fetch = require('node-fetch');
var config = require('./config');
var FB = require('./facebook.action');
console.log("+++ Setting up Welcome Message +++");
const endpoint = "https://graph.facebook.com/v2.6/";
const params = "/thread_settings?access_token=";
var postcontent = generatePostContent();
const finalurl = endpoint + config.FB_PAGE_ID + params + config.FB_PAGE_TOKEN;
fetch(finalurl, {
method: 'POST',
headers: {"Content-Type": "application/json"},
body: JSON.stringify(postcontent)
}
).then(function (res) {
return res.json();
}).then(function (json) {
if (json.result)
console.log("\n" + json.result);
if (json.error)
console.error(json);
});
function generatePostContent() {
/* Text only
return {
"setting_type": "call_to_actions",
"thread_state": "new_thread",
"call_to_actions": [
{
"message": {
"text": "Welcome to my Bot!"
}
}
]
};
*/
return {
"setting_type": "call_to_actions",
"thread_state": "new_thread",
"call_to_actions": [
{
"message": {
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"elements": [
FB.generatePayloadElement(
"Welcome to my Bot",
null,
null,
null,
FB.generateActionButton("Say something funny", "CTA_SAY_FUNNY")
)
]
}
}
}
}
]
}
}