mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-10 19:30:46 +08:00
Add Telegram and Discord IM channels
This commit is contained in:
parent
7123fce47a
commit
cb74e1c4c7
66 changed files with 8579 additions and 1910 deletions
30
plugin-src/host/channels/telegram/index.mjs
Normal file
30
plugin-src/host/channels/telegram/index.mjs
Normal 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';
|
||||
17
plugin-src/host/channels/telegram/production.mjs
Normal file
17
plugin-src/host/channels/telegram/production.mjs
Normal 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,
|
||||
});
|
||||
}
|
||||
21
plugin-src/host/channels/telegram/rpc.mjs
Normal file
21
plugin-src/host/channels/telegram/rpc.mjs
Normal 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,
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue