mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-25 16:12:13 +00:00
refactor: move Telegram channel implementation to extensions/ (#45635)
* refactor: move Telegram channel implementation to extensions/telegram/src/ Move all Telegram channel code (123 files + 10 bot/ files + 8 channel plugin files) from src/telegram/ and src/channels/plugins/*/telegram.ts to extensions/telegram/src/. Leave thin re-export shims at original locations so cross-cutting src/ imports continue to resolve. - Fix all relative import paths in moved files (../X/ -> ../../../src/X/) - Fix vi.mock paths in 60 test files - Fix inline typeof import() expressions - Update tsconfig.plugin-sdk.dts.json rootDir to "." for cross-directory DTS - Update write-plugin-sdk-entry-dts.ts for new rootDir structure - Move channel plugin files with correct path remapping * fix: support keyed telegram send deps * fix: sync telegram extension copies with latest main * fix: correct import paths and remove misplaced files in telegram extension * fix: sync outbound-adapter with main (add sendTelegramPayloadMessages) and fix delivery.test import path
This commit is contained in:
45
extensions/telegram/src/api-logging.ts
Normal file
45
extensions/telegram/src/api-logging.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { danger } from "../../../src/globals.js";
|
||||
import { formatErrorMessage } from "../../../src/infra/errors.js";
|
||||
import { createSubsystemLogger } from "../../../src/logging/subsystem.js";
|
||||
import type { RuntimeEnv } from "../../../src/runtime.js";
|
||||
|
||||
export type TelegramApiLogger = (message: string) => void;
|
||||
|
||||
type TelegramApiLoggingParams<T> = {
|
||||
operation: string;
|
||||
fn: () => Promise<T>;
|
||||
runtime?: RuntimeEnv;
|
||||
logger?: TelegramApiLogger;
|
||||
shouldLog?: (err: unknown) => boolean;
|
||||
};
|
||||
|
||||
const fallbackLogger = createSubsystemLogger("telegram/api");
|
||||
|
||||
function resolveTelegramApiLogger(runtime?: RuntimeEnv, 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(danger(`telegram ${operation} failed: ${errText}`));
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user