1- import type { Context , SessionData } from '#root/bot/context.js'
1+ import type { Context } from '#root/bot/context.js'
22import type { Config } from '#root/config.js'
33import type { Logger } from '#root/logger.js'
4- import type { BotConfig , StorageAdapter } from 'grammy'
5- import { createContextConstructor } from '#root/bot/context.js'
4+ import type { BotConfig } from 'grammy'
65import { adminFeature } from '#root/bot/features/admin.js'
76import { languageFeature } from '#root/bot/features/language.js'
87import { unhandledFeature } from '#root/bot/features/unhandled.js'
@@ -15,35 +14,34 @@ import { autoChatAction } from '@grammyjs/auto-chat-action'
1514import { hydrate } from '@grammyjs/hydrate'
1615import { hydrateReply , parseMode } from '@grammyjs/parse-mode'
1716import { sequentialize } from '@grammyjs/runner'
18- import { Bot as TelegramBot } from 'grammy'
17+ import { MemorySessionStorage , Bot as TelegramBot } from 'grammy'
1918
2019interface Dependencies {
2120 config : Config
2221 logger : Logger
2322}
2423
25- interface Options {
26- botSessionStorage ?: StorageAdapter < SessionData >
27- botConfig ?: Omit < BotConfig < Context > , 'ContextConstructor' >
28- }
29-
3024function getSessionKey ( ctx : Omit < Context , 'session' > ) {
3125 return ctx . chat ?. id . toString ( )
3226}
3327
34- export function createBot ( token : string , dependencies : Dependencies , options : Options = { } ) {
28+ export function createBot ( token : string , dependencies : Dependencies , botConfig ?: BotConfig < Context > ) {
3529 const {
3630 config,
3731 logger,
3832 } = dependencies
3933
40- const bot = new TelegramBot ( token , {
41- ...options . botConfig ,
42- ContextConstructor : createContextConstructor ( {
43- logger,
44- config,
45- } ) ,
34+ const bot = new TelegramBot < Context > ( token , botConfig )
35+
36+ bot . use ( async ( ctx , next ) => {
37+ ctx . config = config
38+ ctx . logger = logger . child ( {
39+ update_id : ctx . update . update_id ,
40+ } )
41+
42+ await next ( )
4643 } )
44+
4745 const protectedBot = bot . errorBoundary ( errorHandler )
4846
4947 // Middlewares
@@ -56,7 +54,10 @@ export function createBot(token: string, dependencies: Dependencies, options: Op
5654 protectedBot . use ( autoChatAction ( bot . api ) )
5755 protectedBot . use ( hydrateReply )
5856 protectedBot . use ( hydrate ( ) )
59- protectedBot . use ( session ( { getSessionKey, storage : options . botSessionStorage } ) )
57+ protectedBot . use ( session ( {
58+ getSessionKey,
59+ storage : new MemorySessionStorage ( ) ,
60+ } ) )
6061 protectedBot . use ( i18n )
6162
6263 // Handlers
0 commit comments