Files
openclaw/extensions/telegram/src/send-error-predicates.ts
Peter Steinberger c636060f04 fix(telegram): preserve voice fallback text
Preserve visible text when Telegram rejects a voice note for recipient privacy.

Co-authored-by: Peter Steinberger <steipete@macos.shared>
2026-08-07 08:18:31 +05:30

25 lines
1.0 KiB
TypeScript

import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
const TELEGRAM_CAPTION_TOO_LONG_RE = /caption is too long/i;
const TELEGRAM_PHOTO_LIMIT_ERROR_RE = /\b(?:PHOTO_INVALID_DIMENSIONS|PHOTO_TOO_BIG)\b/i;
const TELEGRAM_VOICE_FORBIDDEN_MARKER = "VOICE_MESSAGES_FORBIDDEN";
function resolveTelegramErrorDescription(error: unknown): string {
return isRecord(error) && typeof error.description === "string"
? error.description
: formatErrorMessage(error);
}
export function isTelegramCaptionTooLongError(error: unknown): boolean {
return TELEGRAM_CAPTION_TOO_LONG_RE.test(resolveTelegramErrorDescription(error));
}
export function isTelegramPhotoLimitError(error: unknown): boolean {
return TELEGRAM_PHOTO_LIMIT_ERROR_RE.test(resolveTelegramErrorDescription(error));
}
export function isTelegramVoiceMessagesForbiddenError(error: unknown): boolean {
return resolveTelegramErrorDescription(error).includes(TELEGRAM_VOICE_FORBIDDEN_MARKER);
}