refactor(telegram): use grammY native helpers

This commit is contained in:
Ayaan Zaidi
2026-05-07 08:55:41 +05:30
parent 53efb6747d
commit 923ea990fd
2 changed files with 5 additions and 60 deletions

View File

@@ -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<TelegramUpdateType> =
grammy.API_CONSTANTS?.DEFAULT_UPDATE_TYPES ?? FALLBACK_DEFAULT_UPDATE_TYPES;
API_CONSTANTS.DEFAULT_UPDATE_TYPES;
export function resolveTelegramAllowedUpdates(): ReadonlyArray<TelegramUpdateType> {
const updates = [...DEFAULT_TELEGRAM_UPDATE_TYPES] as TelegramUpdateType[];

View File

@@ -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<typeof createServer>;
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) {