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

@ -5,10 +5,17 @@ export const name = 'dsh-dingtalk-host';
export const inject = ['connection', 'credentials', 'webServer'];
export async function apply(ctx, config = {}) {
if (config?.controller) return installDingtalkRpc(ctx, config.controller, config.rpcOptions);
if (config?.controller) {
return installDingtalkRpc(ctx, config.controller, config.rpcOptions, config.rpcAuthority);
}
const production = await createProductionController(ctx, config, config.internals);
const disposeRpc = installDingtalkRpc(ctx, production.controller, config.rpcOptions);
const disposeRpc = installDingtalkRpc(
ctx,
production.controller,
config.rpcOptions,
config.rpcAuthority,
);
ctx.effect(() => async () => {
await production.close();
}, 'dsh-dingtalk: close bot connections');

View file

@ -1,4 +1,5 @@
import QRCode from 'qrcode';
import { resolveRpcAuthority } from '../../rpc-authority.mjs';
export const DINGTALK_RPC_CHANNEL = '/dingtalk';
export const DINGTALK_ENDPOINTS = Object.freeze({
@ -224,13 +225,13 @@ export function createDingtalkRpcHandler(controller, { encodeQr = qrDataUrl } =
};
}
export function installDingtalkRpc(ctx, controller, options) {
export function installDingtalkRpc(ctx, controller, options, authority) {
if (!ctx?.connection?.rpc || typeof ctx.connection.rpc.handle !== 'function') {
throw new TypeError('DSH Host Connection RPC is required');
}
return ctx.connection.rpc.handle(
DINGTALK_RPC_CHANNEL,
createDingtalkRpcHandler(controller, options),
{ authority: 'loopback' },
{ authority: resolveRpcAuthority(authority) },
);
}