wxbot: stripMarkdown 开关化,默认不剥——微信已支持 markdown 渲染,出口透传保格式;DEFAULTS.bot.strip_markdown=false + env WXBOT_STRIP_MARKDOWN=1/true 可恢复旧纯文化降级(0/off 显式关闭,同 WXBOT_LOG_LEVEL 注入模式),命令回执与 /api/deliver 两处发送统一走 outText()。channel.js 出口注释同步(渲染适配在消费方不变,默认形态改为透传);wxbot/README env 表与 /api/deliver 行更新。compose 的 WXBOT_STRIP_MARKDOWN 注线与 ARCHITECTURE 同步暂留工作树(与未提交的 wechat digest 改动、core VIRTUAL_HOST WIP 混在同一文件,避免夹带)。
This commit is contained in:
@@ -83,7 +83,7 @@ function parseCommand(text) {
|
||||
}
|
||||
|
||||
// 命令输出统一用 markdown(channel 层的规范格式):支持渲染的接入端直接用,
|
||||
// 微信这类纯文本端由 wxbot 发送前 stripMarkdown 降级——格式信息留在生产方,渲染适配在消费方。
|
||||
// 微信端渲染适配在 wxbot 出口:默认透传 markdown(微信已支持渲染),env WXBOT_STRIP_MARKDOWN=1 才 stripMarkdown 纯文化——格式信息留在生产方,渲染适配在消费方。
|
||||
const HELP_TEXT = [
|
||||
'**可用命令**',
|
||||
'- `/new [msg]` 新建会话并切换',
|
||||
@@ -109,7 +109,7 @@ function statusReply(db, s) {
|
||||
const looping = !!(run && run.looping);
|
||||
const lines = [
|
||||
'**会话状态**',
|
||||
'- 会话:`' + (s.title || s.id),
|
||||
'- 会话:`' + (s.title || s.id) + '`',
|
||||
'- 状态:' + (looping ? '回合进行中' : (STATUS_TEXT[s.status] || s.status)),
|
||||
'- 模型:`' + (s.model_id || '未绑定') + '`',
|
||||
];
|
||||
|
||||
+2
-1
@@ -40,6 +40,7 @@ agent-core 的 `wechat_bindings` 表;扫码二维码呈现在 agent-core 的 W
|
||||
| `WXBOT_TOKEN` | 根 `.env`(`scripts/init.sh` 生成/复用) | 本服务 `/api/*` 鉴权白名单(自动并入)+ 回调 core `/wxhook/*` 的凭据,与 core 侧同一值双向互信 |
|
||||
| `CORE_URL` | compose 静态注 `http://agent-core:8090` | 转发目标 |
|
||||
| `WXBOT_LOG_LEVEL` | compose 静态注 `info` | 日志等级(debug 原样打印收信消息结构;none/off→silent) |
|
||||
| `WXBOT_STRIP_MARKDOWN` | 根 `.env` 可选(默认空) | 出口 markdown 纯文化开关:空/0 = 原样透传(微信已支持渲染);1 = 恢复 stripMarkdown 降级 |
|
||||
|
||||
端口、非文本消息占位文案等次要旋钮走 `src/server.js` 内置 DEFAULTS;日志等级由 env `WXBOT_LOG_LEVEL`
|
||||
决定(compose 注入,同 executor 的 `EXECUTOR_LOG_LEVEL` 约定;`debug` 原样打印收信消息结构,
|
||||
@@ -68,7 +69,7 @@ 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 已分段;出口统一 stripMarkdown,微信不渲染 markdown) |
|
||||
| POST | `/api/deliver {id,to,text}` | 文本投递(core 已分段;markdown 默认透传,微信已支持渲染,`WXBOT_STRIP_MARKDOWN=1` 时出口纯文化) |
|
||||
| POST | `/api/typing {id,to}` | 「正在输入」心跳(core 在工具调用/结果时触发,每绑定 2s 冷却;typing 自然过期无需 stopTyping) |
|
||||
| POST | `/api/deliver_media {id,to,filename,b64}` | 附件投递(core 已把正文里的 /p/ 链接换成本地字节并做归属/大小校验;SDK 按扩展名自动路由 image/video/file 卡片) |
|
||||
|
||||
|
||||
+14
-3
@@ -29,6 +29,7 @@ const DEFAULTS = {
|
||||
bot: {
|
||||
storage_dir: "/data/bots", // 每绑定一个子目录(目录名 = binding id)
|
||||
log_level: "info", // debug | info | warn | error | silent;运行期被 env WXBOT_LOG_LEVEL 覆盖(compose 注入,同 EXECUTOR_LOG_LEVEL 模式)
|
||||
strip_markdown: false, // 出口 markdown 纯文化开关:微信已支持渲染 markdown,默认 false 原样透传;env WXBOT_STRIP_MARKDOWN=1 可恢复剥除
|
||||
empty_hint: "(这条消息类型暂时接不住——支持文字/图片/视频/文件;指令可发 /help)", // 未接入类型(voice/贴纸等)的本地兑底回执
|
||||
},
|
||||
};
|
||||
@@ -111,6 +112,16 @@ fs.mkdirSync(CONFIG.bot.storage_dir, { recursive: true });
|
||||
CONFIG.bot.log_level = map[lv] || String(CONFIG.bot.log_level || "info").toLowerCase();
|
||||
}
|
||||
|
||||
// markdown 出口处理开关:微信已支持渲染 markdown → 默认透传;若某些客户端/版本翻车,
|
||||
// env WXBOT_STRIP_MARKDOWN=1/true(compose 注入)或配置文件 bot.strip_markdown: true 恢复旧行为(出口纯文化)。
|
||||
{
|
||||
const ev = String(process.env.WXBOT_STRIP_MARKDOWN || "").trim().toLowerCase();
|
||||
if (ev) CONFIG.bot.strip_markdown = /^(1|true|on|yes)$/.test(ev);
|
||||
else CONFIG.bot.strip_markdown = CONFIG.bot.strip_markdown === true || CONFIG.bot.strip_markdown === "true";
|
||||
}
|
||||
// 出口文本:开关开启才 stripMarkdown,否则原样;命令回执与 /api/deliver 两处发送共用。
|
||||
const outText = (s) => (CONFIG.bot.strip_markdown ? stripMarkdown(String(s)) : String(s));
|
||||
|
||||
// ── 鉴权 ─────────────────────────────────────────────────────────────────────
|
||||
function requireAuth(req, res, next) {
|
||||
if (!CONFIG.auth.enabled) return next();
|
||||
@@ -282,8 +293,8 @@ async function onIncoming(inst, msg) {
|
||||
}
|
||||
try {
|
||||
const r = await corePost("/wxhook/inbox", { id: inst.id, from: userId, text: text || undefined, media: media || undefined }, 30000);
|
||||
// 命令回执可能是 markdown(channel 层规范格式);微信不渲染 markdown,出口统一 stripMarkdown 降级。
|
||||
if (r && r.kind === "command" && r.reply) await inst.bot.send(userId, stripMarkdown(r.reply));
|
||||
// 命令回执可能是 markdown(channel 层规范格式);默认透传(微信已支持渲染),开关控制是否纯文化。
|
||||
if (r && r.kind === "command" && r.reply) await inst.bot.send(userId, outText(r.reply));
|
||||
} catch (e) {
|
||||
if (e.status === 404) {
|
||||
// core 侧绑定已删(解绑通知丢失的孤儿实例):告知用户并自毁(连凭证一起清,避免复活再骚扰)
|
||||
@@ -357,7 +368,7 @@ app.post("/api/deliver", requireAuth, async (req, res) => {
|
||||
if (!inst) return res.status(404).json({ error: "实例不存在" });
|
||||
if (!to || !String(text || "").trim()) return res.status(400).json({ error: "to/text 不能为空" });
|
||||
try {
|
||||
await inst.bot.send(String(to), stripMarkdown(String(text)));
|
||||
await inst.bot.send(String(to), outText(text));
|
||||
res.json({ ok: true });
|
||||
} catch (e) {
|
||||
res.status(502).json({ error: "发送失败:" + String(e?.message || e).slice(0, 200) });
|
||||
|
||||
Reference in New Issue
Block a user