Add Telegram and Discord IM channels

This commit is contained in:
xmanrui 2026-08-16 14:47:16 +08:00
parent 7123fce47a
commit cb74e1c4c7
66 changed files with 8579 additions and 1910 deletions

View file

@ -0,0 +1,30 @@
import { createProductionController } from './production.mjs';
import { installTelegramRpc } from './rpc.mjs';
export const name = 'dsh-im-telegram-host';
export const inject = ['connection', 'credentials', 'webServer'];
export async function apply(ctx, config = {}) {
if (config?.controller) {
return installTelegramRpc(ctx, config.controller, config.rpcAuthority);
}
const production = await createProductionController(ctx, config, config.internals ?? {});
const disposeRpc = installTelegramRpc(ctx, production.controller, config.rpcAuthority);
ctx.effect(() => async () => production.close(), 'dsh-im: close Telegram bot connections');
return disposeRpc;
}
export function createTelegramHostPlugin(config) {
return Object.freeze({ name, inject, apply: (ctx) => apply(ctx, config) });
}
export { createProductionController } from './production.mjs';
export {
TELEGRAM_ENDPOINTS,
TELEGRAM_RPC_CHANNEL,
TELEGRAM_RPC_ENDPOINTS,
createTelegramRpcHandler,
installTelegramRpc,
} from './rpc.mjs';
export { TelegramController } from '../../../../src/channels/telegram/telegram-controller.mjs';
export { TelegramRuntime } from '../../../../src/channels/telegram/telegram-runtime.mjs';

View file

@ -0,0 +1,17 @@
import { TelegramConfigStore } from '../../../../src/channels/telegram/config-store.mjs';
import { TelegramHarnessClient } from '../../../../src/channels/telegram/harness-client.mjs';
import { TelegramController } from '../../../../src/channels/telegram/telegram-controller.mjs';
import { TelegramRuntime } from '../../../../src/channels/telegram/telegram-runtime.mjs';
import { TelegramStateStore } from '../../../../src/channels/telegram/state-store.mjs';
import { createTokenProductionController } from '../shared/production.mjs';
export function createProductionController(ctx, config = {}, internals = {}) {
return createTokenProductionController(ctx, config, internals, {
channel: 'telegram',
ConfigStore: TelegramConfigStore,
StateStore: TelegramStateStore,
HarnessClient: TelegramHarnessClient,
Controller: TelegramController,
Runtime: TelegramRuntime,
});
}

View file

@ -0,0 +1,21 @@
import {
TOKEN_BOT_ENDPOINTS,
createTokenBotRpcHandler,
installTokenBotRpc,
} from '../shared/rpc.mjs';
export const TELEGRAM_RPC_CHANNEL = '/telegram';
export const TELEGRAM_ENDPOINTS = TOKEN_BOT_ENDPOINTS;
export const TELEGRAM_RPC_ENDPOINTS = Object.freeze(Object.values(TELEGRAM_ENDPOINTS));
export function createTelegramRpcHandler(controller) {
return createTokenBotRpcHandler(controller, { channel: 'Telegram' });
}
export function installTelegramRpc(ctx, controller, authority) {
return installTokenBotRpc(ctx, controller, {
channel: 'Telegram',
rpcChannel: TELEGRAM_RPC_CHANNEL,
authority,
});
}