dsh-message-gateway 0.1.16 → 0.1.17
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 +34 -25
- package/README.es.md +39 -30
- package/README.md +24 -13
- package/lib/index.js +279 -13
- package/lib/index.js.map +2 -2
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -2,41 +2,50 @@
|
|
|
2
2
|
|
|
3
3
|
[中文](README.md) · [Español](README.es.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
A message-platform gateway plugin for the DSH Web GUI: a "Message platforms" entry below the "New session" button opens a full-screen manager for multi-platform message connectors — credential save, connection tests, status monitoring — plus a built-in persistent bridge for the WeCom AI bot: external messages drive the DSH assistant through a dedicated agent session, and replies stream back token by token. Also provides a universal proactive messaging API supporting Markdown text and native image attachments.
|
|
6
8
|
|
|
7
9
|
## Features
|
|
8
10
|
|
|
9
11
|
- **Sidebar entry**: a "📮 Message platforms" button below "New session" opens the full-screen manager (close with ESC or by clicking the backdrop)
|
|
10
|
-
- **Multi-platform connectors**: Telegram / Discord / QQ bot / WeCom / WeCom AI bot / WeChat (external Wechaty gateway) / WeChat Official Account / WhatsApp / Email / Webhooks
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
15
|
-
- **
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
18
|
-
- **
|
|
19
|
-
- **
|
|
20
|
-
- **
|
|
21
|
-
- **
|
|
12
|
+
- **Multi-platform connectors**: Telegram / Discord / QQ bot / WeCom / WeCom AI bot / WeChat (external Wechaty gateway) / WeChat Official Account / WhatsApp / Email / DingTalk / Feishu / Bark / ServerChan / Webhooks
|
|
13
|
+
- **WeCom AI bot**: fill in `botId + secret` to establish an official SDK WebSocket connection; supports streaming replies, media upload, and **proactive image/file push**
|
|
14
|
+
- **Telegram bot**: save a Bot Token to enable long polling, supporting text streaming and `sendPhoto` **proactive image push**
|
|
15
|
+
- **Discord bot**: save a Bot Token to connect via Gateway, supporting channels/DMs and `files` attachment **proactive image push**
|
|
16
|
+
- **DingTalk Bot**: configure custom bot Webhook & optional HMAC Secret; supports Markdown text and public image URL rendering
|
|
17
|
+
- **Feishu / Lark Bot**: configure custom bot Webhook & optional Secret signature for text and card delivery
|
|
18
|
+
- **Bark (iOS)**: fill in Device Key for instant push notifications with rich image banners (public URL)
|
|
19
|
+
- **ServerChan**: fill in SendKey for push notifications to WeChat / mobile channels with Markdown image URLs
|
|
20
|
+
- **QQ bot**: save appId + secret to connect to the open-platform gateway; passive replies + streaming edits
|
|
21
|
+
- **WeCom app**: fill in CorpID/AgentID/Secret plus callback Token/EncodingAESKey for auto-dialogues
|
|
22
|
+
- **WeChat Official Account**: fill in AppID/Secret plus callback Token for follower dialogues
|
|
23
|
+
- **WhatsApp**: fill in Token + Phone Number ID for WhatsApp webhook dialogues
|
|
24
|
+
- **Email**: fill in IMAP (993/143) + SMTP (465/587/25) for threaded email conversations
|
|
25
|
+
- **Universal proactive push channel**: `POST /gateway/push` (for cron jobs, automation scripts, and pipelines):
|
|
26
|
+
- Request body:
|
|
27
|
+
- `platform`: target platform (`wecom-aibot` / `telegram` / `discord` / `dingtalk` / `feishu` / `bark` / `serverchan` / `email`)
|
|
28
|
+
- `target`: destination target (single-chat userid or group id for `wecom-aibot`; numeric chatId for `telegram`; channelId for `discord`; deviceKey for `bark`, etc.)
|
|
29
|
+
- `content`: optional text content (supports Markdown)
|
|
30
|
+
- `title`: optional title (email subject or notification prefix)
|
|
31
|
+
- `image`: optional image data (**Base64** data or accessible `http(s)://` image URL)
|
|
32
|
+
- `filename`: optional image filename (defaults to `image.png`)
|
|
33
|
+
- Highlights:
|
|
34
|
+
- Text and image can be pushed together or separately
|
|
35
|
+
- `wecom-aibot`, `telegram`, and `discord` support uploading raw local binary buffers directly
|
|
36
|
+
- `bark`, `dingtalk`, and `serverchan` automatically adapt to public image URLs
|
|
22
37
|
- **Credential management**: plaintext is persisted only to `~/.dsh/gateway.json` (mode 600, atomic write); `/gateway/list` never returns credential plaintext, only a `configured` flag
|
|
23
38
|
- **Secret redaction**: message content written to logs / console is automatically masked for likely secrets (`sk-` prefixed keys, GitHub tokens, `Bearer`, `password=` assignments, PEM private keys, and other common patterns), so secrets in bot conversations never leak into log files
|
|
24
39
|
- **Connection tests**: real per-platform checks — Telegram/Discord via Bot API, QQ via access_token, WeCom via gettoken, WeChat MP via cgi-bin/token, WhatsApp via Graph API, Email via IMAP TCP banner, WeCom AI bot via the official SDK long connection (authenticated = pass)
|
|
25
40
|
- **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`
|
|
26
41
|
- **Group-chat @mention stripping**: the leading `@bot-name` is removed before the assistant sees the message
|
|
27
|
-
- **Slash commands**: `/help` / `/time` / `/status` (Chinese aliases:
|
|
42
|
+
- **Slash commands**: `/help` / `/time` / `/status` / `/stats` (Chinese aliases: 帮助/菜单/时间/状态/统计)
|
|
28
43
|
- **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)
|
|
29
|
-
- **Proactive send channel**: `POST /gateway/send` (`{"chatid": "...", "content": "..."}
|
|
30
|
-
- **
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
- **Message routing rules** (plugin config `routes`): route messages by "platform + keyword prefix" to a specific **agent preset** (isolated session) with an optional **dedicated model / skill**. E.g. `{ id: "code", matchPlatform: "telegram", matchPrefix: "code ", agentPreset: "code" }` makes `code write a function` on Telegram enter a code-preset session. First matching rule wins; unmatched messages use the default agent
|
|
35
|
-
- **Slash commands**: `/help` / `/time` / `/status` / `/stats` (Chinese aliases: 帮助/菜单/时间/状态/统计); `/stats` shows per-bridge connection status and active chat count
|
|
36
|
-
- **Agent push tool** (`send_chat_message`): automatically registers a universal message-pushing tool for DSH agents, allowing AI assistants to proactively send summaries, task results, or alerts to Telegram, Discord, WeCom, or Email directly within conversations
|
|
37
|
-
- **Webhook receive endpoint**: `POST /gateway/webhook/in` accepts messages from external systems (any of `text` / `content` / `message`), injects them into the dedicated agent session and returns the full reply synchronously; an optional HMAC-SHA256 signing secret validates requests (contract: [docs/webhooks.md](docs/webhooks.md))
|
|
38
|
-
- **WeChat personal accounts (optional external gateway)**: QR login and status polling against a local Wechaty HTTP gateway (contract: [docs/wechaty-gateway.md](docs/wechaty-gateway.md))
|
|
39
|
-
- **Multilingual**: Chinese / English / Español, following the DSH Web UI language (Spanish browsers auto-switch); defaults to Simplified Chinese
|
|
44
|
+
- **Proactive send channel**: `POST /gateway/send` (`{"chatid": "...", "content": "..."}`) sends markdown messages as the bot
|
|
45
|
+
- **Message routing rules** (plugin config `routes`): route messages by "platform + keyword prefix" to a specific **agent preset** (isolated session) with an optional **dedicated model / skill**
|
|
46
|
+
- **Agent push tool** (`send_chat_message`): automatically registers a universal message-pushing tool for DSH agents, allowing AI assistants to proactively send summaries, task results, or alerts (including screenshots and text) to WeCom, Telegram, Discord, DingTalk, etc.
|
|
47
|
+
- **Webhook receive endpoint**: `POST /gateway/webhook/in` accepts messages from external systems, injects them into the dedicated agent session and returns the full reply synchronously; optional HMAC-SHA256 signature validation
|
|
48
|
+
- **Multilingual**: Chinese / English / Español, following the DSH Web UI language; defaults to Simplified Chinese
|
|
40
49
|
- Light / dark theme follows the DSH Web GUI
|
|
41
50
|
|
|
42
51
|
## Usage
|
package/README.es.md
CHANGED
|
@@ -2,41 +2,50 @@
|
|
|
2
2
|
|
|
3
3
|
[中文](README.md) · [English](README.en.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
Un plugin de pasarela de mensajería para la GUI web de DSH: una entrada "Plataformas de mensajería" debajo del botón "Nueva sesión" abre un gestor a pantalla completa para conectores de mensajería multiplataforma — guardado de credenciales, pruebas de conexión, monitoreo de estado — más un puente persistente integrado para el bot de IA de WeCom: los mensajes externos impulsan al asistente de DSH a través de una sesión de agente dedicada, y las respuestas se transmiten token a token. También proporciona una API universal de push proactivo que admite texto Markdown e imágenes nativas.
|
|
6
8
|
|
|
7
9
|
## Características
|
|
8
10
|
|
|
9
11
|
- **Entrada en la barra lateral**: un botón "📮 Plataformas de mensajería" debajo de "Nueva sesión" abre el gestor a pantalla completa (cierre con ESC o haciendo clic en el fondo)
|
|
10
|
-
- **Conectores multiplataforma**: Telegram / Discord / Bot de QQ / WeCom / Bot de IA de WeCom / WeChat (pasarela Wechaty externa) / Cuenta oficial de WeChat / WhatsApp / Email / Webhooks
|
|
11
|
-
- **Bot de
|
|
12
|
-
- **Bot de
|
|
13
|
-
- **Bot de
|
|
14
|
-
- **
|
|
15
|
-
- **
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
18
|
-
- **Bot de
|
|
19
|
-
- **
|
|
20
|
-
- **
|
|
21
|
-
- **
|
|
12
|
+
- **Conectores multiplataforma**: Telegram / Discord / Bot de QQ / WeCom / Bot de IA de WeCom / WeChat (pasarela Wechaty externa) / Cuenta oficial de WeChat / WhatsApp / Email / DingTalk / Feishu / Bark / ServerChan / Webhooks
|
|
13
|
+
- **Bot de IA de WeCom**: rellene `botId + secret` para conexión WebSocket persistente; admite respuestas en streaming, subida de medios y **envío proactivo de imágenes/archivos**
|
|
14
|
+
- **Bot de Telegram**: guarde un Bot Token para sondeo largo, admite streaming y `sendPhoto` para **envío proactivo de imágenes**
|
|
15
|
+
- **Bot de Discord**: guarde un Bot Token para conectar vía Gateway, admite canales/DMs y adjuntos `files` para **envío proactivo de imágenes**
|
|
16
|
+
- **Bot de DingTalk**: configure Webhook y Secret opcional; admite Markdown y URL de imagen pública
|
|
17
|
+
- **Bot de Feishu / Lark**: configure Webhook y Secret opcional para entrega de mensajes y tarjetas
|
|
18
|
+
- **Bark (iOS)**: ingrese la Device Key para notificaciones instantáneas con banners de imágenes ricas (URL pública)
|
|
19
|
+
- **ServerChan**: configure SendKey para notificaciones a WeChat con URLs de imágenes en Markdown
|
|
20
|
+
- **Bot de QQ**: guarde appId + secret para conectar a la plataforma abierta; respuestas pasivas + edición en streaming
|
|
21
|
+
- **App de WeCom**: rellene CorpID/AgentID/Secret más Token/EncodingAESKey de callback
|
|
22
|
+
- **Cuenta oficial de WeChat**: rellene AppID/Secret más Token de callback
|
|
23
|
+
- **WhatsApp**: rellene Token + Phone Number ID para webhooks de WhatsApp
|
|
24
|
+
- **Email**: rellene IMAP (993/143) + SMTP (465/587/25) para correos en hilos
|
|
25
|
+
- **Canal de push proactivo universal**: `POST /gateway/push` (para tareas programadas, scripts de automatización y pipelines):
|
|
26
|
+
- Cuerpo de la petición:
|
|
27
|
+
- `platform`: plataforma destino (`wecom-aibot` / `telegram` / `discord` / `dingtalk` / `feishu` / `bark` / `serverchan` / `email`)
|
|
28
|
+
- `target`: destino (userid o grupo para `wecom-aibot`; chatId numérico para `telegram`; channelId para `discord`; deviceKey para `bark`, etc.)
|
|
29
|
+
- `content`: texto opcional (admite Markdown)
|
|
30
|
+
- `title`: título opcional (asunto de correo o prefijo de notificación)
|
|
31
|
+
- `image`: imagen opcional (datos en **Base64** o URL accesible `http(s)://`)
|
|
32
|
+
- `filename`: nombre de archivo opcional (por defecto `image.png`)
|
|
33
|
+
- Destacados:
|
|
34
|
+
- El texto y la imagen se pueden enviar juntos o por separado
|
|
35
|
+
- `wecom-aibot`, `telegram` y `discord` admiten la carga directa de buffers binarios locales
|
|
36
|
+
- `bark`, `dingtalk` y `serverchan` se adaptan automáticamente al modo de URL pública
|
|
22
37
|
- **Gestión de credenciales**: el texto plano se guarda solo en `~/.dsh/gateway.json` (modo 600, escritura atómica); `/gateway/list` nunca devuelve credenciales, solo un marcador `configured`
|
|
23
|
-
- **Redacción de secretos**: el contenido de los mensajes escrito en registros / consola se enmascara automáticamente ante posibles secretos
|
|
24
|
-
- **Pruebas de conexión**: comprobaciones reales por plataforma — Telegram/Discord vía Bot API, QQ vía access_token, WeCom vía gettoken, cuenta oficial vía cgi-bin/token, WhatsApp vía Graph API, Email vía banner TCP de IMAP, Bot de IA de WeCom vía la conexión larga del SDK oficial
|
|
25
|
-
- **Puente persistente del Bot de IA de WeCom**: conexión larga WebSocket del SDK oficial con reconexión por retroceso exponencial
|
|
26
|
-
- **Eliminación de menciones @ en grupos
|
|
27
|
-
- **Comandos de barra**: `/help` / `/time` / `/status`
|
|
28
|
-
- **Mensaje de bienvenida
|
|
29
|
-
- **Canal de envío proactivo**: `POST /gateway/send`
|
|
30
|
-
- **
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
- **Reglas de enrutado de mensajes** (configuración del plugin `routes`): enruta mensajes por "plataforma + prefijo de palabra clave" a un **preset de agente** específico (sesión aislada) con un **modelo / skill** opcional. Ej.: `{ id: "code", matchPlatform: "telegram", matchPrefix: "code ", agentPreset: "code" }` hace que `code escribe una función` en Telegram entre en una sesión de preset code. Gana la primera regla que coincida; los mensajes sin coincidencia usan el agente por defecto
|
|
35
|
-
- **Comandos de barra**: `/help` / `/time` / `/status` / `/stats` (alias en chino: 帮助/菜单/时间/状态/统计); `/stats` muestra el estado de conexión de cada puente y el número de chats activos
|
|
36
|
-
- **Herramienta de push para agentes** (`send_chat_message`): registra automáticamente una herramienta de envío de mensajes para los agentes de DSH, permitiendo que el asistente envíe resúmenes, resultados o alertas a Telegram, Discord, WeCom o Email directamente desde la conversación
|
|
37
|
-
- **Endpoint de recepción de webhooks**: `POST /gateway/webhook/in` acepta mensajes de sistemas externos (cualquiera de `text` / `content` / `message`), los inyecta en la sesión de agente dedicada y devuelve la respuesta completa de forma síncrona; un secreto de firma HMAC-SHA256 opcional valida las peticiones (contrato: [docs/webhooks.md](docs/webhooks.md))
|
|
38
|
-
- **Cuentas personales de WeChat (pasarela externa opcional)**: inicio de sesión por QR y sondeo de estado contra una pasarela HTTP Wechaty local (contrato: [docs/wechaty-gateway.md](docs/wechaty-gateway.md))
|
|
39
|
-
- **Multilingüe**: chino / inglés / español, siguiendo el idioma de la interfaz web de DSH (los navegadores en español cambian automáticamente); por defecto chino simplificado
|
|
38
|
+
- **Redacción de secretos**: el contenido de los mensajes escrito en registros / consola se enmascara automáticamente ante posibles secretos
|
|
39
|
+
- **Pruebas de conexión**: comprobaciones reales por plataforma — Telegram/Discord vía Bot API, QQ vía access_token, WeCom vía gettoken, cuenta oficial vía cgi-bin/token, WhatsApp vía Graph API, Email vía banner TCP de IMAP, Bot de IA de WeCom vía la conexión larga del SDK oficial
|
|
40
|
+
- **Puente persistente del Bot de IA de WeCom**: conexión larga WebSocket del SDK oficial con reconexión por retroceso exponencial
|
|
41
|
+
- **Eliminación de menciones @ en grupos**
|
|
42
|
+
- **Comandos de barra**: `/help` / `/time` / `/status` / `/stats`
|
|
43
|
+
- **Mensaje de bienvenida opcional**
|
|
44
|
+
- **Canal de envío proactivo**: `POST /gateway/send`
|
|
45
|
+
- **Reglas de enrutado de mensajes** (`routes`)
|
|
46
|
+
- **Herramienta de push para agentes** (`send_chat_message`): registra automáticamente una herramienta para que los agentes envíen resúmenes, resultados o alertas (incluyendo imágenes y capturas de pantalla)
|
|
47
|
+
- **Endpoint de recepción de webhooks**: `POST /gateway/webhook/in`
|
|
48
|
+
- **Multilingüe**: chino / inglés / español, siguiendo el idioma de la interfaz web de DSH
|
|
40
49
|
- Tema claro / oscuro siguiendo la GUI web de DSH
|
|
41
50
|
|
|
42
51
|
## Uso
|
package/README.md
CHANGED
|
@@ -2,23 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
[English](README.en.md) · [Español](README.es.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
DSH Web GUI 的消息平台网关插件:在侧边栏「新会话」按钮下方提供「消息平台」入口,全屏管理多平台消息连接器——凭据保存、连接测试、状态监控,并内置企业微信智能机器人的常驻桥接:外部消息经专用 agent 会话驱动 DSH 助手,回复按 token 流式回发;同时提供全平台通用主动图文推送通道(支持发送 Markdown 文本与多模态原生图片)。
|
|
6
8
|
|
|
7
9
|
## 功能
|
|
8
10
|
|
|
9
11
|
- **侧边栏入口**:「新会话」按钮下方新增「📮 消息平台」按钮,点击打开全屏管理页(ESC / 点击遮罩关闭)
|
|
10
|
-
- **多平台连接器**:Telegram / Discord / QQ 机器人 / 企业微信 / 企业微信智能机器人 / 微信(外部 Wechaty 网关)/ 微信公众号 / WhatsApp / Email / Webhooks
|
|
11
|
-
-
|
|
12
|
-
- **
|
|
12
|
+
- **多平台连接器**:Telegram / Discord / QQ 机器人 / 企业微信 / 企业微信智能机器人 / 微信(外部 Wechaty 网关)/ 微信公众号 / WhatsApp / Email / 钉钉 / 飞书 / Bark / Server酱 / Webhooks
|
|
13
|
+
- **企业微信智能机器人**:填 `botId + secret` 保存即建立官方 SDK WebSocket 常驻连接;支持文本流式对话、素材上传与**主动图片/文件推送**
|
|
14
|
+
- **Telegram 机器人**:填 Bot Token 保存即启用长轮询,与机器人对话即可使用,支持 `sendPhoto` **主动图片推送**
|
|
15
|
+
- **Discord 机器人**:填 Bot Token 保存即接入网关,频道/私信直接对话,支持 `files` 附件**主动图片推送**
|
|
16
|
+
- **钉钉群机器人**:配置自定义机器人 Webhook 与可选加签密钥(Secret),支持 Markdown 消息推送与公网图片 URL 渲染
|
|
17
|
+
- **飞书群机器人**:配置自定义机器人 Webhook 与可选签名密钥(Secret),支持标准文本与卡片推送
|
|
18
|
+
- **Bark (iOS)**:填入 Device Key,实现手机秒级弹窗通知推送与富文本大图横幅(公网 URL)
|
|
19
|
+
- **Server酱 (Turbo版)**:填入 SendKey,支持将通知推送至微信 / 手机服务号,支持 Markdown 图片 URL
|
|
13
20
|
- **QQ 机器人**:填 appId + secret 保存即连接开放平台网关(频道/群/私信),被动回复 + 流式编辑
|
|
14
21
|
- **企业微信应用**:填 CorpID/AgentID/Secret + 回调 Token/EncodingAESKey,后台配置回调 URL(`/gateway/wecom/callback`)后发消息即自动对话
|
|
15
22
|
- **微信公众号**:填 AppID/Secret + 回调 Token,后台配置服务器 URL(`/gateway/wechat-mp/callback`)后发消息即自动对话
|
|
16
23
|
- **WhatsApp**:填 Token + Phone Number ID,Meta 后台配置 Webhook(`/gateway/whatsapp/webhook`)后发消息即自动对话
|
|
17
24
|
- **Email**:填 IMAP(收件,993/143)+ SMTP(回复,465/587/25),按邮件线程自动归类会话,回复用 Re: 原主题
|
|
18
|
-
|
|
19
|
-
-
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
- **通用主动推送通道**:`POST /gateway/push`(供定时任务、自动化脚本、外部流水线等调用):
|
|
26
|
+
- 请求参数:
|
|
27
|
+
- `platform`:目标平台(`wecom-aibot` / `telegram` / `discord` / `dingtalk` / `feishu` / `bark` / `serverchan` / `email`)
|
|
28
|
+
- `target`:目标会话(`wecom-aibot` 为单聊 userid 或群 ID;`telegram` 为 chatId 数字;`discord` 为 channelId;`bark` 为 deviceKey 等)
|
|
29
|
+
- `content`:可选文本内容(支持 Markdown)
|
|
30
|
+
- `title`:可选标题(Email 作为主题,其他平台作为前缀)
|
|
31
|
+
- `image`:可选图片数据(支持 **Base64** 编码数据,或公网可访问的 `http(s)://` 图片 URL)
|
|
32
|
+
- `filename`:可选图片文件名(默认 `image.png`)
|
|
33
|
+
- 特性:
|
|
34
|
+
- 文字与图片可同时发送,亦可单独发送纯文字或纯图片
|
|
35
|
+
- `wecom-aibot`、`telegram`、`discord` 支持本地二进制图片直接上传与原生下发
|
|
36
|
+
- `bark`、`dingtalk`、`serverchan` 自动适配公网图片 URL 模式
|
|
22
37
|
- **凭据管理**:明文只落盘 `~/.dsh/gateway.json`(权限 600,原子写入),`/gateway/list` 永不回传凭据明文,只返回 configured 标记
|
|
23
38
|
- **敏感信息脱敏**:写入日志 / 控制台的消息内容自动遮蔽疑似密钥(`sk-` 前缀、GitHub token、`Bearer`、`password=` 赋值、私钥 PEM 等通用模式),机器人对话里的机密不会泄露到日志文件
|
|
24
39
|
- **连接测试**:每个平台独立的真实连接测试——Telegram/Discord 走 Bot API、QQ 走 access_token、企微走 gettoken、微信公众号走 cgi-bin/token、WhatsApp 走 Graph API、Email 走 IMAP TCP banner、企微智能机器人走官方 SDK 长连接(认证成功即通过)
|
|
@@ -27,13 +42,9 @@ DSH Web GUI 的消息平台网关插件:在侧边栏「新会话」按钮下
|
|
|
27
42
|
- **斜杠命令**:`/help` / `/time` / `/status`(含中文别名:帮助/菜单/时间/状态)
|
|
28
43
|
- **进入会话欢迎语**:可选配置(配置项 `welcomeReply`,默认 `false` 保持免打扰,开启后用户当天首次进入单聊自动回复欢迎词)
|
|
29
44
|
- **主动发送通道**:`POST /gateway/send`(`{"chatid": "...", "content": "..."}`,单聊=userid,群聊=群 ID)以机器人身份主动发送 markdown 消息
|
|
30
|
-
- **通用主动推送**:`POST /gateway/push`(`{"platform": "...", "target": "...", "content": "...", "title": "可选"}`)向任意平台目标推送文本,供定时任务通知 / 其他插件调用:
|
|
31
|
-
- `platform` 支持:`telegram`(target=chatId 数字)、`discord`(target=channelId)、`wecom-aibot`(target=userid/群ID)、`email`(target=收件地址,title 作邮件主题)
|
|
32
|
-
- QQ 平台官方已于 2025-04-21 取消主动推送,仅支持被动回复,调用会返回明确错误
|
|
33
|
-
- 未连接的平台返回 `bridge not connected`
|
|
34
45
|
- **消息路由规则**(插件配置 `routes`):按「平台 + 关键词前缀」把消息路由到指定 **agent 预设**(独立会话)与可选**专用模型 / skill**。例如配置 `{ id: "code", matchPlatform: "telegram", matchPrefix: "code ", agentPreset: "code" }` 后,Telegram 里发 `code 帮我写个函数` 会进入 code 预设的独立会话。按顺序匹配第一条命中;未命中走默认 agent
|
|
35
46
|
- **斜杠命令**:`/help` / `/time` / `/status` / `/stats`(含中文别名:帮助/菜单/时间/状态/统计);`/stats` 展示各平台桥连接状态与活跃会话数
|
|
36
|
-
- **Agent 主动推送工具**(`send_chat_message`):自动向 DSH 注册通用推送工具,AI
|
|
47
|
+
- **Agent 主动推送工具**(`send_chat_message`):自动向 DSH 注册通用推送工具,AI 助手在对话中可自主调用该工具将总结、任务结果或告警(含文字与图片截图)推送至企业微信、Telegram、Discord、钉钉等平台
|
|
37
48
|
- **Webhook 接收端点**:`POST /gateway/webhook/in` 接收外部系统消息(`text` / `content` / `message` 任一字段),注入专用 agent 会话并同步返回完整回复;可配置 HMAC-SHA256 签名密钥校验(契约见 [docs/webhooks.md](docs/webhooks.md))
|
|
38
49
|
- **微信个人号(可选外部网关)**:对接本机 Wechaty HTTP 网关的扫码登录与状态轮询(契约见 [docs/wechaty-gateway.md](docs/wechaty-gateway.md))
|
|
39
50
|
- **多语言**:中文 / English / Español,自动跟随 DSH Web 界面语言(西班牙语浏览器自动切换),默认简体中文
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
3
9
|
var __esm = (fn, res) => function __init() {
|
|
4
10
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
5
11
|
};
|
|
@@ -3270,6 +3276,27 @@ var WecomBridge = class {
|
|
|
3270
3276
|
return false;
|
|
3271
3277
|
}
|
|
3272
3278
|
}
|
|
3279
|
+
/**
|
|
3280
|
+
* 主动向会话发送图片消息(chatid:单聊=userid,群聊=群 ID)。
|
|
3281
|
+
* 内部自动上传临时素材(WeCom uploadMedia)后通过 aibot_send_msg 发送。
|
|
3282
|
+
* @param chatid 接收会话 ID
|
|
3283
|
+
* @param image 图片数据(Buffer)
|
|
3284
|
+
* @param filename 可选文件名(默认 image.png)
|
|
3285
|
+
*/
|
|
3286
|
+
async sendImage(chatid, image, filename = "image.png") {
|
|
3287
|
+
try {
|
|
3288
|
+
const media = await this.client?.uploadMedia(image, { type: "image", filename });
|
|
3289
|
+
if (!media?.media_id) {
|
|
3290
|
+
console.error("[dsh-message-gateway] sendImage upload failed: no media_id returned");
|
|
3291
|
+
return false;
|
|
3292
|
+
}
|
|
3293
|
+
await this.client?.sendMediaMessage(chatid, "image", media.media_id);
|
|
3294
|
+
return true;
|
|
3295
|
+
} catch (error) {
|
|
3296
|
+
console.error("[dsh-message-gateway] sendImage failed", error);
|
|
3297
|
+
return false;
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3273
3300
|
/** 回复欢迎语(enter_chat 事件)。 */
|
|
3274
3301
|
async welcome(frame, content) {
|
|
3275
3302
|
try {
|
|
@@ -3419,6 +3446,38 @@ var TelegramBridge = class {
|
|
|
3419
3446
|
const result = await this.sendText(chatId, content);
|
|
3420
3447
|
return result !== null;
|
|
3421
3448
|
}
|
|
3449
|
+
/**
|
|
3450
|
+
* 主动推送图片:向指定 chat 发送照片(支持 Buffer 或图片 URL)。
|
|
3451
|
+
* @param chatId 目标聊天 ID
|
|
3452
|
+
* @param photo 图片数据 Buffer 或公网图片 URL
|
|
3453
|
+
* @param caption 可选图片附带文字说明
|
|
3454
|
+
* @param filename 可选文件名
|
|
3455
|
+
*/
|
|
3456
|
+
async sendPhoto(chatId, photo, caption, filename = "photo.png") {
|
|
3457
|
+
try {
|
|
3458
|
+
if (typeof photo === "string") {
|
|
3459
|
+
const body = { chat_id: chatId, photo };
|
|
3460
|
+
if (caption) body.caption = caption.slice(0, 1024);
|
|
3461
|
+
const result = await this.api("sendPhoto", body);
|
|
3462
|
+
return result?.message_id !== void 0;
|
|
3463
|
+
}
|
|
3464
|
+
const form = new FormData();
|
|
3465
|
+
form.append("chat_id", String(chatId));
|
|
3466
|
+
form.append("photo", new Blob([new Uint8Array(photo)]), filename);
|
|
3467
|
+
if (caption) form.append("caption", caption.slice(0, 1024));
|
|
3468
|
+
const response = await fetch(`https://api.telegram.org/bot${this.token}/sendPhoto`, {
|
|
3469
|
+
method: "POST",
|
|
3470
|
+
body: form,
|
|
3471
|
+
signal: AbortSignal.timeout(3e4)
|
|
3472
|
+
});
|
|
3473
|
+
if (!response.ok) return false;
|
|
3474
|
+
const data = await response.json();
|
|
3475
|
+
return data.ok === true;
|
|
3476
|
+
} catch (error) {
|
|
3477
|
+
console.error("[dsh-message-gateway] telegram sendPhoto failed", error);
|
|
3478
|
+
return false;
|
|
3479
|
+
}
|
|
3480
|
+
}
|
|
3422
3481
|
/** 发送文本(Markdown 失败自动降级纯文本)。 */
|
|
3423
3482
|
async sendText(chatId, text) {
|
|
3424
3483
|
const body = { chat_id: chatId, text: text.slice(0, MSG_LIMIT), parse_mode: "Markdown", disable_web_page_preview: true };
|
|
@@ -3642,6 +3701,34 @@ var DiscordBridge = class {
|
|
|
3642
3701
|
return false;
|
|
3643
3702
|
}
|
|
3644
3703
|
}
|
|
3704
|
+
/**
|
|
3705
|
+
* 主动推送图片:向指定频道发送图片附件。
|
|
3706
|
+
* @param channelId 目标频道 ID
|
|
3707
|
+
* @param image 图片数据 Buffer
|
|
3708
|
+
* @param content 可选文字说明
|
|
3709
|
+
* @param filename 可选文件名
|
|
3710
|
+
*/
|
|
3711
|
+
async sendImage(channelId, image, content, filename = "image.png") {
|
|
3712
|
+
try {
|
|
3713
|
+
const form = new FormData();
|
|
3714
|
+
form.append("files[0]", new Blob([new Uint8Array(image)]), filename);
|
|
3715
|
+
if (content) {
|
|
3716
|
+
form.append("payload_json", JSON.stringify({ content: content.slice(0, MSG_LIMIT2) }));
|
|
3717
|
+
}
|
|
3718
|
+
const response = await fetch(`${REST}/channels/${encodeURIComponent(channelId)}/messages`, {
|
|
3719
|
+
method: "POST",
|
|
3720
|
+
headers: { authorization: `Bot ${this.token}` },
|
|
3721
|
+
body: form,
|
|
3722
|
+
signal: AbortSignal.timeout(3e4)
|
|
3723
|
+
});
|
|
3724
|
+
if (!response.ok) return false;
|
|
3725
|
+
const data = await response.json();
|
|
3726
|
+
return data.id !== void 0;
|
|
3727
|
+
} catch (error) {
|
|
3728
|
+
console.error("[dsh-message-gateway] discord sendImage failed", error);
|
|
3729
|
+
return false;
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3645
3732
|
/** 停止网关连接。 */
|
|
3646
3733
|
stop() {
|
|
3647
3734
|
this.stopped = true;
|
|
@@ -5031,6 +5118,16 @@ var BridgeManager = class {
|
|
|
5031
5118
|
const userid = body.from?.userid ?? "";
|
|
5032
5119
|
const chatid = body.chatid ?? "";
|
|
5033
5120
|
const key = chatid !== "" ? `wecom:group:${chatid}` : `wecom:user:${userid}`;
|
|
5121
|
+
try {
|
|
5122
|
+
const fs = __require("node:fs");
|
|
5123
|
+
const path = __require("node:path");
|
|
5124
|
+
const os = __require("node:os");
|
|
5125
|
+
const target = chatid !== "" ? chatid : userid;
|
|
5126
|
+
if (target) {
|
|
5127
|
+
fs.writeFileSync(path.join(os.homedir(), ".dsh", "latest_wecom_target.txt"), target, "utf8");
|
|
5128
|
+
}
|
|
5129
|
+
} catch {
|
|
5130
|
+
}
|
|
5034
5131
|
const sink = {
|
|
5035
5132
|
stream: (f, sid, content, finish) => void this.wecom?.streamReply(f, sid, content, finish)
|
|
5036
5133
|
// 企业微信走单一流式消息(ack → 内容 → 定稿同一条消息就地更新);
|
|
@@ -5189,6 +5286,115 @@ ${secret}`;
|
|
|
5189
5286
|
return { ok: false, detail: `platform "${platform}" does not support push` };
|
|
5190
5287
|
}
|
|
5191
5288
|
}
|
|
5289
|
+
/**
|
|
5290
|
+
* 主动推送图片:向指定平台的目标会话发送图片。
|
|
5291
|
+
* - wecom-aibot: 自动上传临时素材并发送 image 消息
|
|
5292
|
+
* - telegram: 调用 sendPhoto(支持 Buffer 上传或图片 URL)
|
|
5293
|
+
* - discord: multipart 上传 files[0] 附件
|
|
5294
|
+
* - bark: 支持图片 URL 传入(通过 image 字段富文本横幅展示)
|
|
5295
|
+
* - dingtalk: 支持图片 URL(在 Markdown 中嵌入 ![]())
|
|
5296
|
+
* - serverchan: 支持图片 URL(在 Markdown desp 中嵌入 ![]())
|
|
5297
|
+
* - feishu / qq / email / 其它: 对不支持的二进制上传返回明确的官方协议限制原因
|
|
5298
|
+
*
|
|
5299
|
+
* @param platform 平台 id
|
|
5300
|
+
* @param target 目标(wecom-aibot=userid/群ID;telegram=chatId;discord=channelId;bark=deviceKey 等)
|
|
5301
|
+
* @param image 图片数据 Buffer 或可公网访问的图片 URL 字符串
|
|
5302
|
+
* @param opts.caption 可选文字说明
|
|
5303
|
+
* @param opts.filename 可选文件名(默认 image.png)
|
|
5304
|
+
*/
|
|
5305
|
+
async pushImage(platform, target, image, opts = {}) {
|
|
5306
|
+
const filename = opts.filename ?? "image.png";
|
|
5307
|
+
const isUrl = typeof image === "string" && /^https?:\/\//i.test(image.trim());
|
|
5308
|
+
switch (platform) {
|
|
5309
|
+
case "wecom-aibot": {
|
|
5310
|
+
if (this.wecom === null) return { ok: false, detail: "wecom-aibot bridge not connected" };
|
|
5311
|
+
if (typeof image === "string") {
|
|
5312
|
+
try {
|
|
5313
|
+
const resp = await fetch(image, { signal: AbortSignal.timeout(2e4) });
|
|
5314
|
+
if (!resp.ok) return { ok: false, detail: `failed to fetch image from url: HTTP ${resp.status}` };
|
|
5315
|
+
image = Buffer.from(await resp.arrayBuffer());
|
|
5316
|
+
} catch (err) {
|
|
5317
|
+
return { ok: false, detail: `fetch image url error: ${err instanceof Error ? err.message : String(err)}` };
|
|
5318
|
+
}
|
|
5319
|
+
}
|
|
5320
|
+
const sent = await this.wecom.sendImage(target, image, filename);
|
|
5321
|
+
return sent ? { ok: true, detail: "sent" } : { ok: false, detail: "wecom image send failed" };
|
|
5322
|
+
}
|
|
5323
|
+
case "telegram": {
|
|
5324
|
+
if (this.telegram === null) return { ok: false, detail: "telegram bridge not connected" };
|
|
5325
|
+
const chatId = Number(target);
|
|
5326
|
+
if (!Number.isInteger(chatId) || chatId <= 0) return { ok: false, detail: "telegram target must be a numeric chatId" };
|
|
5327
|
+
const sent = await this.telegram.sendPhoto(chatId, image, opts.caption, filename);
|
|
5328
|
+
return sent ? { ok: true, detail: "sent" } : { ok: false, detail: "telegram photo send failed" };
|
|
5329
|
+
}
|
|
5330
|
+
case "discord": {
|
|
5331
|
+
if (this.discord === null) return { ok: false, detail: "discord bridge not connected" };
|
|
5332
|
+
let buf;
|
|
5333
|
+
if (typeof image === "string") {
|
|
5334
|
+
try {
|
|
5335
|
+
const resp = await fetch(image, { signal: AbortSignal.timeout(2e4) });
|
|
5336
|
+
if (!resp.ok) return { ok: false, detail: `failed to fetch image from url: HTTP ${resp.status}` };
|
|
5337
|
+
buf = Buffer.from(await resp.arrayBuffer());
|
|
5338
|
+
} catch (err) {
|
|
5339
|
+
return { ok: false, detail: `fetch image url error: ${err instanceof Error ? err.message : String(err)}` };
|
|
5340
|
+
}
|
|
5341
|
+
} else {
|
|
5342
|
+
buf = image;
|
|
5343
|
+
}
|
|
5344
|
+
const sent = await this.discord.sendImage(target, buf, opts.caption, filename);
|
|
5345
|
+
return sent ? { ok: true, detail: "sent" } : { ok: false, detail: "discord image send failed" };
|
|
5346
|
+
}
|
|
5347
|
+
case "bark": {
|
|
5348
|
+
if (!isUrl) {
|
|
5349
|
+
return { ok: false, detail: "Bark only supports public image URLs (pass image as http/https URL string)" };
|
|
5350
|
+
}
|
|
5351
|
+
const { loadStore: loadStore2 } = await Promise.resolve().then(() => (init_gateway_store(), gateway_store_exports));
|
|
5352
|
+
const store = await loadStore2();
|
|
5353
|
+
const server = (store.platforms.bark?.serverUrl || "https://api.day.app").replace(/\/+$/, "");
|
|
5354
|
+
const deviceKey = target || store.platforms.bark?.deviceKey;
|
|
5355
|
+
if (!deviceKey) return { ok: false, detail: "missing bark device key" };
|
|
5356
|
+
const url = `${server}/${encodeURIComponent(deviceKey)}/`;
|
|
5357
|
+
const resp = await fetch(url, {
|
|
5358
|
+
method: "POST",
|
|
5359
|
+
headers: { "content-type": "application/json" },
|
|
5360
|
+
body: JSON.stringify({
|
|
5361
|
+
title: opts.caption ?? "DSH \u901A\u77E5",
|
|
5362
|
+
body: opts.caption ? "" : "\u6536\u5230\u4E00\u5F20\u56FE\u7247",
|
|
5363
|
+
image,
|
|
5364
|
+
group: "DSH"
|
|
5365
|
+
})
|
|
5366
|
+
});
|
|
5367
|
+
const r = await resp.json().catch(() => ({}));
|
|
5368
|
+
return r.code === 200 || resp.status === 200 ? { ok: true, detail: "sent" } : { ok: false, detail: r.message ?? "bark send failed" };
|
|
5369
|
+
}
|
|
5370
|
+
case "dingtalk": {
|
|
5371
|
+
if (!isUrl) {
|
|
5372
|
+
return { ok: false, detail: "DingTalk custom robot only supports public image URLs via Markdown image tag" };
|
|
5373
|
+
}
|
|
5374
|
+
const caption = opts.caption ?? "\u56FE\u7247";
|
|
5375
|
+
const mdText = `${caption ? `${caption}
|
|
5376
|
+
|
|
5377
|
+
` : ""}`;
|
|
5378
|
+
return this.pushMessage("dingtalk", target, mdText, { title: opts.caption ?? "\u56FE\u7247" });
|
|
5379
|
+
}
|
|
5380
|
+
case "serverchan": {
|
|
5381
|
+
if (!isUrl) {
|
|
5382
|
+
return { ok: false, detail: "ServerChan only supports public image URLs via Markdown desp" };
|
|
5383
|
+
}
|
|
5384
|
+
const caption = opts.caption ?? "\u56FE\u7247";
|
|
5385
|
+
const mdText = `${caption ? `${caption}
|
|
5386
|
+
|
|
5387
|
+
` : ""}`;
|
|
5388
|
+
return this.pushMessage("serverchan", target, mdText, { title: opts.caption ?? "\u56FE\u7247" });
|
|
5389
|
+
}
|
|
5390
|
+
case "feishu":
|
|
5391
|
+
return { ok: false, detail: "Feishu custom robot webhook does not support binary image upload without tenant_access_token (im/v1/images)" };
|
|
5392
|
+
case "qq":
|
|
5393
|
+
return { ok: false, detail: "QQ platform has discontinued active push API since 2025-04-21" };
|
|
5394
|
+
default:
|
|
5395
|
+
return { ok: false, detail: `platform "${platform}" does not support image push` };
|
|
5396
|
+
}
|
|
5397
|
+
}
|
|
5192
5398
|
/**
|
|
5193
5399
|
* 向已配置的 Outbound Webhooks 广播事件(异步投递,失败不阻塞)。
|
|
5194
5400
|
*/
|
|
@@ -6036,7 +6242,7 @@ function callbackIdentity(key, send) {
|
|
|
6036
6242
|
}
|
|
6037
6243
|
|
|
6038
6244
|
// src/host/routes.ts
|
|
6039
|
-
var BODY_CAP_BYTES =
|
|
6245
|
+
var BODY_CAP_BYTES = 8 << 20;
|
|
6040
6246
|
var CALLBACK_PATHS = {
|
|
6041
6247
|
wecom: "/gateway/wecom/callback",
|
|
6042
6248
|
"wechat-mp": "/gateway/wechat-mp/callback",
|
|
@@ -6361,18 +6567,57 @@ function registerGatewayRoutes(ctx, manager) {
|
|
|
6361
6567
|
const target = typeof body?.target === "string" ? body.target.trim() : "";
|
|
6362
6568
|
const content = typeof body?.content === "string" ? body.content.trim() : "";
|
|
6363
6569
|
const title = typeof body?.title === "string" ? body.title.trim() : "";
|
|
6364
|
-
|
|
6365
|
-
|
|
6570
|
+
const imageB64 = typeof body?.image === "string" ? body.image.trim() : "";
|
|
6571
|
+
const filename = typeof body?.filename === "string" && body.filename.trim() !== "" ? body.filename.trim() : void 0;
|
|
6572
|
+
if (platform === "" || target === "" || content === "" && imageB64 === "") {
|
|
6573
|
+
json(res, { ok: false, error: { code: "internal", message: "missing platform/target, or both content and image are empty" } }, 400);
|
|
6366
6574
|
return;
|
|
6367
6575
|
}
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6576
|
+
if (content !== "") {
|
|
6577
|
+
const textResult = await manager.pushMessage(platform, target, content, { title: title === "" ? void 0 : title });
|
|
6578
|
+
if (!textResult.ok) {
|
|
6579
|
+
json(res, { ok: false, error: { code: "internal", message: textResult.detail } }, 409);
|
|
6580
|
+
return;
|
|
6581
|
+
}
|
|
6582
|
+
}
|
|
6583
|
+
if (imageB64 !== "") {
|
|
6584
|
+
let imagePayload;
|
|
6585
|
+
if (/^https?:\/\//i.test(imageB64)) {
|
|
6586
|
+
imagePayload = imageB64;
|
|
6587
|
+
} else {
|
|
6588
|
+
const cleanB64 = imageB64.replace(/^data:image\/[a-zA-Z0-9+.-]+;base64,/, "");
|
|
6589
|
+
try {
|
|
6590
|
+
imagePayload = Buffer.from(cleanB64, "base64");
|
|
6591
|
+
} catch {
|
|
6592
|
+
json(res, { ok: false, error: { code: "internal", message: "invalid base64 image data" } }, 400);
|
|
6593
|
+
return;
|
|
6594
|
+
}
|
|
6595
|
+
}
|
|
6596
|
+
const imgResult = await manager.pushImage(platform, target, imagePayload, {
|
|
6597
|
+
caption: content !== "" ? void 0 : title !== "" ? title : void 0,
|
|
6598
|
+
filename
|
|
6599
|
+
});
|
|
6600
|
+
if (!imgResult.ok) {
|
|
6601
|
+
json(res, { ok: false, error: { code: "internal", message: imgResult.detail } }, 409);
|
|
6602
|
+
return;
|
|
6603
|
+
}
|
|
6372
6604
|
}
|
|
6373
6605
|
json(res, { ok: true, value: { sent: true } });
|
|
6374
6606
|
return;
|
|
6375
6607
|
}
|
|
6608
|
+
if (path === "/gateway/recent-target") {
|
|
6609
|
+
const fs = await import("node:fs");
|
|
6610
|
+
const pathModule = await import("node:path");
|
|
6611
|
+
const os = await import("node:os");
|
|
6612
|
+
const targetFile = pathModule.join(os.homedir(), ".dsh", "latest_wecom_target.txt");
|
|
6613
|
+
let target = "";
|
|
6614
|
+
try {
|
|
6615
|
+
target = fs.readFileSync(targetFile, "utf8").trim();
|
|
6616
|
+
} catch {
|
|
6617
|
+
}
|
|
6618
|
+
json(res, { ok: true, value: { target } });
|
|
6619
|
+
return;
|
|
6620
|
+
}
|
|
6376
6621
|
if (path === "/gateway/send") {
|
|
6377
6622
|
const body = payload;
|
|
6378
6623
|
const chatid = typeof body?.chatid === "string" ? body.chatid.trim() : "";
|
|
@@ -6567,6 +6812,14 @@ function apply(ctx, config = Config({})) {
|
|
|
6567
6812
|
title: {
|
|
6568
6813
|
type: "string",
|
|
6569
6814
|
description: "\u53EF\u9009\u6807\u9898\uFF08email \u4F5C\u4E3A\u4E3B\u9898\uFF0C\u5176\u4ED6\u5E73\u53F0\u4F5C\u4E3A\u9996\u884C\u52A0\u7C97\u524D\u7F00\uFF09"
|
|
6815
|
+
},
|
|
6816
|
+
image: {
|
|
6817
|
+
type: "string",
|
|
6818
|
+
description: "\u53EF\u9009\u56FE\u7247\u6570\u636E\uFF1ABase64 \u5B57\u7B26\u4E32\u6216\u516C\u7F51\u53EF\u8BBF\u95EE\u7684 http/https \u56FE\u7247 URL"
|
|
6819
|
+
},
|
|
6820
|
+
filename: {
|
|
6821
|
+
type: "string",
|
|
6822
|
+
description: "\u53EF\u9009\u56FE\u7247\u6587\u4EF6\u540D\uFF08\u5982 screenshot.png\uFF0C\u9ED8\u8BA4 image.png\uFF09"
|
|
6570
6823
|
}
|
|
6571
6824
|
},
|
|
6572
6825
|
output: {
|
|
@@ -6578,14 +6831,27 @@ function apply(ctx, config = Config({})) {
|
|
|
6578
6831
|
const target = String(args.target ?? "").trim();
|
|
6579
6832
|
const message = String(args.message ?? "").trim();
|
|
6580
6833
|
const title = args.title !== void 0 ? String(args.title).trim() : void 0;
|
|
6581
|
-
|
|
6582
|
-
|
|
6834
|
+
const image = args.image !== void 0 ? String(args.image).trim() : void 0;
|
|
6835
|
+
const filename = args.filename !== void 0 ? String(args.filename).trim() : void 0;
|
|
6836
|
+
if (!platform || !target || !message && !image) {
|
|
6837
|
+
return "\u9519\u8BEF\uFF1Aplatform\u3001target \u4E3A\u5FC5\u586B\uFF0C\u4E14 message \u4E0E image \u81F3\u5C11\u63D0\u4F9B\u4E00\u4E2A";
|
|
6583
6838
|
}
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
return `\
|
|
6839
|
+
if (message) {
|
|
6840
|
+
const res = await manager.pushMessage(platform, target, message, { title });
|
|
6841
|
+
if (!res.ok) return `\u6587\u672C\u63A8\u9001\u5931\u8D25\uFF1A${res.detail}`;
|
|
6842
|
+
}
|
|
6843
|
+
if (image) {
|
|
6844
|
+
let imgPayload;
|
|
6845
|
+
if (/^https?:\/\//i.test(image)) {
|
|
6846
|
+
imgPayload = image;
|
|
6847
|
+
} else {
|
|
6848
|
+
const clean = image.replace(/^data:image\/[a-zA-Z0-9+.-]+;base64,/, "");
|
|
6849
|
+
imgPayload = Buffer.from(clean, "base64");
|
|
6850
|
+
}
|
|
6851
|
+
const imgRes = await manager.pushImage(platform, target, imgPayload, { caption: message ? void 0 : title, filename });
|
|
6852
|
+
if (!imgRes.ok) return `\u56FE\u7247\u63A8\u9001\u5931\u8D25\uFF1A${imgRes.detail}`;
|
|
6587
6853
|
}
|
|
6588
|
-
return `\u63A8\u9001\
|
|
6854
|
+
return `\u5DF2\u6210\u529F\u63A8\u9001\u81F3 [${platform}] \u76EE\u6807 ${target}`;
|
|
6589
6855
|
}
|
|
6590
6856
|
}));
|
|
6591
6857
|
}
|