-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.ts
More file actions
90 lines (74 loc) · 2.43 KB
/
main.ts
File metadata and controls
90 lines (74 loc) · 2.43 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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import _Werror from './lib/werror.ts';
import logger from './lib/logger.ts';
import resolveConfig, { Config } from './lib/config.ts';
import setupBot from './lib/telegram/setup-bot.ts';
import { run } from '@grammyjs/runner';
import { loadMemory } from './lib/memory.ts';
import { migrateDb } from './lib/db/migrate.ts';
// AI runtime details moved to handler module
// reply helpers used inside handler module
// rate limiter helpers moved to middlewares
import registerAll from './lib/telegram/register-all.ts';
import { startTelemetry } from './lib/app/observability.ts';
import { startSchedulers } from './lib/app/scheduler.ts';
import { wireShutdown } from './lib/app/shutdown.ts';
import { startWebServer } from './lib/web/server.ts';
const sdk = startTelemetry();
// (schemas and reaction utilities moved to dedicated modules)
let config: Config;
await migrateDb();
const memory = await loadMemory();
logger.info('Memory loaded');
try {
config = await resolveConfig(memory.db);
} catch (error) {
logger.error('Config error: ', error);
Deno.exit(1);
}
const runtimeConfig = {
getBotToken: () => config.botToken,
};
const bot = await setupBot(config, memory);
startWebServer({
bot,
memory,
runtimeConfig,
});
// Register everything in correct order
registerAll(bot, config);
run(bot, {
runner: {
// @ts-expect-error drop_pending_updates is supported by grammY runner
drop_pending_updates: true,
fetch: {
allowed_updates: [
'message',
'edited_message',
'channel_post',
'edited_channel_post',
'business_connection',
'business_message',
'edited_business_message',
'deleted_business_messages',
'inline_query',
'chosen_inline_result',
'callback_query',
'shipping_query',
'pre_checkout_query',
'poll',
'poll_answer',
'my_chat_member',
'chat_join_request',
'chat_boost',
'removed_chat_boost',
'message_reaction',
'message_reaction_count',
] as const,
},
},
});
logger.info('Bot started');
// TODO: Remind users about bot existence
const _stopSchedulers = startSchedulers({ db: memory.db, logger });
// Save memory on exit
wireShutdown(bot, sdk);