fix(ci): harden telegram seams and cap job timeouts

This commit is contained in:
Vincent Koc
2026-03-22 21:38:26 -07:00
parent 6eafa2ec87
commit 09cb77ed38
8 changed files with 95 additions and 10 deletions

View File

@@ -43,6 +43,8 @@ import {
const VOICE_FORBIDDEN_RE = /VOICE_MESSAGES_FORBIDDEN/;
const CAPTION_TOO_LONG_RE = /caption is too long/i;
const GrammyErrorCtor: typeof GrammyError | undefined =
typeof GrammyError === "function" ? GrammyError : undefined;
type DeliveryProgress = ReplyThreadDeliveryProgress & {
deliveredCount: number;
@@ -175,14 +177,14 @@ async function sendPendingFollowUpText(params: {
}
function isVoiceMessagesForbidden(err: unknown): boolean {
if (err instanceof GrammyError) {
if (GrammyErrorCtor && err instanceof GrammyErrorCtor) {
return VOICE_FORBIDDEN_RE.test(err.description);
}
return VOICE_FORBIDDEN_RE.test(formatErrorMessage(err));
}
function isCaptionTooLong(err: unknown): boolean {
if (err instanceof GrammyError) {
if (GrammyErrorCtor && err instanceof GrammyErrorCtor) {
return CAPTION_TOO_LONG_RE.test(err.description);
}
return CAPTION_TOO_LONG_RE.test(formatErrorMessage(err));

View File

@@ -15,6 +15,9 @@ import { resolveTelegramMediaPlaceholder } from "./helpers.js";
import type { StickerMetadata, TelegramContext } from "./types.js";
const FILE_TOO_BIG_RE = /file is too big/i;
const GrammyErrorCtor: typeof GrammyError | undefined =
typeof GrammyError === "function" ? GrammyError : undefined;
function buildTelegramMediaSsrfPolicy(apiRoot?: string) {
const hostnames = ["api.telegram.org"];
if (apiRoot) {
@@ -41,7 +44,7 @@ function buildTelegramMediaSsrfPolicy(apiRoot?: string) {
* Unlike network errors, this is a permanent error and should not be retried.
*/
function isFileTooBigError(err: unknown): boolean {
if (err instanceof GrammyError) {
if (GrammyErrorCtor && err instanceof GrammyErrorCtor) {
return FILE_TOO_BIG_RE.test(err.description);
}
return FILE_TOO_BIG_RE.test(formatErrorMessage(err));

View File

@@ -9,9 +9,11 @@ import { buildTelegramThreadParams, type TelegramThreadSpec } from "./helpers.js
const PARSE_ERR_RE = /can't parse entities|parse entities|find end of the entity/i;
const EMPTY_TEXT_ERR_RE = /message text is empty/i;
const THREAD_NOT_FOUND_RE = /message thread not found/i;
const GrammyErrorCtor: typeof GrammyError | undefined =
typeof GrammyError === "function" ? GrammyError : undefined;
function isTelegramThreadNotFoundError(err: unknown): boolean {
if (err instanceof GrammyError) {
if (GrammyErrorCtor && err instanceof GrammyErrorCtor) {
return THREAD_NOT_FOUND_RE.test(err.description);
}
return THREAD_NOT_FOUND_RE.test(formatErrorMessage(err));