import { collectTelegramUnmentionedGroupIds } from "../../../extensions/telegram/src/audit.js"; import { telegramMessageActions } from "../../../extensions/telegram/src/channel-actions.js"; import { setTelegramThreadBindingIdleTimeoutBySessionKey, setTelegramThreadBindingMaxAgeBySessionKey, } from "../../../extensions/telegram/src/thread-bindings.js"; import { resolveTelegramToken } from "../../../extensions/telegram/src/token.js"; import { createLazyRuntimeMethod, createLazyRuntimeSurface } from "../../shared/lazy-runtime.js"; import { createTelegramTypingLease } from "./runtime-telegram-typing.js"; import type { PluginRuntimeChannel } from "./types-channel.js"; type RuntimeTelegramOps = typeof import("./runtime-telegram-ops.runtime.js").runtimeTelegramOps; const loadRuntimeTelegramOps = createLazyRuntimeSurface( () => import("./runtime-telegram-ops.runtime.js"), ({ runtimeTelegramOps }) => runtimeTelegramOps, ); const auditGroupMembershipLazy = createLazyRuntimeMethod< RuntimeTelegramOps, Parameters, ReturnType >(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.auditGroupMembership); const probeTelegramLazy = createLazyRuntimeMethod< RuntimeTelegramOps, Parameters, ReturnType >(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.probeTelegram); const sendMessageTelegramLazy = createLazyRuntimeMethod< RuntimeTelegramOps, Parameters, ReturnType >(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.sendMessageTelegram); const sendPollTelegramLazy = createLazyRuntimeMethod< RuntimeTelegramOps, Parameters, ReturnType >(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.sendPollTelegram); const monitorTelegramProviderLazy = createLazyRuntimeMethod< RuntimeTelegramOps, Parameters, ReturnType >(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.monitorTelegramProvider); const sendTypingTelegramLazy = createLazyRuntimeMethod< RuntimeTelegramOps, Parameters, ReturnType >(loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.typing.pulse); const editMessageTelegramLazy = createLazyRuntimeMethod< RuntimeTelegramOps, Parameters, ReturnType >( loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.conversationActions.editMessage, ); const editMessageReplyMarkupTelegramLazy = createLazyRuntimeMethod< RuntimeTelegramOps, Parameters, ReturnType >( loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.conversationActions.editReplyMarkup, ); const deleteMessageTelegramLazy = createLazyRuntimeMethod< RuntimeTelegramOps, Parameters, ReturnType >( loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.conversationActions.deleteMessage, ); const renameForumTopicTelegramLazy = createLazyRuntimeMethod< RuntimeTelegramOps, Parameters, ReturnType >( loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.conversationActions.renameTopic, ); const pinMessageTelegramLazy = createLazyRuntimeMethod< RuntimeTelegramOps, Parameters, ReturnType >( loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.conversationActions.pinMessage, ); const unpinMessageTelegramLazy = createLazyRuntimeMethod< RuntimeTelegramOps, Parameters, ReturnType >( loadRuntimeTelegramOps, (runtimeTelegramOps) => runtimeTelegramOps.conversationActions.unpinMessage, ); export function createRuntimeTelegram(): PluginRuntimeChannel["telegram"] { return { auditGroupMembership: auditGroupMembershipLazy, collectUnmentionedGroupIds: collectTelegramUnmentionedGroupIds, probeTelegram: probeTelegramLazy, resolveTelegramToken, sendMessageTelegram: sendMessageTelegramLazy, sendPollTelegram: sendPollTelegramLazy, monitorTelegramProvider: monitorTelegramProviderLazy, messageActions: telegramMessageActions, threadBindings: { setIdleTimeoutBySessionKey: setTelegramThreadBindingIdleTimeoutBySessionKey, setMaxAgeBySessionKey: setTelegramThreadBindingMaxAgeBySessionKey, }, typing: { pulse: sendTypingTelegramLazy, start: async ({ to, accountId, cfg, intervalMs, messageThreadId }) => await createTelegramTypingLease({ to, accountId, cfg, intervalMs, messageThreadId, pulse: async ({ to, accountId, cfg, messageThreadId }) => await sendTypingTelegramLazy(to, { accountId, cfg, messageThreadId, }), }), }, conversationActions: { editMessage: editMessageTelegramLazy, editReplyMarkup: editMessageReplyMarkupTelegramLazy, clearReplyMarkup: async (chatIdInput, messageIdInput, opts = {}) => await editMessageReplyMarkupTelegramLazy(chatIdInput, messageIdInput, [], opts), deleteMessage: deleteMessageTelegramLazy, renameTopic: renameForumTopicTelegramLazy, pinMessage: pinMessageTelegramLazy, unpinMessage: unpinMessageTelegramLazy, }, }; }