-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
44 lines (36 loc) · 1.09 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
const Bot = require('node-telegram-bot-api');
const start = require('./message-handlers/handle-start');
const register = require('./message-handlers/handle-register');
const order = require('./message-handlers/handle-order');
const token = process.env.TELEGRAM_TOKEN;
let bot;
if(process.env.NODE_ENV === 'production') {
bot = new Bot(token);
bot.setWebHook(process.env.HEROKU_URL + bot.token);
}
else {
bot = new Bot(token, { polling: true });
}
console.log('Bot server started in ' + process.env.NODE_ENV + ' mode');
bot.onText(/^/, (message) => {
if (message.text === '/start') {
console.log('Handling start message.');
start(bot, message);
return;
}
if (message.text === '/NotifyMe') {
console.log('Handling order message.');
order(bot, message);
return;
}
console.log('Unknown message recieved.');
bot.sendMessage(message.chat.id, 'Say waaaat?');
});
bot.on('message', (message) => {
if (typeof (message.contact) !== 'undefined') {
console.log('Handling register message.');
register(bot, message);
return;
}
});
module.exports = bot;