


























@@ -1,8 +1,10 @@
11import { type Bot, GrammyError } from "grammy";
2+import { createTelegramRetryRunner } from "openclaw/plugin-sdk/retry-runtime";
23import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
34import { formatErrorMessage } from "openclaw/plugin-sdk/ssrf-runtime";
45import { withTelegramApiErrorLogging } from "../api-logging.js";
56import { markdownToTelegramHtml } from "../format.js";
7+import { isSafeToRetrySendError, isTelegramRateLimitError } from "../network-errors.js";
68import {
79buildTelegramSendParams,
810getTelegramNativeQuoteReplyMessageId,
@@ -51,6 +53,13 @@ function removeMessageThreadIdParam(
5153return rest;
5254}
535556+function createTelegramDeliverySendRetry() {
57+return createTelegramRetryRunner({
58+shouldRetry: (err) => isSafeToRetrySendError(err) || isTelegramRateLimitError(err),
59+strictShouldRetry: true,
60+});
61+}
62+5463export async function sendTelegramWithThreadFallback<T>(params: {
5564operation: string;
5665runtime: RuntimeEnv;
@@ -68,14 +77,21 @@ export async function sendTelegramWithThreadFallback<T>(params: {
6877const mergedShouldLog = params.shouldLog
6978 ? (err: unknown) => params.shouldLog!(err) && !shouldSuppressFirstErrorLog(err)
7079 : (err: unknown) => !shouldSuppressFirstErrorLog(err);
71-72-try {
73-return await withTelegramApiErrorLogging({
74-operation: params.operation,
80+const requestWithRetry = createTelegramDeliverySendRetry();
81+const runLoggedSend = (
82+operation: string,
83+requestParams: Record<string, unknown>,
84+shouldLog?: (err: unknown) => boolean,
85+) =>
86+withTelegramApiErrorLogging({
87+ operation,
7588runtime: params.runtime,
76-shouldLog: mergedShouldLog,
77-fn: () => params.send(params.requestParams),
89+...(shouldLog ? { shouldLog } : {}),
90+fn: () => requestWithRetry(() => params.send(requestParams), operation),
7891});
92+93+try {
94+return await runLoggedSend(params.operation, params.requestParams, mergedShouldLog);
7995} catch (err) {
8096if (hasNativeQuote && isTelegramQuoteParamError(err)) {
8197params.runtime.log?.(
@@ -94,11 +110,7 @@ export async function sendTelegramWithThreadFallback<T>(params: {
94110params.runtime.log?.(
95111`telegram ${params.operation}: message thread not found; retrying without message_thread_id`,
96112);
97-return await withTelegramApiErrorLogging({
98-operation: `${params.operation} (threadless retry)`,
99-runtime: params.runtime,
100-fn: () => params.send(retryParams),
101-});
113+return await runLoggedSend(`${params.operation} (threadless retry)`, retryParams);
102114}
103115}
104116此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。