协同群改为智价通BOT接管对话,报价单按需生成;补客户名称、计费重与陆运报价条件
为什么改:应用建的协同群只能代答,销售在群里发文件、@人、问报价都对不上人; 本次把群对话交给智价通BOT,应用只负责拉群和解散群,并把几处销售已反馈的口径补齐。 群与身份: - 新增 group_bot 短协调(Redis 带环境前缀):记录 BOT 已接管群、当前关联工单、 @BOT 指令窗口与窗口外先到的附件,只做协调不当六态,六态仍在主账。 - 群里没有 @BOT 的文字不回;非 @ 文字断开当前单关联,之后必须重新 @BOT 带工单号。 - 先发文件再 @BOT 也认:窗口外附件先缓冲,等 @BOT 认领后补办。 - 会话存档只补附件、不重复办理 BOT 已办的同一句文字,避免同一条消息回两遍。 - 入站 from.userid 是加密 open_userid 时按官方接口换明文(带 Redis 缓存), 否则与主账 sales_wecom_id 永远比不上,航线本人会被判成「不是本人」。 - 桥侧只认本群 req_id,不再借用别的群 req_id,避免测服把话发进别的群。 报价单: - 建群后只发字段摘要和成交卡,Excel/PDF 等群里 @BOT 说「生成报价单」再出; 多段逐段出,没价出空白表;出表后补推成交跟进不涨 deal_version、不重置等待计时。 - 陆运转人工先选业务类型和报价场景再建群,按选定模板名直取,不再靠关键词猜。 - 空运舱位只回一条时直接出该条报价,不再发选择卡。 字段与金额: - 客户名称改为海/空/陆询价非必填,有值写回工单列,后台列表、报价单与 factsJson 一致。 - 空运新增计费重投影:体积重=CBM×166.7,计费重=max(毛重,体积重); TMS 无价、航线手工按 KG 报价时按计费重×单价算整票金额,群摘要与报价单同公式。 - 陆运报价附加条件统一到 land_quote_condition:未含税/含0税/未含燃油/含燃油费, 燃油只乘主运费,不乘提货送货报关等杂费;跨境整车无备注列时追加到底部备注事项。 - 海运拼柜不适用箱型箱量:不进必填、不进补问、不出站,改回整柜可再用。 - 海运提货地址/派送地址改为非必填,写了才出站(placeOfReceipt/deliveryAddress), 禁止从港口或贸易条款反推地址;TMS 查不到价时把 TMS 原话透给销售。 - 中港集拼与跨境集拼同口径:按体积+毛重,不采车型数量;修正被国内拼车别名抢单。 - 报关费区只收报关类费目;口岸海关监管费+接驳费按车型列回填固定行。 主账与后台: - 看板处理量按协同群处理人统计;下线「平均报价销售额」;处理人搜索先把姓名换回企微 id。 - 「转人工」筛选同时兼容旧六态与新 collab_mode=handoff,新版单不再漏。 - 报价单客户名称、提货/派送地址、空运计费重、拼柜空箱型按新口径填表。 - 新增协同成员查询支持与 AIR_NEED_WO v2 迁移脚本。 文档:04 补海运/空运/陆运必填与地址口径,10 补地址出站规则,12 补测服独立应用 1000015 的部署与切换记录。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,17 +2,19 @@
|
||||
* 空运群出站报文:禁止 stream(企微会加「内容由AI生成」和赞踩)。
|
||||
* 只发 markdown,且不带 feedback。
|
||||
* 有这次 @ 的 req_id 才走 aibot_respond_msg,群里才会引用原消息。
|
||||
*
|
||||
* 2026-11-21 修复(测服超时话术跑到空运群):
|
||||
* req_id 只能是「本群」的。企微 aibot_respond_msg 按 req_id 投递回原会话,
|
||||
* body.chatid 不改变投递目标;以前在拿不到本群 req_id 时回退到 lastAny
|
||||
* (最近一次任意群 @),结果陆运/海运群主动发言被投递到最后 @ 机器人的空运群。
|
||||
* 这里删掉跨群回退:拿不到本群 req_id 就返回空,调用方改走 aibot_send_msg + 指定 chatid。
|
||||
*/
|
||||
function pickReplyReqId({ fromCaller, fromChat, lastAny }) {
|
||||
function pickReplyReqId({ fromCaller, fromChat }) {
|
||||
const caller = String(fromCaller || "").trim();
|
||||
if (caller) {
|
||||
return caller;
|
||||
}
|
||||
const chat = String(fromChat || "").trim();
|
||||
if (chat) {
|
||||
return chat;
|
||||
}
|
||||
return String(lastAny || "").trim();
|
||||
return String(fromChat || "").trim();
|
||||
}
|
||||
|
||||
// 含星号的尺寸或箱量。已在行内代码里的整段跳过,避免套两层。
|
||||
|
||||
@@ -50,7 +50,6 @@ function startLongConnectionLoop(opts) {
|
||||
lastError: "",
|
||||
pending: new Map(),
|
||||
lastCallback: new Map(),
|
||||
lastAnyReq: "",
|
||||
heartbeatTimer: null,
|
||||
reconnectTimer: null,
|
||||
stop: () => {},
|
||||
@@ -90,10 +89,10 @@ function startLongConnectionLoop(opts) {
|
||||
const fromCaller = String(callbackReqId || "").trim();
|
||||
const chatKey = String(chatId || "").trim();
|
||||
const fromChat = state.lastCallback.get(chatKey) || "";
|
||||
// 只用本群 req_id:跨群回退会把话发到别的群(企微按 req_id 投递)。
|
||||
const replyReqId = pickReplyReqId({
|
||||
fromCaller,
|
||||
fromChat,
|
||||
lastAny: state.lastAnyReq || "",
|
||||
});
|
||||
// 用这次 @ 的 req_id 回 aibot_respond_msg,群里才会引用原消息。
|
||||
const reqId = replyReqId || generateReqId("aibot_send_msg");
|
||||
@@ -275,17 +274,61 @@ function startLongConnectionLoop(opts) {
|
||||
wait.reject(err);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把企微智能机器人回调归一成智能体入站结构。
|
||||
*
|
||||
* 2026-11-19 补(真机问题:@BOT 换行带图时正文变空):
|
||||
* - 群聊里图片/文件/视频的独立回调企微不推,@ 带图只会来 mixed(文字+图片);
|
||||
* - 以前只读 body.text,mixed 的正文和图片地址全丢,智能体把空正文当文字去要工单号。
|
||||
* 这里把 mixed 的多段文字拼成 content,把图片地址放进 media(加密 URL、5 分钟过期,
|
||||
* 只用于判断「只有图没有字」,不在这里下载)。
|
||||
* 文件消息官方不给文件名,只有加密 URL,因此群聊文件仍只走会话存档。
|
||||
*/
|
||||
function normalizeInbound(frame) {
|
||||
const body = frame.body || {};
|
||||
const from = body.from || {};
|
||||
const text = (body.text && body.text.content) || "";
|
||||
const msgType = String(body.msgtype || "text");
|
||||
let text = (body.text && body.text.content) || "";
|
||||
const media = {};
|
||||
if (msgType === "mixed") {
|
||||
const items =
|
||||
body.mixed && Array.isArray(body.mixed.msg_item) ? body.mixed.msg_item : [];
|
||||
const texts = [];
|
||||
const images = [];
|
||||
for (const item of items) {
|
||||
if (!item || typeof item !== "object") {
|
||||
continue;
|
||||
}
|
||||
if (item.msgtype === "text" && item.text && item.text.content) {
|
||||
texts.push(String(item.text.content));
|
||||
}
|
||||
if (item.msgtype === "image" && item.image && item.image.url) {
|
||||
images.push(String(item.image.url));
|
||||
}
|
||||
}
|
||||
if (!text && texts.length) {
|
||||
text = texts.join("\n");
|
||||
}
|
||||
if (images.length) {
|
||||
media.image_count = images.length;
|
||||
media.image_urls = images;
|
||||
}
|
||||
} else if (body.image && body.image.url) {
|
||||
media.image_count = 1;
|
||||
media.image_url = String(body.image.url);
|
||||
} else if (body.video && body.video.url) {
|
||||
media.video_url = String(body.video.url);
|
||||
} else if (body.file && body.file.url) {
|
||||
media.file_url = String(body.file.url);
|
||||
}
|
||||
return {
|
||||
sender_id: String(from.userid || "").trim(),
|
||||
message_id: String(body.msgid || (frame.headers && frame.headers.req_id) || "").trim(),
|
||||
content: text,
|
||||
msg_type: String(body.msgtype || "text"),
|
||||
msg_type: msgType,
|
||||
chat_id: String(body.chatid || "").trim(),
|
||||
chat_type: body.chattype === "single" ? "c2c" : "group",
|
||||
media,
|
||||
raw: {
|
||||
source: "aibot",
|
||||
aibot_req_id: frame.headers && frame.headers.req_id,
|
||||
@@ -335,9 +378,6 @@ function startLongConnectionLoop(opts) {
|
||||
if (reqId && chatKey) {
|
||||
state.lastCallback.set(chatKey, reqId);
|
||||
}
|
||||
if (reqId) {
|
||||
state.lastAnyReq = reqId;
|
||||
}
|
||||
const officialBody = Object.assign({}, frame.body || {}, {
|
||||
aibot_direct: true,
|
||||
aibot_req_id: reqId || "",
|
||||
@@ -349,6 +389,8 @@ function startLongConnectionLoop(opts) {
|
||||
content: inbound.content,
|
||||
chat_id: inbound.chat_id,
|
||||
chat_type: inbound.chat_type,
|
||||
// 2026-11-19:mixed 的图片地址等元信息必须一起转,否则智能体只看到空正文。
|
||||
media: inbound.media || {},
|
||||
})
|
||||
: officialBody;
|
||||
if (!payload.sender_id && !payload.from) {
|
||||
|
||||
@@ -39,10 +39,20 @@ test("dimension asterisks stay visible in group markdown", () => {
|
||||
assert.equal(again.body.markdown.content, "体积(CBM)(必填):`1.1*2.1*2.1`");
|
||||
});
|
||||
|
||||
test("reply req id falls back to last inbound when chat map misses", () => {
|
||||
assert.equal(pickReplyReqId({ fromCaller: "cb_1", fromChat: "old", lastAny: "any" }), "cb_1");
|
||||
assert.equal(pickReplyReqId({ fromCaller: "", fromChat: "chat_cb", lastAny: "any" }), "chat_cb");
|
||||
assert.equal(pickReplyReqId({ fromCaller: "", fromChat: "", lastAny: "jeD_msF" }), "jeD_msF");
|
||||
assert.equal(pickReplyReqId({ fromCaller: "", fromChat: "", lastAny: "" }), "");
|
||||
test("reply req id only uses the same chat, never the last inbound from another chat", () => {
|
||||
assert.equal(pickReplyReqId({ fromCaller: "cb_1", fromChat: "old" }), "cb_1");
|
||||
assert.equal(pickReplyReqId({ fromCaller: "", fromChat: "chat_cb" }), "chat_cb");
|
||||
// 2026-11-21 测服事故:没有本群 req_id 时必须主动发言,不能借用别的群 req_id。
|
||||
assert.equal(pickReplyReqId({ fromCaller: "", fromChat: "" }), "");
|
||||
});
|
||||
|
||||
test("proactive message to a chat without its own callback uses aibot_send_msg", () => {
|
||||
const frame = buildGroupMessageFrame({
|
||||
chatId: "wr_land_group",
|
||||
content: "产品响应超时",
|
||||
callbackReqId: pickReplyReqId({ fromCaller: "", fromChat: "" }),
|
||||
});
|
||||
assert.equal(frame.cmd, "aibot_send_msg");
|
||||
assert.equal(frame.body.chatid, "wr_land_group");
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user