前言¶
在 DeepSeek Harness(DSH)裏接 Telegram 或微信,常見做法是各自寫一套 webhook、鑑權和消息解析,業務插件再分別訂閱不同事件。通道一多,去重、回覆路由和「誰可以說話」的邊界容易散落在各適配器裏。dsh-channel-gateway 把傳輸層收成一層:適配器把各平臺流量規範成同一條入站契約,網關在傳輸邊界做授權並統一拋出 channel/inbound,消費方用入站消息攜帶的 route 經 ctx.channels.send 回話。下面按資料說明它是什麼、怎麼裝、怎麼用,以及啓用時要注意的點。
這是什麼¶
dsh-channel-gateway 是社區維護者 wowyuarm 發佈的 DSH 插件包,npm 名爲 @wowyuarm/dsh-channel-gateway(當前資料中的版本爲 0.1.3)。它在 SkillHub 目錄分類爲 admin-security;GitHub 獨立倉庫已歸檔,後續開發在 monorepo wowyuarm/dsh-plugins 的 packages/channel-gateway,已發佈的 npm 包路徑不變。
插件只負責聊天集成裏的「傳輸半層」:固定消息契約,以及 provider 與 consumer 之間的接縫。消息語義、是否已處理、下一步路由由上層決定。
消息契約與網關 API¶
公開 API 刻意保持小而穩定,共五類表面(字段細節見倉庫 docs/architecture.md):
| 表面 | 形態 |
|---|---|
| 入站 | InboundMessage:channel、providerMessageId、actor、place、visibility、text、可選 attachments、timestamp、可選 replyTo/raw |
| 出站 | OutboundMessage:channel、route、text、可選 attachments/replyTo/format |
| 傳輸 | Channel:name、capabilities、start(inbox)、stop()、send(message)、可選 resolveAttachment |
| 網關 | ctx.channels.register(channel)、ctx.channels.send(message)、ctx.channels.resolveAttachment、事件 channel/inbound |
| 授權 | ChannelAuth { authorize(request) },默認 allowlist |
契約裏有三塊是 consumer 需要、而 provider 原生 payload 往往給不齊的:actor / place / visibility(誰、在哪、對誰可見)、providerMessageId(去重與持久化接受)、以及 place.route(通道 mint 的不透明目的地;回覆時原樣作爲 OutboundMessage.route,上層不必拼 provider 地址)。
核心功能¶
網關與授權¶
安裝 bundle 後會插入 gateway 服務行。入站消息經網關授權後,以單一類型事件 channel/inbound 通知訂閱者;出站統一走 ctx.channels.send。
誰可以說話由 gateway 行 的配置決定,而不是各 adapter 的 token 配置:
- id: channel-gateway
config:
allow:
- telegram:123456789 # 某通道上的單個 actor
- weixin:* # 某通道上全部 actor
# - '*' # 所有人
allow 爲空則誰也不準入。
通道適配器(可選行)¶
各平臺以獨立 DSH 行啓用,需各自憑證:
| 適配器 | 傳輸 | 入口包名 | 說明 |
|---|---|---|---|
| Telegram | Bot API 長輪詢 getUpdates |
@wowyuarm/dsh-channel-gateway/telegram |
文本與媒體;附件可本地 data 或 provider ref/url;resolveAttachment 可下載入站附件字節;format: 'markdown' 按 Telegram HTML 渲染;config.token 缺省時可讀環境變量 DSH_TELEGRAM_TOKEN |
| 微信 | iLink 長輪詢 ilink/bot/getupdates |
@wowyuarm/dsh-channel-gateway/weixin |
文本與媒體;回覆需引用入站 context_token(微信約兩分鐘後過期,適配器會在過期前刷新);format: 'markdown' 爲消毒後的微信 Markdown;媒體上下行按參考 iLink 協議實現,資料註明尚未在真實賬號上完整驗證;QR 登錄未實現,需已有 token |
兩個適配器支持 HTTPS_PROXY / NO_PROXY(Node 自帶 fetch 默認不讀代理,除非設置 NODE_USE_ENV_PROXY)。
安裝與啓用¶
官方安裝命令(來自 README):
dsh plugin add @wowyuarm/dsh-channel-gateway --profile <profile>
在 profile 裏按需插入 adapter 行,例如:
- insert:
- id: channel-telegram
name: '@wowyuarm/dsh-channel-gateway/telegram'
config: { token: '<bot token>' }
- id: channel-weixin
name: '@wowyuarm/dsh-channel-gateway/weixin'
config: { token: '<iLink bot token>' }
運行環境要求 Node >=22。與 DSH 的耦合僅通過 peer 依賴 @deepseek-ai/cordis(^4.0.1)與 @deepseek-ai/schemastery(^3.18.1);資料中在 DSH 0.1.5-rc.3(latest)與 0.1.7-rc.x(next)上做過 typecheck、測試與構建驗證。
典型用法:訂閱入站並回復¶
消費方插件聲明 inject: ['channels'],監聽 channel/inbound,按 (channel, providerMessageId) 去重並持久化接受後,用入站 place.route 回消息:
import type { Context } from '@deepseek-ai/cordis'
import type {} from '@wowyuarm/dsh-channel-gateway'
export const name = 'my-ingress'
export const inject = ['channels']
export function apply(ctx: Context) {
ctx.on('channel/inbound', (message) => {
// Deduplicate on (message.channel, message.providerMessageId), accept it
// durably, route it.
void handle(message)
})
}
async function handle(message: InboundMessage) {
// ... later, answer it:
await ctx.channels.send({ channel: message.channel, route: message.place.route, text: 'ok' })
}
適用場景與注意¶
適合需要在 DSH 內統一接 Telegram Bot 與微信 iLink、且希望授權與入站事件在一處收口的多通道機器人或 ingress 插件。若你只做單一平臺且不需要共享契約,可直接用各平臺 SDK;若需要網關 allowlist 與 route 抽象,這一包更對口。
啓用前請自行閱讀源碼與 MIT 許可證;插件與 DSH 進程同權限運行,token 與 allow 配置相當於把誰能觸發你的 agent 寫在 profile 裏。微信適配器在資料中明確標註媒體路徑與 live 賬號驗證仍有限制;獨立倉庫已只讀,issue 與 PR 應指向 monorepo。
DSH 生態是「一切皆插件」;SkillHub 等社區目錄與 DeepSeek / 幻方無官方從屬關係,本文僅基於公開 README 與 package 元數據。
鏈接¶
- 目錄頁:https://www.skillhub.cn/plugins/wowyuarm/dsh-channel-gateway
- GitHub(歸檔):https://github.com/wowyuarm/dsh-channel-gateway
- 後續開發:https://github.com/wowyuarm/dsh-plugins(
packages/channel-gateway)