mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-18 05:20:48 +00:00
* 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
108 lines
2.9 KiB
TypeScript
108 lines
2.9 KiB
TypeScript
import type { ReplyToMode } from "../../../src/config/config.js";
|
|
import type { TelegramAccountConfig } from "../../../src/config/types.telegram.js";
|
|
import { danger } from "../../../src/globals.js";
|
|
import type { RuntimeEnv } from "../../../src/runtime.js";
|
|
import {
|
|
buildTelegramMessageContext,
|
|
type BuildTelegramMessageContextParams,
|
|
type TelegramMediaRef,
|
|
} from "./bot-message-context.js";
|
|
import { dispatchTelegramMessage } from "./bot-message-dispatch.js";
|
|
import type { TelegramBotOptions } from "./bot.js";
|
|
import type { TelegramContext, TelegramStreamMode } from "./bot/types.js";
|
|
|
|
/** Dependencies injected once when creating the message processor. */
|
|
type TelegramMessageProcessorDeps = Omit<
|
|
BuildTelegramMessageContextParams,
|
|
"primaryCtx" | "allMedia" | "storeAllowFrom" | "options"
|
|
> & {
|
|
telegramCfg: TelegramAccountConfig;
|
|
runtime: RuntimeEnv;
|
|
replyToMode: ReplyToMode;
|
|
streamMode: TelegramStreamMode;
|
|
textLimit: number;
|
|
opts: Pick<TelegramBotOptions, "token">;
|
|
};
|
|
|
|
export const createTelegramMessageProcessor = (deps: TelegramMessageProcessorDeps) => {
|
|
const {
|
|
bot,
|
|
cfg,
|
|
account,
|
|
telegramCfg,
|
|
historyLimit,
|
|
groupHistories,
|
|
dmPolicy,
|
|
allowFrom,
|
|
groupAllowFrom,
|
|
ackReactionScope,
|
|
logger,
|
|
resolveGroupActivation,
|
|
resolveGroupRequireMention,
|
|
resolveTelegramGroupConfig,
|
|
sendChatActionHandler,
|
|
runtime,
|
|
replyToMode,
|
|
streamMode,
|
|
textLimit,
|
|
opts,
|
|
} = deps;
|
|
|
|
return async (
|
|
primaryCtx: TelegramContext,
|
|
allMedia: TelegramMediaRef[],
|
|
storeAllowFrom: string[],
|
|
options?: { messageIdOverride?: string; forceWasMentioned?: boolean },
|
|
replyMedia?: TelegramMediaRef[],
|
|
) => {
|
|
const context = await buildTelegramMessageContext({
|
|
primaryCtx,
|
|
allMedia,
|
|
replyMedia,
|
|
storeAllowFrom,
|
|
options,
|
|
bot,
|
|
cfg,
|
|
account,
|
|
historyLimit,
|
|
groupHistories,
|
|
dmPolicy,
|
|
allowFrom,
|
|
groupAllowFrom,
|
|
ackReactionScope,
|
|
logger,
|
|
resolveGroupActivation,
|
|
resolveGroupRequireMention,
|
|
resolveTelegramGroupConfig,
|
|
sendChatActionHandler,
|
|
});
|
|
if (!context) {
|
|
return;
|
|
}
|
|
try {
|
|
await dispatchTelegramMessage({
|
|
context,
|
|
bot,
|
|
cfg,
|
|
runtime,
|
|
replyToMode,
|
|
streamMode,
|
|
textLimit,
|
|
telegramCfg,
|
|
opts,
|
|
});
|
|
} catch (err) {
|
|
runtime.error?.(danger(`telegram message processing failed: ${String(err)}`));
|
|
try {
|
|
await bot.api.sendMessage(
|
|
context.chatId,
|
|
"Something went wrong while processing your request. Please try again.",
|
|
context.threadSpec?.id != null ? { message_thread_id: context.threadSpec.id } : undefined,
|
|
);
|
|
} catch {
|
|
// Best-effort fallback; delivery may fail if the bot was blocked or the chat is invalid.
|
|
}
|
|
}
|
|
};
|
|
};
|