refactor(telegram): use grammY native helpers · openclaw/openclaw@923ea99
obviyus
·
2026-05-07
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | | -import * as grammy from "grammy"; |
| 1 | +import { API_CONSTANTS } from "grammy"; |
2 | 2 | |
3 | | -const FALLBACK_ALL_UPDATE_TYPES = [ |
4 | | -"message", |
5 | | -"edited_message", |
6 | | -"channel_post", |
7 | | -"edited_channel_post", |
8 | | -"business_connection", |
9 | | -"business_message", |
10 | | -"edited_business_message", |
11 | | -"deleted_business_messages", |
12 | | -"message_reaction", |
13 | | -"message_reaction_count", |
14 | | -"inline_query", |
15 | | -"chosen_inline_result", |
16 | | -"callback_query", |
17 | | -"shipping_query", |
18 | | -"pre_checkout_query", |
19 | | -"poll", |
20 | | -"poll_answer", |
21 | | -"my_chat_member", |
22 | | -"chat_member", |
23 | | -"chat_join_request", |
24 | | -] as const; |
25 | | - |
26 | | -const FALLBACK_DEFAULT_UPDATE_TYPES = [ |
27 | | -"message", |
28 | | -"edited_message", |
29 | | -"channel_post", |
30 | | -"edited_channel_post", |
31 | | -"business_connection", |
32 | | -"business_message", |
33 | | -"edited_business_message", |
34 | | -"deleted_business_messages", |
35 | | -"message_reaction", |
36 | | -"message_reaction_count", |
37 | | -"inline_query", |
38 | | -"chosen_inline_result", |
39 | | -"callback_query", |
40 | | -"shipping_query", |
41 | | -"pre_checkout_query", |
42 | | -"poll", |
43 | | -"poll_answer", |
44 | | -"my_chat_member", |
45 | | -"chat_member", |
46 | | -"chat_join_request", |
47 | | -] as const; |
48 | | - |
49 | | -export type TelegramUpdateType = |
50 | | -| (typeof FALLBACK_ALL_UPDATE_TYPES)[number] |
51 | | -| (typeof grammy.API_CONSTANTS.ALL_UPDATE_TYPES)[number]; |
| 3 | +export type TelegramUpdateType = (typeof API_CONSTANTS.ALL_UPDATE_TYPES)[number]; |
52 | 4 | |
53 | 5 | export const DEFAULT_TELEGRAM_UPDATE_TYPES: ReadonlyArray<TelegramUpdateType> = |
54 | | -grammy.API_CONSTANTS?.DEFAULT_UPDATE_TYPES ?? FALLBACK_DEFAULT_UPDATE_TYPES; |
| 6 | +API_CONSTANTS.DEFAULT_UPDATE_TYPES; |
55 | 7 | |
56 | 8 | export function resolveTelegramAllowedUpdates(): ReadonlyArray<TelegramUpdateType> { |
57 | 9 | const updates = [...DEFAULT_TELEGRAM_UPDATE_TYPES] as TelegramUpdateType[]; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import { createServer } from "node:http"; |
2 | 2 | import type { IncomingMessage } from "node:http"; |
3 | 3 | import net from "node:net"; |
4 | | -import * as grammy from "grammy"; |
| 4 | +import { InputFile } from "grammy"; |
5 | 5 | import type { ChannelAccountSnapshot } from "openclaw/plugin-sdk/channel-contract"; |
6 | 6 | import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types"; |
7 | 7 | import { isDiagnosticsEnabled } from "openclaw/plugin-sdk/diagnostic-runtime"; |
@@ -46,13 +46,6 @@ const TELEGRAM_WEBHOOK_REGISTRATION_RETRY_POLICY: BackoffPolicy = {
|
46 | 46 | factor: 2, |
47 | 47 | jitter: 0.2, |
48 | 48 | }; |
49 | | -const InputFileCtor: typeof grammy.InputFile = |
50 | | -typeof grammy.InputFile === "function" |
51 | | - ? grammy.InputFile |
52 | | - : (class InputFileFallback { |
53 | | -constructor(public readonly path: string) {} |
54 | | -} as unknown as typeof grammy.InputFile); |
55 | | - |
56 | 49 | async function listenHttpServer(params: { |
57 | 50 | server: ReturnType<typeof createServer>; |
58 | 51 | port: number; |
@@ -462,7 +455,7 @@ export async function startTelegramWebhook(opts: {
|
462 | 455 | bot.api.setWebhook(publicUrl, { |
463 | 456 | secret_token: secret, |
464 | 457 | allowed_updates: resolveTelegramAllowedUpdates(), |
465 | | -certificate: opts.webhookCertPath ? new InputFileCtor(opts.webhookCertPath) : undefined, |
| 458 | +certificate: opts.webhookCertPath ? new InputFile(opts.webhookCertPath) : undefined, |
466 | 459 | }), |
467 | 460 | }); |
468 | 461 | } catch (err) { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。