mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-13 19:10:39 +00:00
90 lines
2.1 KiB
TypeScript
90 lines
2.1 KiB
TypeScript
import type { ReplyToMode } from "../config/config.js";
|
|
import type { TelegramAccountConfig } from "../config/types.telegram.js";
|
|
import type { RuntimeEnv } from "../runtime.js";
|
|
import type { TelegramBotOptions } from "./bot.js";
|
|
import type { TelegramContext, TelegramStreamMode } from "./bot/types.js";
|
|
import {
|
|
buildTelegramMessageContext,
|
|
type BuildTelegramMessageContextParams,
|
|
type TelegramMediaRef,
|
|
} from "./bot-message-context.js";
|
|
import { dispatchTelegramMessage } from "./bot-message-dispatch.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,
|
|
runtime,
|
|
replyToMode,
|
|
streamMode,
|
|
textLimit,
|
|
opts,
|
|
} = deps;
|
|
|
|
return async (
|
|
primaryCtx: TelegramContext,
|
|
allMedia: TelegramMediaRef[],
|
|
storeAllowFrom: string[],
|
|
options?: { messageIdOverride?: string; forceWasMentioned?: boolean },
|
|
) => {
|
|
const context = await buildTelegramMessageContext({
|
|
primaryCtx,
|
|
allMedia,
|
|
storeAllowFrom,
|
|
options,
|
|
bot,
|
|
cfg,
|
|
account,
|
|
historyLimit,
|
|
groupHistories,
|
|
dmPolicy,
|
|
allowFrom,
|
|
groupAllowFrom,
|
|
ackReactionScope,
|
|
logger,
|
|
resolveGroupActivation,
|
|
resolveGroupRequireMention,
|
|
resolveTelegramGroupConfig,
|
|
});
|
|
if (!context) {
|
|
return;
|
|
}
|
|
await dispatchTelegramMessage({
|
|
context,
|
|
bot,
|
|
cfg,
|
|
runtime,
|
|
replyToMode,
|
|
streamMode,
|
|
textLimit,
|
|
telegramCfg,
|
|
opts,
|
|
});
|
|
};
|
|
};
|