Files
dsh-telegram-channel/lib/index.js
T
dsh-agent 4039dec03c feat(config): 渲染默认 rich(用户要求 2026-09-14)
Config.rendering 默认 'html'→'rich';显式 'html'/'compat' 仍可强制兼容模式。
profile cordis.patch.yml 的 rendering 同步改为 rich(patch 会覆盖插件默认值,
两处都改才生效)。旧客户端显示'不支持'时用 /rich off 按聊天切回。
2026-09-16 10:42:45 +08:00

53 lines
2.0 KiB
JavaScript

import Schema from '@deepseek-ai/schemastery';
import { TelegramBridge } from './bridge.js';
export const name = 'dsh-telegram-channel';
/** agents: followup; apiProxy: workspace/session catalog + /model; userQuestions: TG answer hook (Cordis requires inject). */
export const inject = ['agents', 'apiProxy', 'userQuestions'];
export const Config = Schema.object({
token: Schema.string().default(''),
allowedUserIds: Schema.array(Schema.number()).default([]),
allowAllUsers: Schema.boolean().default(false),
maxMessageLength: Schema.number().default(4096),
pollingTimeoutSec: Schema.number().default(30),
rendering: Schema.string().default('rich'),
});
function resolveAllowedUserIds(config) {
if (config.allowedUserIds && config.allowedUserIds.length > 0) {
return config.allowedUserIds;
}
const raw = process.env.DSH_TELEGRAM_ALLOWED_USER_IDS ?? '';
return raw
.split(/[,;\s]+/)
.map((part) => part.trim())
.filter(Boolean)
.map((part) => Number(part))
.filter((n) => Number.isFinite(n) && n > 0);
}
export function apply(ctx, config) {
const token = (config.token && config.token.length > 0)
? config.token
: (process.env.DSH_TELEGRAM_TOKEN ?? '');
if (!token) {
ctx.logger.error('dsh-telegram-channel: missing bot token (set config.token or DSH_TELEGRAM_TOKEN); polling not started');
return;
}
const bridge = new TelegramBridge(ctx, {
token,
allowedUserIds: resolveAllowedUserIds(config),
allowAllUsers: config.allowAllUsers ?? false,
maxMessageLength: config.maxMessageLength ?? 4096,
pollingTimeoutSec: config.pollingTimeoutSec ?? 30,
rendering: config.rendering === 'rich' ? 'rich' : 'html',
});
ctx.effect(() => {
bridge.start();
return () => { void bridge.stop(); };
}, 'dsh-telegram-channel.serve');
}
export * from './format.js';
export * from './client.js';
export * from './auth.js';
export * from './commands.js';
export * from './label.js';
export * from './bridge.js';