mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-16 15:43:57 -06:00
c636060f04
Preserve visible text when Telegram rejects a voice note for recipient privacy. Co-authored-by: Peter Steinberger <steipete@macos.shared>
25 lines
1.0 KiB
TypeScript
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);
|
|
}
|