-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
41 lines (35 loc) · 1.2 KB
/
app.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
const Telegraf = require('telegraf');
const RedisSession = require('telegraf-session-redis');
const LocalSession = require('telegraf-session-local');
const TelegrafI18n = require('telegraf-i18n');
const bluebird = require('bluebird');
const mongoose = require('mongoose');
const path = require('path');
require('./src/models');
const config = require('./config');
const handlers = require('./src/handlers');
const middlewares = require('./src/middlewares');
const bot = new Telegraf(config.botToken, { username: config.botUsername });
const telegrafI18n = new TelegrafI18n({
directory: path.resolve(__dirname, 'config/locales'),
defaultLanguage: 'en',
useSession: true,
});
mongoose.Promise = bluebird;
mongoose.connect(config.mongoUrl, { useMongoClient: true });
if (config.useLocalSession) {
const localSession = new LocalSession({ database: 'db.json' });
bot.use(localSession.middleware());
} else {
const redisSession = new RedisSession({
store: { url: config.redisUrl },
});
bot.use(redisSession.middleware());
}
bot.use(telegrafI18n.middleware());
bot.use(middlewares);
bot.use(handlers.commands, handlers.messages, handlers.other);
bot.catch((err) => {
console.error(err);
});
bot.startPolling();