

























@@ -339,16 +339,11 @@ export const registerTelegramHandlers = ({
339339entities: undefined,
340340 ...(params.date != null ? { date: params.date } : {}),
341341});
342+// grammy's Context.getFile reads update state via `this`; keep the receiver bound.
342343const buildSyntheticContext = (
343-ctx: Pick<TelegramContext, "me"> & { getFile?: unknown },
344+ctx: Pick<TelegramContext, "me" | "getFile">,
344345message: 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) });
352347353348const MULTI_SELECT_PREFIX = "OC_MULTI|";
354349const MULTI_SELECT_TOGGLE_PREFIX = `${MULTI_SELECT_PREFIX}toggle|`;
@@ -463,7 +458,7 @@ export const registerTelegramHandlers = ({
463458}),
464459);
465460const buildCallbackSyntheticTextContext = (params: {
466-ctx: Pick<TelegramContext, "me"> & { getFile?: unknown };
461+ctx: Pick<TelegramContext, "me" | "getFile">;
467462callbackMessage: Message;
468463callback: { from?: Message["from"] };
469464text: string;
@@ -1265,10 +1260,7 @@ export const registerTelegramHandlers = ({
12651260type TelegramGroupAllowContext = Awaited<ReturnType<typeof resolveTelegramGroupAllowFromContext>>;
12661261type TelegramEventAuthorizationMode = "reaction" | "callback-scope" | "callback-allowlist";
12671262type 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);
1272126412731265const TELEGRAM_EVENT_AUTH_RULES: Record<
12741266TelegramEventAuthorizationMode,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。