@@ -339,16 +339,11 @@ export const registerTelegramHandlers = ({
339339 entities : undefined ,
340340 ...( params . date != null ? { date : params . date } : { } ) ,
341341 } ) ;
342+ // grammy's Context.getFile reads update state via `this`; keep the receiver bound.
342343 const buildSyntheticContext = (
343- ctx : Pick < TelegramContext , "me" > & { getFile ?: unknown } ,
344+ ctx : Pick < TelegramContext , "me" | " getFile" > ,
344345 message : Message ,
345- ) : TelegramContext => {
346- const getFile =
347- typeof ctx . getFile === "function"
348- ? ( ctx . getFile as TelegramContext [ "getFile" ] ) . bind ( ctx as object )
349- : async ( ) => ( { } ) ;
350- return { message, me : ctx . me , getFile } ;
351- } ;
346+ ) : TelegramContext => ( { message, me : ctx . me , getFile : ctx . getFile . bind ( ctx ) } ) ;
352347
353348 const MULTI_SELECT_PREFIX = "OC_MULTI|" ;
354349 const MULTI_SELECT_TOGGLE_PREFIX = `${ MULTI_SELECT_PREFIX } toggle|` ;
@@ -463,7 +458,7 @@ export const registerTelegramHandlers = ({
463458 } ) ,
464459 ) ;
465460 const buildCallbackSyntheticTextContext = ( params : {
466- ctx : Pick < TelegramContext , "me" > & { getFile ?: unknown } ;
461+ ctx : Pick < TelegramContext , "me" | " getFile" > ;
467462 callbackMessage : Message ;
468463 callback : { from ?: Message [ "from" ] } ;
469464 text : string ;
@@ -1265,10 +1260,7 @@ export const registerTelegramHandlers = ({
12651260 type TelegramGroupAllowContext = Awaited < ReturnType < typeof resolveTelegramGroupAllowFromContext > > ;
12661261 type TelegramEventAuthorizationMode = "reaction" | "callback-scope" | "callback-allowlist" ;
12671262 type TelegramEventAuthorizationContext = TelegramGroupAllowContext & { dmPolicy : DmPolicy } ;
1268- const getChat =
1269- typeof ( bot . api as { getChat ?: unknown } ) . getChat === "function"
1270- ? ( bot . api as { getChat : TelegramGetChat } ) . getChat . bind ( bot . api )
1271- : undefined ;
1263+ const getChat : TelegramGetChat = bot . api . getChat . bind ( bot . api ) ;
12721264
12731265 const TELEGRAM_EVENT_AUTH_RULES : Record <
12741266 TelegramEventAuthorizationMode ,
0 commit comments