-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
101 lines (66 loc) · 2.07 KB
/
index.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
"use strict"
const http = require('http')
const Bot = require('messenger-bot')
//const Intelligence = require('./Intelligence')
let bot = new Bot({
token: process.env.ACCESS_TOKEN,
verify: process.env.VERIFY_TOKEN,
app_secret: process.env.APP_SECRET
})
bot.on('error', (err) => {
console.log(err.message)
})
bot.on('message', (payload, reply) => {
let text = payload.message.text
/* clean */
let cleanText = text.
replace(/please/g, '').
replace(/.+ thanks/g, ''). // strip thanks if not on its own
trim().
toLowerCase()
let resp = response(text)
bot.getProfile(payload.sender.id, (err, profile) => {
if (err) throw err
reply({ text: resp }, (err) => {
if (err) {
console.log(`error ${err}`)
throw err
}
console.log(`Replied back to ${profile.first_name} ${profile.last_name}: ${resp}`)
})
})
})
let notUnderstood = "Sorry I am not able to understand to your question yet."
let notYetImplemented = "Sorry this feature has not yet be implemented. Come back soon"
function response(text) {
if (text.match(/^(hi|hello|ola|hey|salut)\s*[!?.]*$/)) {
//TODO greeting
return notYetImplemented
} else if (text ==='help') {
//TODO help
return notYetImplemented
}
else if (text.match(/^who */)) {
//TODO find player/team
return notYetImplemented
} else if (text.match(/^when */)) {
//TODO find when next game of a team will play
return notYetImplemented
} else if (text.match(/^where */)) {
//TODO find where a game will be be played
return notYetImplemented
} else if (text.match(/^(follow|subscribe) */)) {
//TODO implement follow capability and specific message
return notYetImplemented
} else if (text == 'latest news') {
//TODO capi query with lastest news about euro
return notYetImplemented
} else {
return notUnderstood
}
}
function nextGame(team) {
}
let port = process.env.PORT
http.createServer(bot.middleware()).listen(port)
console.log('Echo bot server running at port ' + port)