From 923ea990fd8831f3ca546af1cf3cee0874f73b4f Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Thu, 7 May 2026 08:55:41 +0530 Subject: [PATCH] refactor(telegram): use grammY native helpers --- extensions/telegram/src/allowed-updates.ts | 54 ++-------------------- extensions/telegram/src/webhook.ts | 11 +---- 2 files changed, 5 insertions(+), 60 deletions(-) diff --git a/extensions/telegram/src/allowed-updates.ts b/extensions/telegram/src/allowed-updates.ts index 3cfbc95da78..67b56fab20c 100644 --- a/extensions/telegram/src/allowed-updates.ts +++ b/extensions/telegram/src/allowed-updates.ts @@ -1,57 +1,9 @@ -import * as grammy from "grammy"; +import { API_CONSTANTS } from "grammy"; -const FALLBACK_ALL_UPDATE_TYPES = [ - "message", - "edited_message", - "channel_post", - "edited_channel_post", - "business_connection", - "business_message", - "edited_business_message", - "deleted_business_messages", - "message_reaction", - "message_reaction_count", - "inline_query", - "chosen_inline_result", - "callback_query", - "shipping_query", - "pre_checkout_query", - "poll", - "poll_answer", - "my_chat_member", - "chat_member", - "chat_join_request", -] as const; - -const FALLBACK_DEFAULT_UPDATE_TYPES = [ - "message", - "edited_message", - "channel_post", - "edited_channel_post", - "business_connection", - "business_message", - "edited_business_message", - "deleted_business_messages", - "message_reaction", - "message_reaction_count", - "inline_query", - "chosen_inline_result", - "callback_query", - "shipping_query", - "pre_checkout_query", - "poll", - "poll_answer", - "my_chat_member", - "chat_member", - "chat_join_request", -] as const; - -export type TelegramUpdateType = - | (typeof FALLBACK_ALL_UPDATE_TYPES)[number] - | (typeof grammy.API_CONSTANTS.ALL_UPDATE_TYPES)[number]; +export type TelegramUpdateType = (typeof API_CONSTANTS.ALL_UPDATE_TYPES)[number]; export const DEFAULT_TELEGRAM_UPDATE_TYPES: ReadonlyArray = - grammy.API_CONSTANTS?.DEFAULT_UPDATE_TYPES ?? FALLBACK_DEFAULT_UPDATE_TYPES; + API_CONSTANTS.DEFAULT_UPDATE_TYPES; export function resolveTelegramAllowedUpdates(): ReadonlyArray { const updates = [...DEFAULT_TELEGRAM_UPDATE_TYPES] as TelegramUpdateType[]; diff --git a/extensions/telegram/src/webhook.ts b/extensions/telegram/src/webhook.ts index 3d59acb90ec..ec2cd3fbeda 100644 --- a/extensions/telegram/src/webhook.ts +++ b/extensions/telegram/src/webhook.ts @@ -1,7 +1,7 @@ import { createServer } from "node:http"; import type { IncomingMessage } from "node:http"; import net from "node:net"; -import * as grammy from "grammy"; +import { InputFile } from "grammy"; import type { ChannelAccountSnapshot } from "openclaw/plugin-sdk/channel-contract"; import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types"; import { isDiagnosticsEnabled } from "openclaw/plugin-sdk/diagnostic-runtime"; @@ -46,13 +46,6 @@ const TELEGRAM_WEBHOOK_REGISTRATION_RETRY_POLICY: BackoffPolicy = { factor: 2, jitter: 0.2, }; -const InputFileCtor: typeof grammy.InputFile = - typeof grammy.InputFile === "function" - ? grammy.InputFile - : (class InputFileFallback { - constructor(public readonly path: string) {} - } as unknown as typeof grammy.InputFile); - async function listenHttpServer(params: { server: ReturnType; port: number; @@ -462,7 +455,7 @@ export async function startTelegramWebhook(opts: { bot.api.setWebhook(publicUrl, { secret_token: secret, allowed_updates: resolveTelegramAllowedUpdates(), - certificate: opts.webhookCertPath ? new InputFileCtor(opts.webhookCertPath) : undefined, + certificate: opts.webhookCertPath ? new InputFile(opts.webhookCertPath) : undefined, }), }); } catch (err) {