mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-23 15:18:09 +00:00
Merged via squash.
Prepared head SHA: 7975bc06ac
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
// Telegram plugin module implements bot behavior.
|
|
import { getSessionEntry, listSessionEntries } from "openclaw/plugin-sdk/session-store-runtime";
|
|
import {
|
|
createTelegramBotCore,
|
|
getTelegramSequentialKey,
|
|
setTelegramBotRuntimeForTest,
|
|
} from "./bot-core.js";
|
|
import { defaultTelegramBotDeps, type TelegramBotDeps } from "./bot-deps.js";
|
|
import type { TelegramBotOptions } from "./bot.types.js";
|
|
|
|
export type { TelegramBotOptions } from "./bot.types.js";
|
|
|
|
export { getTelegramSequentialKey, setTelegramBotRuntimeForTest };
|
|
|
|
export function createTelegramBot(
|
|
opts: TelegramBotOptions,
|
|
): ReturnType<typeof createTelegramBotCore> {
|
|
return createTelegramBotCore({
|
|
...opts,
|
|
telegramDeps: withTelegramSessionAccessorDeps(opts.telegramDeps ?? defaultTelegramBotDeps),
|
|
});
|
|
}
|
|
|
|
function withTelegramSessionAccessorDeps(deps: TelegramBotDeps): TelegramBotDeps {
|
|
if (!deps.loadSessionStore) {
|
|
return {
|
|
...deps,
|
|
getSessionEntry: deps.getSessionEntry ?? getSessionEntry,
|
|
listSessionEntries: deps.listSessionEntries ?? listSessionEntries,
|
|
};
|
|
}
|
|
|
|
const listInjectedEntries = (
|
|
scope: Parameters<NonNullable<TelegramBotDeps["listSessionEntries"]>>[0] = {},
|
|
) => {
|
|
const storePath =
|
|
scope.storePath ?? deps.resolveStorePath(undefined, { agentId: scope.agentId });
|
|
return Object.entries(deps.loadSessionStore?.(storePath) ?? {}).map(([sessionKey, entry]) => ({
|
|
sessionKey,
|
|
entry,
|
|
}));
|
|
};
|
|
|
|
return {
|
|
...deps,
|
|
// Existing Telegram tests and custom deps inject loadSessionStore; expose
|
|
// the same data through the accessor seam consumed by migrated handlers.
|
|
getSessionEntry:
|
|
deps.getSessionEntry ??
|
|
((scope) =>
|
|
listInjectedEntries(scope).find(({ sessionKey }) => sessionKey === scope.sessionKey)
|
|
?.entry),
|
|
listSessionEntries: deps.listSessionEntries ?? listInjectedEntries,
|
|
};
|
|
}
|