微信渠道上下文与出站文件卡片:收信幂等注入 channel_note(微信环境说明+「给链接即交付」约定)并强制 executing(跳过顾问 handoff,同定时任务理由);deliverNow 扫 /p/ 链接→归属硬校验→deliver_media→SDK 自动路由 image/video/file 卡片(链接文字兜底);wxbot /api/deliver_media 30mb 解析器前置
This commit is contained in:
+4
-2
@@ -65,7 +65,8 @@ docker compose up -d agent-core # core 带 WXBOT_URL/WXBOT_TOKEN 重建(
|
||||
| POST | `/api/instances/:id/refresh` | 重发登录流程(二维码过期/失败后;保留凭证) |
|
||||
| DELETE | `/api/instances/:id` | 销毁实例并删登录凭证(解绑) |
|
||||
| GET | `/api/instances/:id/qr.svg` | 当前登录二维码(core 设置页代理渲染) |
|
||||
| POST | `/api/deliver {id,to,text}` | 外发投递(core 已按微信长度分段) |
|
||||
| POST | `/api/deliver {id,to,text}` | 文本投递(core 已分段;出口统一 stripMarkdown,微信不渲染 markdown) |
|
||||
| POST | `/api/deliver_media {id,to,filename,b64}` | 附件投递(core 已把正文里的 /p/ 链接换成本地字节并做归属/大小校验;SDK 按扩展名自动路由 image/video/file 卡片) |
|
||||
|
||||
## 本地调试
|
||||
|
||||
@@ -80,5 +81,6 @@ WXBOT_TOKEN=$WXBOT_TOKEN CORE_URL=http://127.0.0.1:8090 \
|
||||
|
||||
- 语音消息目前回 `bot.empty_hint` 占位(二期:SDK `bot.download(msg)` 拿 WAV(需 `silk-wasm`)
|
||||
→ tools/asr `/api/transcribe` 转写后进会话)。
|
||||
- 出站图片/文件二期:core 的 `GET /p/<id>` 公网链喂 `bot.send(userId, {url})`(SDK 自动下载上传 CDN)。
|
||||
- 出站文件/图片已实现「链接→卡片」:AI 在回复正文里给 mint 链接,core 自动换成微信文件卡片
|
||||
(链接文字保留兜底);AI 侧约定见 core 注入的 channel_note。
|
||||
- core 未配 `WXBOT_URL` 时微信功能整体静默关闭(设置页不出现入口,服务零报错)。
|
||||
|
||||
+24
-1
@@ -265,9 +265,12 @@ async function onIncoming(inst, msg) {
|
||||
}
|
||||
}
|
||||
|
||||
// ── HTTP 服务 ────────────────────────────────────────────────────────────────
|
||||
// ── HTTP 服务 ──────────────────────────────────────────────────────────────────────
|
||||
const app = express();
|
||||
app.disable("x-powered-by");
|
||||
// 附件投递带 base64 大 body:该路径单独先挂大限额解析器(早于全局 1mb;body-parser 幂等,
|
||||
// 全局那份见到 req._body 会自动跳过),与 core 侧 /wxhook 同法。
|
||||
app.use("/api/deliver_media", express.json({ limit: "30mb" }));
|
||||
app.use(express.json({ limit: "1mb" }));
|
||||
|
||||
app.get("/health", (_req, res) => {
|
||||
@@ -330,6 +333,26 @@ app.post("/api/deliver", requireAuth, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// core → wxbot 附件投递(链接→卡片):core 已把正文里的 /p/ 链接换成本地读好的字节并做
|
||||
// 归属/大小/数量校验;这里只转发 SDK——bot.send 的 file 按扩展名自动路由 image/video/file 卡片,
|
||||
// CDN 上传 + 加密全在 SDK 内。
|
||||
app.post("/api/deliver_media", requireAuth, async (req, res) => {
|
||||
const { id, to, filename, b64 } = req.body || {};
|
||||
const inst = instances.get(String(id || ""));
|
||||
if (!inst) return res.status(404).json({ error: "实例不存在" });
|
||||
if (!to || !String(b64 || "").trim()) return res.status(400).json({ error: "to/b64 不能为空" });
|
||||
const buf = Buffer.from(String(b64).slice(0, 30 * 1024 * 1024), "base64");
|
||||
if (!buf.length) return res.status(400).json({ error: "b64 解码失败" });
|
||||
if (buf.length > 20 * 1024 * 1024) return res.status(413).json({ error: "附件过大(限 20MB)" });
|
||||
const safeName = String(filename || "file").split(/[\\/]/).pop().slice(0, 120) || "file";
|
||||
try {
|
||||
await inst.bot.send(String(to), { file: buf, fileName: safeName });
|
||||
res.json({ ok: true });
|
||||
} catch (e) {
|
||||
res.status(502).json({ error: "附件发送失败:" + String(e?.message || e).slice(0, 200) });
|
||||
}
|
||||
});
|
||||
|
||||
// 启动即恢复:扫描凭证目录逐个拉起实例(core 不在线也照常上线;状态回调失败不影响)
|
||||
for (const ent of fs.readdirSync(CONFIG.bot.storage_dir, { withFileTypes: true })) {
|
||||
if (ent.isDirectory() && ID_RE.test(ent.name)) createInstance(ent.name);
|
||||
|
||||
Reference in New Issue
Block a user