mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-30 13:15:03 +00:00
fix(telegram): prevent duplicate messages with slow LLM providers (#41932)
Merged via squash.
Prepared head SHA: 2f50c51d5a
Co-authored-by: hougangdev <105773686+hougangdev@users.noreply.github.com>
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Reviewed-by: @obviyus
This commit is contained in:
@@ -123,6 +123,29 @@ export function isSafeToRetrySendError(err: unknown): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
function hasTelegramErrorCode(err: unknown, matches: (code: number) => boolean): boolean {
|
||||
for (const candidate of collectTelegramErrorCandidates(err)) {
|
||||
if (!candidate || typeof candidate !== "object" || !("error_code" in candidate)) {
|
||||
continue;
|
||||
}
|
||||
const code = (candidate as { error_code: unknown }).error_code;
|
||||
if (typeof code === "number" && matches(code)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Returns true for HTTP 5xx server errors (error may have been processed). */
|
||||
export function isTelegramServerError(err: unknown): boolean {
|
||||
return hasTelegramErrorCode(err, (code) => code >= 500);
|
||||
}
|
||||
|
||||
/** Returns true for HTTP 4xx client errors (Telegram explicitly rejected, not applied). */
|
||||
export function isTelegramClientRejection(err: unknown): boolean {
|
||||
return hasTelegramErrorCode(err, (code) => code >= 400 && code < 500);
|
||||
}
|
||||
|
||||
export function isRecoverableTelegramNetworkError(
|
||||
err: unknown,
|
||||
options: { context?: TelegramNetworkErrorContext; allowMessageMatch?: boolean } = {},
|
||||
|
||||
Reference in New Issue
Block a user