forked from fbsamples/messenger-platform-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notUsedyet.js
147 lines (140 loc) · 4.78 KB
/
notUsedyet.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* Send a button message using the Send API.
*
*/
function sendButtonMessage(recipientId) {
var messageData = {
recipient: {
id: recipientId
},
message: {
attachment: {
type: "template",
payload: {
template_type: "button",
text: "This is test text",
buttons:[{
type: "web_url",
url: "https://www.oculus.com/en-us/rift/",
title: "Open Web URL"
}, {
type: "postback",
title: "Call Postback",
payload: "Developer defined postback"
}]
}
}
}
};
callSendAPI(messageData);
}
/*
* Send a Structured Message (Generic Message type) using the Send API.
*
*/
function sendGenericMessage(recipientId) {
var messageData = {
recipient: {
id: recipientId
},
message: {
attachment: {
type: "template",
payload: {
template_type: "generic",
elements: [{
title: "rift",
subtitle: "Correct",
image_url: "https://www.dropbox.com/s/nsyzfgjiuwr7n9q/9782091724935-248A.jpg?dl=0",
buttons: [{
type: "web_url",
url: "https://www.oculus.com/en-us/rift/",
title: "Open Web URL"
}, {
type: "postback",
title: "Call Postback",
payload: "Payload for first bubble",
}],
}, {
title: "touch",
subtitle: "Correct",
image_url: "https://www.dropbox.com/s/nsyzfgjiuwr7n9q/9782091724935-248A.jpg?dl=0",
buttons: [{
type: "web_url",
url: "https://www.oculus.com/en-us/touch/",
title: "Open Web URL"
}, {
type: "postback",
title: "Call Postback",
payload: "Payload for second bubble",
}]
}]
}
}
}
};
callSendAPI(messageData);
}
/*
* Send a receipt message using the Send API.
*
*/
function sendReceiptMessage(recipientId) {
// Generate a random receipt ID as the API requires a unique ID
var receiptId = "order" + Math.floor(Math.random()*1000);
var messageData = {
recipient: {
id: recipientId
},
message:{
attachment: {
type: "template",
payload: {
template_type: "receipt",
recipient_name: "PeterMessageConsumer Chang",
order_number: receiptId,
currency: "USD",
payment_method: "Visa 1234",
timestamp: "1428444852",
elements: [{
title: "Oculus Rift",
subtitle: "Includes: headset, sensor, remote",
quantity: 1,
price: 599.00,
currency: "USD",
image_url: "http://messengerdemo.parseapp.com/img/riftsq.png"
}, {
title: "Samsung Gear VR",
subtitle: "Frost White",
quantity: 1,
price: 99.99,
currency: "USD",
image_url: "http://messengerdemo.parseapp.com/img/gearvrsq.png"
}],
address: {
street_1: "1 Hacker Way",
street_2: "",
city: "Menlo Park",
postal_code: "94025",
state: "CA",
country: "US"
},
summary: {
subtotal: 698.99,
shipping_cost: 20.00,
total_tax: 57.67,
total_cost: 626.66
},
adjustments: [{
name: "New Customer Discount",
amount: -50
}, {
name: "$100 Off Coupon",
amount: -100
}]
}
}
}
};
callSendAPI(messageData);
}