mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-16 23:52:40 -06:00
84cfc43684
Keep Telegram Bot API deadlines and cancellation active until grammY finishes consuming each response body. Cancel discarded HTTP 421 bodies before retry and cover the stalled group-dispatch boundary with typed socket and live Telegram proof.
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
// Telegram plugin module implements api logging behavior.
|
|
import { createSubsystemLogger } from "openclaw/plugin-sdk/runtime-env";
|
|
import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
|
|
import { formatErrorMessage } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
|
|
type TelegramApiLogger = (message: string) => void;
|
|
|
|
type TelegramApiLoggingParams<T> = {
|
|
operation: string;
|
|
fn: () => Promise<T>;
|
|
runtime?: Pick<RuntimeEnv, "error">;
|
|
logger?: TelegramApiLogger;
|
|
shouldLog?: (err: unknown) => boolean;
|
|
};
|
|
|
|
const fallbackLogger = createSubsystemLogger("telegram/api");
|
|
|
|
function resolveTelegramApiLogger(runtime?: Pick<RuntimeEnv, "error">, logger?: TelegramApiLogger) {
|
|
if (logger) {
|
|
return logger;
|
|
}
|
|
if (runtime?.error) {
|
|
return runtime.error;
|
|
}
|
|
return (message: string) => fallbackLogger.error(message);
|
|
}
|
|
|
|
export async function withTelegramApiErrorLogging<T>({
|
|
operation,
|
|
fn,
|
|
runtime,
|
|
logger,
|
|
shouldLog,
|
|
}: TelegramApiLoggingParams<T>): Promise<T> {
|
|
try {
|
|
return await fn();
|
|
} catch (err) {
|
|
if (!shouldLog || shouldLog(err)) {
|
|
const errText = formatErrorMessage(err);
|
|
const log = resolveTelegramApiLogger(runtime, logger);
|
|
log(`telegram ${operation} failed: ${errText}`);
|
|
}
|
|
throw err;
|
|
}
|
|
}
|