现象:生产货主群机器人发「<店铺名>LSFJY…\n物流单号:SF… 拦截」无任何回信 (ai_thoughts=null、无 outbound 子记录),2026-08-28 起该群 0 回信。 根因:INTERCEPT_GUARD 用裸词「物流」判定物流查询意图,命中了单号标签 「物流单号:」→ 拦截规则被 continue 跳过 → 无规则命中且 aiFallback=false → 静默(不写 thoughts、不建工单)。store 群该格式消息共 275 条,其中 178 条未回信。 修复:判定查询意图前先剔除运单号标签(物流单号 / 物流单 号 / 物 流单号 / 快递单号 / 运单号),标签之外的「物流轨迹 / 查快递 / 到哪」等查询词仍照旧拦截, 客服对话类消息继续静默,不会误建拦截工单。 验证: - script/tmp-check-inbox-intercept-guard.cjs:12/12 通过(含生产群分组可用性断言) - script/tmp-push-inbox-robot-intercept.cjs:本地走真实签名入站链路(/warehouse inbox.push), 用库内真实顺丰运单覆盖纯数字 / SF / YT 三种单号形态 3/3,均建拦截工单 + 通知快递群 + 回信 + 置订单 intercept_status/intercept_time
105 lines
4.7 KiB
JavaScript
105 lines
4.7 KiB
JavaScript
/**
|
||
* 临时校验:拦截规则防误判守卫(INTERCEPT_GUARD)修复效果。
|
||
* 背景:机器人格式 "物流单号:SF123 拦截" 因含"物流"被守卫拦掉 → 规则未命中 → 静默不回信。
|
||
* 用 fake ctx 直接实例化 inbox.rules Service,不连库、不写库。
|
||
* 运行:node script/tmp-check-inbox-intercept-guard.cjs
|
||
*/
|
||
'use strict';
|
||
|
||
const RulesService = require('../app/service/inbox/rules');
|
||
|
||
function buildService(groupType, calls) {
|
||
const svc = Object.create(RulesService.prototype);
|
||
const registry = new Map([
|
||
[ 'interceptWaybill', { groups: [ 'bound:store:after_sales' ] }],
|
||
[ 'cancelIntercept', { groups: [ 'bound:store:after_sales' ] }],
|
||
[ 'queryWeight', { groups: [ 'bound:store:after_sales' ] }],
|
||
]);
|
||
svc.ctx = {
|
||
inboxContext: { group_type: groupType },
|
||
logger: { info() {}, warn() {}, error() {} },
|
||
service: {
|
||
inbox: {
|
||
groups: {
|
||
resolveActiveGroups: () => [ 'bound:store:after_sales' ],
|
||
isFunctionAvailable: def => Array.isArray(def.groups) && def.groups.length > 0,
|
||
},
|
||
functions: {
|
||
registry,
|
||
callFunction: async (fn, params) => {
|
||
calls.push({ fn, params });
|
||
return { success: true, data: { direct_reply: true, message: `MOCK ${fn}` } };
|
||
},
|
||
},
|
||
},
|
||
},
|
||
};
|
||
return svc;
|
||
}
|
||
|
||
const CASES = [
|
||
// [说明, 正文, 期望是否已处理, 期望函数]
|
||
[ '机器人格式-物流单号+拦截', '优禾康官方旗舰店LSFJY202609143442\n物流单号:SF5151786672496 拦截', true, 'interceptWaybill' ],
|
||
[ '机器人格式-单号中间带空格', '罗斯福医疗器械专营店LSFJY202608307192\n物流单 号:SF5117392937919 拦截', true, 'interceptWaybill' ],
|
||
[ '机器人格式-物流二字被空格断开', '优禾康番茄健康监测专卖店LSFJY202609022796\n物 流单号:SF6048940605674 拦截', true, 'interceptWaybill' ],
|
||
[ '机器人格式-快递单号标签', '快递单号:SF5151786672496 拦截', true, 'interceptWaybill' ],
|
||
[ '普通拦截请求', '拦截 SF5151786672496', true, 'interceptWaybill' ],
|
||
[ '取消拦截(长词优先)', '取消拦截 SF5151786672496', true, 'cancelIntercept' ],
|
||
[ '查询物流到哪了(不应拦截)', '这个件拦截的物流到哪了 SF5151786672496', false, null ],
|
||
[ '标签外仍有物流查询词(不应拦截)', '物流单号:SF5151786672496 拦截,顺便查下这个物流到哪了', false, null ],
|
||
[ '查快递(无拦截词)', '帮我查快递 SF5151786672496 到哪了', false, null ],
|
||
[ '客服对话-物流显示签收+拦截有风险', '772077887170843:已登记退回,物流显示签收,已通知站点核实处理,因签收之后的包裹拦截有风险', false, null ],
|
||
[ '客服对话-物流轨迹查询', '麻烦看下这个件拦截了没有,物流轨迹一直没更新 SF5151786672496', false, null ],
|
||
[ '确认语静默', '好的', true, null ],
|
||
];
|
||
|
||
(async () => {
|
||
let pass = 0;
|
||
const fails = [];
|
||
for (const [ desc, text, expectHandled, expectFn ] of CASES) {
|
||
const calls = [];
|
||
const svc = buildService('store', calls);
|
||
const res = await svc.handle(text);
|
||
const handled = !!res.handled;
|
||
const fn = res.fn || null;
|
||
const ok = handled === expectHandled && fn === expectFn;
|
||
if (ok) pass++;
|
||
else fails.push({ desc, expectHandled, expectFn, handled, fn, silent: !!res.silent, calls });
|
||
console.log(
|
||
`${ok ? '✅' : '❌'} ${desc} → handled=${handled} fn=${fn} silent=${!!res.silent} ` +
|
||
`reply=${res.reply ? JSON.stringify(String(res.reply).slice(0, 40)) : '-'}`
|
||
);
|
||
}
|
||
console.log(`\n结果:${pass}/${CASES.length} 通过`);
|
||
if (fails.length > 0) {
|
||
console.log('失败明细:', JSON.stringify(fails, null, 2));
|
||
process.exitCode = 1;
|
||
}
|
||
|
||
// ---- 生产群上下文模拟:真实分组解析 + 函数可用性(groups.js 为纯逻辑,不连库)----
|
||
const GroupsService = require('../app/service/inbox/groups');
|
||
const prodCtx = {
|
||
inboxContext: {
|
||
warehouse_id: 1000028,
|
||
store_id: 1000249,
|
||
group_type: 'store',
|
||
sub_type: 'after_sales',
|
||
group_id: '47357811653@chatroom',
|
||
},
|
||
logger: { info() {}, warn() {}, error() {} },
|
||
};
|
||
const groupsSvc = Object.create(GroupsService.prototype);
|
||
groupsSvc.ctx = prodCtx;
|
||
const active = groupsSvc.resolveActiveGroups();
|
||
const available = groupsSvc.isFunctionAvailable(
|
||
{ groups: [ 'bound:warehouse:customer_service', 'bound:store:after_sales' ] },
|
||
active
|
||
);
|
||
console.log(
|
||
'\n生产群 47357811653@chatroom(store/after_sales/store_id=1000249) ' +
|
||
`activeGroups=${JSON.stringify(active)} interceptWaybill可用=${available}`
|
||
);
|
||
if (!available) process.exitCode = 1;
|
||
})();
|
||
|