55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
/**
|
|
* 空运群出站报文:禁止 stream(企微会加「内容由AI生成」和赞踩)。
|
|
* 只发 markdown,且不带 feedback。
|
|
* 有这次 @ 的 req_id 才走 aibot_respond_msg,群里才会引用原消息。
|
|
*/
|
|
function pickReplyReqId({ fromCaller, fromChat, lastAny }) {
|
|
const caller = String(fromCaller || "").trim();
|
|
if (caller) {
|
|
return caller;
|
|
}
|
|
const chat = String(fromChat || "").trim();
|
|
if (chat) {
|
|
return chat;
|
|
}
|
|
return String(lastAny || "").trim();
|
|
}
|
|
|
|
// 含星号的尺寸或箱量。已在行内代码里的整段跳过,避免套两层。
|
|
const STAR_TOKEN = /`[^`]*`|([A-Za-z0-9.]+(?:\s*\*\s*[A-Za-z0-9.]+)+)/g;
|
|
|
|
function showLiteralAsterisks(text) {
|
|
// 企微 markdown 会吃掉星号:1.1*2.1*2.1 显示成 1.12.12.1。
|
|
// 放进行内代码后,群里仍是星号。智能体若已经套过,这里不再套第二层。
|
|
return String(text || "").replace(STAR_TOKEN, (full, token) => (token ? "`" + token + "`" : full));
|
|
}
|
|
|
|
function buildGroupMessageFrame({ chatId, content, callbackReqId, reqId }) {
|
|
const text = showLiteralAsterisks(String(content || ""));
|
|
const markdown = { content: text };
|
|
if (callbackReqId) {
|
|
return {
|
|
cmd: "aibot_respond_msg",
|
|
headers: { req_id: callbackReqId },
|
|
body: {
|
|
chatid: chatId,
|
|
chat_type: 2,
|
|
msgtype: "markdown",
|
|
markdown,
|
|
},
|
|
};
|
|
}
|
|
return {
|
|
cmd: "aibot_send_msg",
|
|
headers: { req_id: reqId || "aibot_send_msg" },
|
|
body: {
|
|
chatid: chatId,
|
|
chat_type: 2,
|
|
msgtype: "markdown",
|
|
markdown,
|
|
},
|
|
};
|
|
}
|
|
|
|
module.exports = { buildGroupMessageFrame, pickReplyReqId, showLiteralAsterisks };
|