-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (28 loc) · 1.27 KB
/
index.js
File metadata and controls
36 lines (28 loc) · 1.27 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
'use strict';
const Telegram = require('telegram-node-bot'),
PersistentMemoryStorage = require('./adapters/PersistentMemoryStorage'),
storage = new PersistentMemoryStorage(
`${__dirname}/data/userStorage.json`,
`${__dirname}/data/chatStorage.json`
),
tg = new Telegram.Telegram('Your Api key from botfather in telegram', {
workers : 1,
storage : storage
});
const PingController = require('./controller/ping');
const OtherwiseController = require('./controller/otherwise');
const TodoController = require('./controller/todo');
const ToController = require('./controller/todo');
tg.router.when(new Telegram.TextCommand('/ping', 'pingCommand'), new PingController())
.otherwise(new OtherwiseController());
tg.router.when(new Telegram.TextCommand('/add', 'addCommand'), new TodoController())
.when(new Telegram.TextCommand('/get', 'getCommand'), new ToController())
// .when(new Telegram.TextCommand('/start', 'startCommand'), new ToController())
.when(new Telegram.TextCommand('/check', 'checkCommand'), new ToController())
.otherwise(new OtherwiseController());
function exitHandler(exitCode){
storage.flush();
process.exit(exitCode);
}
process.on('SIGINT', exitHandler.bind(null, 0));
process.on('uncaughtException', exitHandler.bind(null, 1));