2026-03-16 02:20:09 -07:00
|
|
|
import { collectTelegramUnmentionedGroupIds } from "../../../extensions/telegram/src/audit.js";
|
2026-03-16 01:05:18 -07:00
|
|
|
import { telegramMessageActions } from "../../../extensions/telegram/src/channel-actions.js";
|
2026-03-16 00:40:32 -07:00
|
|
|
import {
|
|
|
|
|
setTelegramThreadBindingIdleTimeoutBySessionKey,
|
|
|
|
|
setTelegramThreadBindingMaxAgeBySessionKey,
|
|
|
|
|
} from "../../../extensions/telegram/src/thread-bindings.js";
|
2026-03-16 00:24:40 -07:00
|
|
|
import { resolveTelegramToken } from "../../../extensions/telegram/src/token.js";
|
|
|
|
|
import { createTelegramTypingLease } from "./runtime-telegram-typing.js";
|
|
|
|
|
import type { PluginRuntimeChannel } from "./types-channel.js";
|
|
|
|
|
|
2026-03-17 00:00:05 -07:00
|
|
|
type RuntimeTelegramOps = typeof import("./runtime-telegram-ops.runtime.js").runtimeTelegramOps;
|
|
|
|
|
|
|
|
|
|
let runtimeTelegramOpsPromise: Promise<RuntimeTelegramOps> | null = null;
|
2026-03-16 02:20:09 -07:00
|
|
|
|
|
|
|
|
function loadRuntimeTelegramOps() {
|
2026-03-17 00:00:05 -07:00
|
|
|
runtimeTelegramOpsPromise ??= import("./runtime-telegram-ops.runtime.js").then(
|
|
|
|
|
({ runtimeTelegramOps }) => runtimeTelegramOps,
|
|
|
|
|
);
|
2026-03-16 02:20:09 -07:00
|
|
|
return runtimeTelegramOpsPromise;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auditGroupMembershipLazy: PluginRuntimeChannel["telegram"]["auditGroupMembership"] = async (
|
|
|
|
|
...args
|
|
|
|
|
) => {
|
2026-03-17 00:00:05 -07:00
|
|
|
const runtimeTelegramOps = await loadRuntimeTelegramOps();
|
|
|
|
|
return runtimeTelegramOps.auditGroupMembership(...args);
|
2026-03-16 02:20:09 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const probeTelegramLazy: PluginRuntimeChannel["telegram"]["probeTelegram"] = async (...args) => {
|
2026-03-17 00:00:05 -07:00
|
|
|
const runtimeTelegramOps = await loadRuntimeTelegramOps();
|
|
|
|
|
return runtimeTelegramOps.probeTelegram(...args);
|
2026-03-16 02:20:09 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const sendMessageTelegramLazy: PluginRuntimeChannel["telegram"]["sendMessageTelegram"] = async (
|
|
|
|
|
...args
|
|
|
|
|
) => {
|
2026-03-17 00:00:05 -07:00
|
|
|
const runtimeTelegramOps = await loadRuntimeTelegramOps();
|
|
|
|
|
return runtimeTelegramOps.sendMessageTelegram(...args);
|
2026-03-16 02:20:09 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const sendPollTelegramLazy: PluginRuntimeChannel["telegram"]["sendPollTelegram"] = async (
|
|
|
|
|
...args
|
|
|
|
|
) => {
|
2026-03-17 00:00:05 -07:00
|
|
|
const runtimeTelegramOps = await loadRuntimeTelegramOps();
|
|
|
|
|
return runtimeTelegramOps.sendPollTelegram(...args);
|
2026-03-16 02:20:09 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const monitorTelegramProviderLazy: PluginRuntimeChannel["telegram"]["monitorTelegramProvider"] =
|
|
|
|
|
async (...args) => {
|
2026-03-17 00:00:05 -07:00
|
|
|
const runtimeTelegramOps = await loadRuntimeTelegramOps();
|
|
|
|
|
return runtimeTelegramOps.monitorTelegramProvider(...args);
|
2026-03-16 02:20:09 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const sendTypingTelegramLazy: PluginRuntimeChannel["telegram"]["typing"]["pulse"] = async (
|
|
|
|
|
...args
|
|
|
|
|
) => {
|
2026-03-17 00:00:05 -07:00
|
|
|
const runtimeTelegramOps = await loadRuntimeTelegramOps();
|
|
|
|
|
return runtimeTelegramOps.typing.pulse(...args);
|
2026-03-16 02:20:09 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const editMessageTelegramLazy: PluginRuntimeChannel["telegram"]["conversationActions"]["editMessage"] =
|
|
|
|
|
async (...args) => {
|
2026-03-17 00:00:05 -07:00
|
|
|
const runtimeTelegramOps = await loadRuntimeTelegramOps();
|
|
|
|
|
return runtimeTelegramOps.conversationActions.editMessage(...args);
|
2026-03-16 02:20:09 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const editMessageReplyMarkupTelegramLazy: PluginRuntimeChannel["telegram"]["conversationActions"]["editReplyMarkup"] =
|
|
|
|
|
async (...args) => {
|
2026-03-17 00:00:05 -07:00
|
|
|
const runtimeTelegramOps = await loadRuntimeTelegramOps();
|
|
|
|
|
return runtimeTelegramOps.conversationActions.editReplyMarkup(...args);
|
2026-03-16 02:20:09 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const deleteMessageTelegramLazy: PluginRuntimeChannel["telegram"]["conversationActions"]["deleteMessage"] =
|
|
|
|
|
async (...args) => {
|
2026-03-17 00:00:05 -07:00
|
|
|
const runtimeTelegramOps = await loadRuntimeTelegramOps();
|
|
|
|
|
return runtimeTelegramOps.conversationActions.deleteMessage(...args);
|
2026-03-16 02:20:09 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const renameForumTopicTelegramLazy: PluginRuntimeChannel["telegram"]["conversationActions"]["renameTopic"] =
|
|
|
|
|
async (...args) => {
|
2026-03-17 00:00:05 -07:00
|
|
|
const runtimeTelegramOps = await loadRuntimeTelegramOps();
|
|
|
|
|
return runtimeTelegramOps.conversationActions.renameTopic(...args);
|
2026-03-16 02:20:09 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const pinMessageTelegramLazy: PluginRuntimeChannel["telegram"]["conversationActions"]["pinMessage"] =
|
|
|
|
|
async (...args) => {
|
2026-03-17 00:00:05 -07:00
|
|
|
const runtimeTelegramOps = await loadRuntimeTelegramOps();
|
|
|
|
|
return runtimeTelegramOps.conversationActions.pinMessage(...args);
|
2026-03-16 02:20:09 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const unpinMessageTelegramLazy: PluginRuntimeChannel["telegram"]["conversationActions"]["unpinMessage"] =
|
|
|
|
|
async (...args) => {
|
2026-03-17 00:00:05 -07:00
|
|
|
const runtimeTelegramOps = await loadRuntimeTelegramOps();
|
|
|
|
|
return runtimeTelegramOps.conversationActions.unpinMessage(...args);
|
2026-03-16 02:20:09 -07:00
|
|
|
};
|
|
|
|
|
|
2026-03-16 00:24:40 -07:00
|
|
|
export function createRuntimeTelegram(): PluginRuntimeChannel["telegram"] {
|
|
|
|
|
return {
|
2026-03-16 02:20:09 -07:00
|
|
|
auditGroupMembership: auditGroupMembershipLazy,
|
2026-03-16 00:24:40 -07:00
|
|
|
collectUnmentionedGroupIds: collectTelegramUnmentionedGroupIds,
|
2026-03-16 02:20:09 -07:00
|
|
|
probeTelegram: probeTelegramLazy,
|
2026-03-16 00:24:40 -07:00
|
|
|
resolveTelegramToken,
|
2026-03-16 02:20:09 -07:00
|
|
|
sendMessageTelegram: sendMessageTelegramLazy,
|
|
|
|
|
sendPollTelegram: sendPollTelegramLazy,
|
|
|
|
|
monitorTelegramProvider: monitorTelegramProviderLazy,
|
2026-03-16 00:24:40 -07:00
|
|
|
messageActions: telegramMessageActions,
|
2026-03-16 00:40:32 -07:00
|
|
|
threadBindings: {
|
|
|
|
|
setIdleTimeoutBySessionKey: setTelegramThreadBindingIdleTimeoutBySessionKey,
|
|
|
|
|
setMaxAgeBySessionKey: setTelegramThreadBindingMaxAgeBySessionKey,
|
|
|
|
|
},
|
2026-03-16 00:24:40 -07:00
|
|
|
typing: {
|
2026-03-16 02:20:09 -07:00
|
|
|
pulse: sendTypingTelegramLazy,
|
2026-03-16 00:24:40 -07:00
|
|
|
start: async ({ to, accountId, cfg, intervalMs, messageThreadId }) =>
|
|
|
|
|
await createTelegramTypingLease({
|
|
|
|
|
to,
|
|
|
|
|
accountId,
|
|
|
|
|
cfg,
|
|
|
|
|
intervalMs,
|
|
|
|
|
messageThreadId,
|
|
|
|
|
pulse: async ({ to, accountId, cfg, messageThreadId }) =>
|
2026-03-16 02:20:09 -07:00
|
|
|
await sendTypingTelegramLazy(to, {
|
2026-03-16 00:24:40 -07:00
|
|
|
accountId,
|
|
|
|
|
cfg,
|
|
|
|
|
messageThreadId,
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
conversationActions: {
|
2026-03-16 02:20:09 -07:00
|
|
|
editMessage: editMessageTelegramLazy,
|
|
|
|
|
editReplyMarkup: editMessageReplyMarkupTelegramLazy,
|
2026-03-16 00:24:40 -07:00
|
|
|
clearReplyMarkup: async (chatIdInput, messageIdInput, opts = {}) =>
|
2026-03-16 02:20:09 -07:00
|
|
|
await editMessageReplyMarkupTelegramLazy(chatIdInput, messageIdInput, [], opts),
|
|
|
|
|
deleteMessage: deleteMessageTelegramLazy,
|
|
|
|
|
renameTopic: renameForumTopicTelegramLazy,
|
|
|
|
|
pinMessage: pinMessageTelegramLazy,
|
|
|
|
|
unpinMessage: unpinMessageTelegramLazy,
|
2026-03-16 00:24:40 -07:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|