-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.mjs
67 lines (52 loc) · 2.01 KB
/
app.mjs
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
import express from "express";
import {
Telegraf,
session,
Scenes
} from 'telegraf';
import { SQLite } from "@telegraf/session/sqlite";
import {
onStart,
onReset
} from './scr/telegram/middleware/middleware.commands.mjs';
import { onInline } from './scr/telegram/middleware/middleware.inline-handler.mjs';
import { runBitrixJob } from "./scr/bitrix/bootstrap.mjs";
import { carPickResponse } from "./scr/telegram/middleware/middleware.car-pick-response.mjs";
import { enterCarVisScene } from "./scr/telegram/middleware/middleware.enter-car-vis-scene.mjs";
import { sceneCarVis } from "./scr/telegram/scenes/scene.car.vis.mjs";
import { sceneCarVisVideoPart } from "./scr/telegram/scenes/scene.car.vis.video.part.mjs";
import { refreshCarlist } from "./scr/bitrix/modules/refresh-car-list.mjs";
const bot = new Telegraf(process.env.TELEGRAM_API_KEY);
const store = SQLite({
filename: "./telegraf-sessions.sqlite",
});
bot.use(session({ store }));
const stage = new Scenes.Stage([sceneCarVis, sceneCarVisVideoPart]);
bot.use(stage.middleware());
const app = express();
(async () => {
runBitrixJob();
bot.start(onStart);
bot.inlineQuery(onInline);
bot.on('chosen_inline_result', carPickResponse);
bot.on('callback_query', enterCarVisScene);
bot.command('refresh_cars', async (ctx, next) => {
ctx.sendChatAction('typing');
const result = await refreshCarlist();
ctx.reply(`Refresh with ${result} cars`)
console.log({ time: new Date(), result })
await next();
});
if (process.env.ENV == 'test') {
bot.command('reset', onReset);
bot.launch();
process.once('SIGINT', () => bot.stop('SIGINT'))
process.once('SIGTERM', () => bot.stop('SIGTERM'))
}
if (process.env.ENV == 'prod') {
app.use(await bot.createWebhook({ domain: process.env.HOST, path: process.env.HOST_PATH }));
app.listen(process.env.PORT, () => {
console.log(`Cheklistbot listen at ${process.env.PORT}`);
});
}
})()