-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (38 loc) · 1.42 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
'use strict';
// const request = require('request-promise');
// const options = {
// method: 'GET',
// uri: 'https://api.telegram.org/bot646247640:AAFTztegZGgyeFMpXXLdLnfWyNLrAesF6oY/getUpdates',
// json: true,
// }
// request(options)
// .then((response) => {
// console.log(response);
// })
// .catch((err) => {
// });
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('646247640:AAFTztegZGgyeFMpXXLdLnfWyNLrAesF6oY', {
workers: 1,
storage: storage
});
const TodoController = require('./controllers/todo'),
OtherwiseController = require('./controllers/otherwise');
const todoCtrl = new TodoController();
tg.router.when(new Telegram.TextCommand('/add', 'addCommand'), todoCtrl)
.when(new Telegram.TextCommand('/get', 'getCommand'), todoCtrl)
.when(new Telegram.TextCommand('/check', 'checkCommand'), todoCtrl)
.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), (error) => {
// console.log("\x1b[31m", "Exception: ", error, "\x1b[0m");
// });