-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
106 lines (104 loc) · 2.96 KB
/
bot.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
const linebot = require('../index.js');
const bot = linebot({
channelId: process.env.CHANNEL_ID,
channelSecret: process.env.CHANNEL_SECRET,
channelAccessToken: process.env.CHANNEL_ACCESS_TOKEN,
verify: true // default=true
});
bot.on('message', function (event){
switch (event.message.type){
case 'text':
switch (event.message.text) {
case 'Me':
event.source.profile().then(function (profile) {
return event.reply('Hello ' + profile.displayName + ' ' + profile.userId);
});
break;
case 'Picture':
event.reply({
type: 'image',
originalContentUrl: 'https://d.line-scdn.net/stf/line-lp/family/en-US/190X190_line_me.png',
previewImageUrl: 'https://d.line-scdn.net/stf/line-lp/family/en-US/190X190_line_me.png'
});
break;
case 'Location':
event.reply({
type: 'location',
title: 'LINE Plus Corporation',
address: '1 Empire tower, Sathorn, Bangkok 10120, Thailand',
latitude: 13.7202068,
longitude: 100.5298698
});
break;
case 'Push':
bot.push('U6350b7606935db981705282747c82ee1', ['Hey!', 'สวัสดี ' + String.fromCharCode(0xD83D, 0xDE01)]);
break;
case 'Push2':
bot.push(['U6350b7606935db981705282747c82ee1', 'U6350b7606935db981705282747c82ee1'], ['Hey!', 'สวัสดี ' + String.fromCharCode(0xD83D, 0xDE01)]);
break;
case 'Multicast':
bot.push(['U6350b7606935db981705282747c82ee1', 'U6350b7606935db981705282747c82ee1'], 'Multicast!');
break;
case 'Confirm':
event.reply({
type: 'template',
altText: 'this is a confirm template',
template: {
type: 'confirm',
text: 'Are you sure?',
actions: [{
type: 'message',
label: 'Yes',
text: 'yes'
}, {
type: 'message',
label: 'No',
text: 'no'
}]
}
});
break;
case 'Multiple':
return event.reply(['Line 1', 'Line 2', 'Line 3', 'Line 4', 'Line 5']);
break;
case 'Version':
event.reply('linebot@' + require('../package.json').version);
break;
default:
event.reply(event.message.text).then(function (data) {
console.log('Success', data);
}).catch(function (error) {
console.log('Error', error);
});
break;
}
break;
case 'image':
event.message.content().then(function (data) {
const s = data.toString('base64').substring(0, 30);
return event.reply('Nice picture! ' + s);
}).catch(function (err) {
return event.reply(err.toString());
});
break;
case 'video':
event.reply('Nice movie!');
break;
case 'audio':
event.reply('Nice song!');
break;
case 'location':
event.reply(['That\'s a good location!', 'Lat:' + event.message.latitude, 'Long:' + event.message.longitude]);
break;
case 'sticker':
event.reply({
type: 'sticker',
packageId: 1,
stickerId: 1
});
break;
default:
event.reply('Unknow message: ' + JSON.stringify(event));
break;
}
});