push.js
2.38 KB
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
const { send } = require('express/lib/response');
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/push'
const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast'
const TOKEN = 'XOyIf8jsoQKq3b1zqxE4wawAoFU2Hz433AO3w8/ye+i6+2KrXpyfFwY0Dk/xhHQLPgtgPTiEP/m4IRW+SlVhdtzfH6c0Lfdw6nJ95QOugHfNWfviAmn5Uojh8LQJeAy21bvaNMCy11f+qgLSRnXmCgdB04t89/1O/w1cDnyilFU='
var USER_ID = 'Uc4258407a7677769f74ba184ec036651'
//Single User
function SingleCast(sendMsg, destination){
USER_ID = destination;
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"to": `${USER_ID}`,
"messages":[
{
"type":"text",
"text":sendMsg
},
{
"type":"text",
"text":"May I help you?"
}
]
}
},(error, response, body) => {
console.log(body)
});
}
// Multicast User
function Multicast(sendMsg){
request.post(
{
url: MULTI_TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"to": [`${USER_ID}`],
"messages":[
{
"type":"text",
"text":sendMsg
},
{
"type":"text",
"text":"May I help you?"
}
]
}
},(error, response, body) => {
console.log(body)
});
}
function Broadcast(msg){
request.post(
{
url: BROAD_TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"messages":[
{
"type":"text",
"text":msg
}
]
}
},(error, response, body) => {
console.log(body)
});
}
exports.SendMessage = function(sendMessage, destination){
SingleCast(sendMessage, destination);
}