-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.1.js
123 lines (114 loc) · 3.04 KB
/
index.1.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
const linebot = require('linebot')
const Stuff = require('./controllers/stuff')()
const History = require('./controllers/history')()
const Reminder = require('./controllers/reminder')()
const config = require('./config.dev')
const CHANNEL_ID = config.config.CHANNEL_ID
const CHANNEL_SECRET = config.config.CHANNEL_SECRET
const CHANNEL_ACCESS_TOKEN = config.config.CHANNEL_ACCESS_TOKEN
const bot = linebot({
channelId: CHANNEL_ID,
channelSecret: CHANNEL_SECRET,
channelAccessToken: CHANNEL_ACCESS_TOKEN
})
bot.on('message', function (event) {
console.log('Event:', JSON.stringify(event))
let userId = event.source.userId
let message = event.message
if (userId) {
if (message.text) {
let response = message.text
let cmd = message.text.toLowerCase()
switch (cmd) {
case 'allreminder':
Reminder.getAllReminder()
break
case 'allhistory':
History.getAllHistory(userId)
break
case 'stuffhistory':
History.getStuffHistory(userId, 13)
break
case 'addreminder':
Reminder.addReminder(userId, 13, [new Date(), new Date()])
break
case 'getstuff':
console.log('==getStuff==')
let stuffList = Stuff.getUserStuff(userId)
response = {
'type': 'text',
'text': stuffList
}
break
case 'update':
History.updateAction(userId, 'add_thing_place', {stuff_postition: 'bag', schedules: [new Date(), new Date()]})
History.addHistory(userId).then((h) => {
console.log(h)
})
response = confirmDialog
break
case 'time':
response = datePicker
break
}
bot.reply(event.replyToken, response).then(function (data) {
// success
}).catch(function (error) {
console.log('Error: ' + JSON.stringify(error))
})
}
}
})
bot.on('postback', function (event) {
console.log('Event:', JSON.stringify(event))
})
let confirmDialog = {
'type': 'template',
'altText': 'this is a confirm template',
'template': {
'type': 'confirm',
'text': '根據我們的觀察 鑰匙是最常不見物品 請問要追蹤鑰匙嗎?',
'actions': [
{
'type': 'message',
'label': '好喔',
'text': 'yes'
},
{
'type': 'message',
'label': '不要',
'text': 'no'
}
]
}
}
let showStuffDialog = {
'type': 'template',
'altText': 'Show all stuff',
'template': {
'type': 'confirm',
'text': '根據我們的觀察 鑰匙是最常不見物品 請問要追蹤鑰匙嗎?',
'actions': [
{
'type': 'message',
'label': 'show',
'text': 'yes'
},
{
'type': 'message',
'label': 'end',
'text': 'no'
}
]
}
}
let datePicker = {
'type': 'datetimepicker',
'label': '請設定提醒時間',
'data': 'storeId=12345',
'mode': 'time',
'initial': '00:00',
'max': '23:59',
'min': '00:00'
}
bot.listen('/', 8000)