dsh-message-gateway 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +1 -1
- package/README.es.md +1 -1
- package/README.md +1 -1
- package/lib/index.js +27 -5
- package/lib/index.js.map +2 -2
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -21,7 +21,7 @@ A message-platform gateway plugin for the DSH Web GUI: a "Message platforms" ent
|
|
|
21
21
|
- **WeCom AI bot persistent bridge**: official SDK WebSocket long connection with exponential backoff reconnect; incoming text messages are injected into an isolated dedicated agent session that wakes the DSH driver; replies stream back as chunks and finalize via `response_url`
|
|
22
22
|
- **Group-chat @mention stripping**: the leading `@bot-name` is removed before the assistant sees the message
|
|
23
23
|
- **Slash commands**: `/help` / `/time` / `/status` (Chinese aliases: 帮助/菜单/时间/状态)
|
|
24
|
-
- **Enter-chat welcome**:
|
|
24
|
+
- **Enter-chat welcome**: optional configuration (`welcomeReply`, defaults to `false` for zero disturbance; when set to `true`, auto-replies a greeting when a user enters single chat for the first time that day)
|
|
25
25
|
- **Proactive send channel**: `POST /gateway/send` (`{"chatid": "...", "content": "..."}`, single chat = userid, group chat = group id) sends markdown messages as the bot
|
|
26
26
|
- **Universal proactive push**: `POST /gateway/push` (`{"platform": "...", "target": "...", "content": "...", "title": "optional"}`) pushes text to any platform target for task notifications / other plugins:
|
|
27
27
|
- `platform` supports `telegram` (target = numeric chatId), `discord` (target = channelId), `wecom-aibot` (target = userid/group id), `email` (target = address, title becomes the subject)
|
package/README.es.md
CHANGED
|
@@ -21,7 +21,7 @@ Un plugin de pasarela de mensajería para la GUI web de DSH: una entrada "Plataf
|
|
|
21
21
|
- **Puente persistente del Bot de IA de WeCom**: conexión larga WebSocket del SDK oficial con reconexión por retroceso exponencial; los mensajes de texto entrantes se inyectan en una sesión de agente dedicada y aislada que despierta al controlador de DSH; las respuestas se transmiten como fragmentos y finalizan vía `response_url`
|
|
22
22
|
- **Eliminación de menciones @ en grupos**: se quita el `@nombre-del-bot` inicial antes de que el asistente vea el mensaje
|
|
23
23
|
- **Comandos de barra**: `/help` / `/time` / `/status` (alias en chino: 帮助/菜单/时间/状态)
|
|
24
|
-
- **Mensaje de bienvenida**:
|
|
24
|
+
- **Mensaje de bienvenida**: configuración opcional (`welcomeReply`, por defecto `false` para cero interrupciones; al activarse en `true`, responde un saludo cuando un usuario entra al chat individual por primera vez ese día)
|
|
25
25
|
- **Canal de envío proactivo**: `POST /gateway/send` (`{"chatid": "...", "content": "..."}`, chat individual = userid, grupo = id de grupo) envía mensajes markdown como el bot
|
|
26
26
|
- **Push proactivo universal**: `POST /gateway/push` (`{"platform": "...", "target": "...", "content": "...", "title": "opcional"}`) envía texto a cualquier plataforma para notificaciones de tareas / otros plugins:
|
|
27
27
|
- `platform` admite `telegram` (target = chatId numérico), `discord` (target = channelId), `wecom-aibot` (target = userid/id de grupo), `email` (target = correo, title como asunto)
|
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ DSH Web GUI 的消息平台网关插件:在侧边栏「新会话」按钮下
|
|
|
21
21
|
- **企业微信智能机器人常驻桥**:官方 SDK WebSocket 长连接,断线自动指数退避重连;收到文本消息 → 注入隔离的专用 agent 会话唤醒 DSH 驱动 → 回复按 chunk 流式回发,结束时经 response_url 定稿
|
|
22
22
|
- **群聊 @提及剥离**:去掉开头的 @机器人名后交给助手
|
|
23
23
|
- **斜杠命令**:`/help` / `/time` / `/status`(含中文别名:帮助/菜单/时间/状态)
|
|
24
|
-
-
|
|
24
|
+
- **进入会话欢迎语**:可选配置(配置项 `welcomeReply`,默认 `false` 保持免打扰,开启后用户当天首次进入单聊自动回复欢迎词)
|
|
25
25
|
- **主动发送通道**:`POST /gateway/send`(`{"chatid": "...", "content": "..."}`,单聊=userid,群聊=群 ID)以机器人身份主动发送 markdown 消息
|
|
26
26
|
- **通用主动推送**:`POST /gateway/push`(`{"platform": "...", "target": "...", "content": "...", "title": "可选"}`)向任意平台目标推送文本,供定时任务通知 / 其他插件调用:
|
|
27
27
|
- `platform` 支持:`telegram`(target=chatId 数字)、`discord`(target=channelId)、`wecom-aibot`(target=userid/群ID)、`email`(target=收件地址,title 作邮件主题)
|
package/lib/index.js
CHANGED
|
@@ -4635,6 +4635,7 @@ var BridgeManager = class {
|
|
|
4635
4635
|
awaiting = null;
|
|
4636
4636
|
/** 各聊天的独立 agent 会话(key = 平台:chatKey;webhook 固定 'webhook')。 */
|
|
4637
4637
|
agents = /* @__PURE__ */ new Map();
|
|
4638
|
+
disposed = false;
|
|
4638
4639
|
/** 当前语言的文案。 */
|
|
4639
4640
|
t(key) {
|
|
4640
4641
|
return botText(this.config.botLocale, key);
|
|
@@ -4812,14 +4813,32 @@ var BridgeManager = class {
|
|
|
4812
4813
|
console.log("[dsh-message-gateway] chat session reset", { key });
|
|
4813
4814
|
return true;
|
|
4814
4815
|
}
|
|
4815
|
-
/**
|
|
4816
|
+
/** 插件卸载时释放全部聊天会话与长连接(带超时脱钩保护,防死锁)。 */
|
|
4816
4817
|
async dispose() {
|
|
4818
|
+
if (this.disposed) return;
|
|
4819
|
+
this.disposed = true;
|
|
4820
|
+
this.wecom?.stop();
|
|
4821
|
+
this.wecom = null;
|
|
4822
|
+
this.telegram?.stop();
|
|
4823
|
+
this.telegram = null;
|
|
4824
|
+
this.discord?.stop();
|
|
4825
|
+
this.discord = null;
|
|
4826
|
+
this.qq?.stop();
|
|
4827
|
+
this.qq = null;
|
|
4828
|
+
this.email?.stop();
|
|
4829
|
+
this.email = null;
|
|
4817
4830
|
this.finishAllPending();
|
|
4818
4831
|
const entries = [...this.agents.values()];
|
|
4819
4832
|
this.agents.clear();
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4833
|
+
const disposePromises = entries.map(
|
|
4834
|
+
(entry) => entry.dispose().catch((error) => {
|
|
4835
|
+
console.warn("[dsh-message-gateway] agent dispose warning", String(error));
|
|
4836
|
+
})
|
|
4837
|
+
);
|
|
4838
|
+
await Promise.race([
|
|
4839
|
+
Promise.allSettled(disposePromises),
|
|
4840
|
+
new Promise((resolve) => setTimeout(resolve, 1500))
|
|
4841
|
+
]);
|
|
4823
4842
|
}
|
|
4824
4843
|
finishAllPending() {
|
|
4825
4844
|
for (const key of [...this.pendingMap.keys()]) this.finishPending(key);
|
|
@@ -4829,6 +4848,7 @@ var BridgeManager = class {
|
|
|
4829
4848
|
* 回复经 sink 流式回发。所有已打通的平台共用此管线。
|
|
4830
4849
|
*/
|
|
4831
4850
|
async handleExternalMessage(id, rawText) {
|
|
4851
|
+
if (this.disposed) return;
|
|
4832
4852
|
const text = stripMention(rawText);
|
|
4833
4853
|
const reply = (content) => {
|
|
4834
4854
|
id.sink.stream(id.frame, `cmd-${Date.now().toString(36)}`, content, true);
|
|
@@ -4973,8 +4993,9 @@ var BridgeManager = class {
|
|
|
4973
4993
|
void this.handleExternalMessage({ key, frame, sink, chatType: chattype === "group" ? "group" : "single" }, rawText);
|
|
4974
4994
|
},
|
|
4975
4995
|
onEnter: (frame) => {
|
|
4996
|
+
if (!this.config.welcomeReply) return;
|
|
4976
4997
|
const userid = frame.body?.from?.userid ?? "";
|
|
4977
|
-
console.log("[dsh-message-gateway] enter chat", { userid });
|
|
4998
|
+
console.log("[dsh-message-gateway] enter chat welcome", { userid });
|
|
4978
4999
|
void this.wecom?.welcome(frame, this.t("welcome"));
|
|
4979
5000
|
}
|
|
4980
5001
|
});
|
|
@@ -6222,6 +6243,7 @@ var Config = Schema.object({
|
|
|
6222
6243
|
autoStartQQ: Schema.boolean().default(true).description("\u542F\u52A8\u65F6\u81EA\u52A8\u7528\u5DF2\u4FDD\u5B58\u7684 QQ \u51ED\u636E\u5EFA\u7ACB\u5E38\u9A7B\u8FDE\u63A5"),
|
|
6223
6244
|
autoStartEmail: Schema.boolean().default(true).description("\u542F\u52A8\u65F6\u81EA\u52A8\u7528\u5DF2\u4FDD\u5B58\u7684 Email \u51ED\u636E\u5EFA\u7ACB\u5E38\u9A7B\u8FDE\u63A5\uFF08IMAP \u8F6E\u8BE2\uFF09"),
|
|
6224
6245
|
groupReply: Schema.boolean().default(true).description("\u662F\u5426\u56DE\u590D\u7FA4\u804A\u6D88\u606F\uFF08false \u65F6\u53EA\u5904\u7406\u5355\u804A\uFF09"),
|
|
6246
|
+
welcomeReply: Schema.boolean().default(false).description("\u662F\u5426\u5728\u7528\u6237\u5F53\u5929\u9996\u6B21\u8FDB\u5165\u5355\u804A\u65F6\u81EA\u52A8\u53D1\u9001\u6B22\u8FCE\u8BED\uFF08\u9ED8\u8BA4 false \u4FDD\u6301\u514D\u6253\u6270\uFF0C\u8BBE\u4E3A true \u5F00\u542F\uFF09"),
|
|
6225
6247
|
routes: Schema.array(Schema.object({
|
|
6226
6248
|
id: Schema.string().required().description("\u89C4\u5219 id\uFF08\u552F\u4E00\u6807\u8BC6\uFF09"),
|
|
6227
6249
|
matchPlatform: Schema.string().description("\u5339\u914D\u5E73\u53F0 id\uFF08telegram/discord/qq/wecom-aibot/email/webhook \u7B49\uFF09\uFF1B\u7F3A\u7701=\u5168\u90E8\u5E73\u53F0"),
|