From 38562c3103ffde162bd1608458f403101a5be68a Mon Sep 17 00:00:00 2001 From: liufumingren Date: Tue, 15 Sep 2026 13:47:01 +0800 Subject: [PATCH] =?UTF-8?q?fix(inbox):=20=E4=BF=AE=E6=AD=A3=E8=BF=90?= =?UTF-8?q?=E5=8D=95=E5=8F=B7=E6=8F=90=E5=8F=96=E6=8A=8A=2014=20=E4=BD=8D?= =?UTF-8?q?=E8=BF=90=E5=8D=95=E5=8F=B7=E5=BD=93=E6=97=A5=E6=9C=9F=E6=88=B3?= =?UTF-8?q?=E5=89=94=E9=99=A4=E5=AF=BC=E8=87=B4=E5=8F=AA=E5=9B=9E=E5=BC=95?= =?UTF-8?q?=E5=AF=BC=E8=AF=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现象:生产货主群机器人发「79140215263762 改地址 广东省广州市番禺区…收件人:王小姐19875119016」, 群里只回了「如需修改地址,发送:改地址+运单号」引导语;ai_thoughts 为 params={} + reason=参数不足-引导提示 → 改地址诉求没建工单、也没转发快递群。 根因:extractWaybills 的日期时间戳过滤正则 /^\d{4}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{4,}$/ 年份不限, 把 79140215263762 读成 7914-02-15 而剔除(该运单实际存在:中通快递 ZTO、 store 1000180、order 577016)。生产 wms_order_express 中有 7627 条运单会被该正则误杀 (中通 769…/791…/736…/790…、韵达 321…/319… 等 14 位号)。 修复:日期戳判定限定年份为 19xx/20xx(/^(19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{4,}$/), 真实日期戳(如 20260914201201)仍被过滤,手机号/座机/售后单号等过滤保持不变; 改动只放宽过滤,不存在回归面。 验证: - script/tmp-check-inbox-intercept-guard.cjs:15/15 通过(新增 14 位中通单号应被提取、 11 位手机号仍过滤、日期戳仍过滤 3 例) - script/tmp-push-inbox-robot-intercept.cjs:新增 INBOX_CONTENT 自定义正文模式; 本地走真实签名入站链路复现生产原文 → 工单 AS20260915000001(change_address/pending, 描述含原文)+ 回信「运单79140215263762修改地址已经登记,稍后客服将人工跟进」 --- app/service/inbox/rules.js | 4 +++- script/tmp-check-inbox-intercept-guard.cjs | 22 ++++++++++++++++---- script/tmp-push-inbox-robot-intercept.cjs | 24 ++++++++++++++-------- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/app/service/inbox/rules.js b/app/service/inbox/rules.js index 033e529..a965c6f 100644 --- a/app/service/inbox/rules.js +++ b/app/service/inbox/rules.js @@ -248,7 +248,9 @@ function extractWaybills(text) { if (/^\d{3,4}-\d{7,8}$/.test(t)) return false; // 座机带横线(020-12345678) if (/^0\d{9,11}$/.test(t)) return false; // 0开头座机/服务号(02012345678) if (/^400\d{7}$/.test(t)) return false; // 400 服务电话 - if (/^\d{4}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{4,}$/.test(t)) return false; // 日期时间戳 + // 日期时间戳(如 20260914201201):年份限定 19xx/20xx, + // 否则 14 位运单号(如中通 79140215263762 → 被误读成 7914-02-15)会被当日期戳剔除 + if (/^(19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{4,}$/.test(t)) return false; if (/^[A-Za-z_-]+$/.test(t)) return false; // 纯字母 return true; }); diff --git a/script/tmp-check-inbox-intercept-guard.cjs b/script/tmp-check-inbox-intercept-guard.cjs index 4975cd7..04040b5 100644 --- a/script/tmp-check-inbox-intercept-guard.cjs +++ b/script/tmp-check-inbox-intercept-guard.cjs @@ -14,6 +14,7 @@ function buildService(groupType, calls) { [ 'interceptWaybill', { groups: [ 'bound:store:after_sales' ] }], [ 'cancelIntercept', { groups: [ 'bound:store:after_sales' ] }], [ 'queryWeight', { groups: [ 'bound:store:after_sales' ] }], + [ 'changeAddr', { groups: [ 'bound:store:after_sales' ] }], ]); svc.ctx = { inboxContext: { group_type: groupType }, @@ -38,7 +39,7 @@ function buildService(groupType, calls) { } const CASES = [ - // [说明, 正文, 期望是否已处理, 期望函数] + // [说明, 正文, 期望是否已处理, 期望函数, 期望提取到的运单号(可选,'' 表示应为空)] [ '机器人格式-物流单号+拦截', '优禾康官方旗舰店LSFJY202609143442\n物流单号:SF5151786672496 拦截', true, 'interceptWaybill' ], [ '机器人格式-单号中间带空格', '罗斯福医疗器械专营店LSFJY202608307192\n物流单 号:SF5117392937919 拦截', true, 'interceptWaybill' ], [ '机器人格式-物流二字被空格断开', '优禾康番茄健康监测专卖店LSFJY202609022796\n物 流单号:SF6048940605674 拦截', true, 'interceptWaybill' ], @@ -51,22 +52,35 @@ const CASES = [ [ '客服对话-物流显示签收+拦截有风险', '772077887170843:已登记退回,物流显示签收,已通知站点核实处理,因签收之后的包裹拦截有风险', false, null ], [ '客服对话-物流轨迹查询', '麻烦看下这个件拦截了没有,物流轨迹一直没更新 SF5151786672496', false, null ], [ '确认语静默', '好的', true, null ], + // 2026-09-15 回归:14 位纯数字运单号被“日期时间戳”过滤器误杀,规则只能回引导语 + [ '改地址+14位中通运单号(不应被日期戳过滤)', + '79140215263762 改地址 广东省广州市番禺区洛浦街道西三村友谊路1号菜鸟站(不打电话)收件人:王小姐19875119016', + true, 'changeAddr', '79140215263762' ], + [ '改地址+截断的11位手机号仍应被过滤(保留原行为)', + '改地址 19875119016', true, 'changeAddr', '' ], + [ '日期时间戳仍应被过滤(保留原行为)', + '改地址 20260914201201', true, 'changeAddr', '' ], ]; (async () => { let pass = 0; const fails = []; - for (const [ desc, text, expectHandled, expectFn ] of CASES) { + for (const [ desc, text, expectHandled, expectFn, expectKeyword ] 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; + const keyword = res.params && res.params.keyword != null ? String(res.params.keyword) : ''; + let ok = handled === expectHandled && fn === expectFn; + if (ok && expectKeyword !== undefined) { + ok = expectKeyword === '' ? keyword === '' : keyword.includes(expectKeyword); + } if (ok) pass++; - else fails.push({ desc, expectHandled, expectFn, handled, fn, silent: !!res.silent, calls }); + else fails.push({ desc, expectHandled, expectFn, expectKeyword, handled, fn, keyword, silent: !!res.silent, calls }); console.log( `${ok ? '✅' : '❌'} ${desc} → handled=${handled} fn=${fn} silent=${!!res.silent} ` + + `keyword=${JSON.stringify(keyword)} ` + `reply=${res.reply ? JSON.stringify(String(res.reply).slice(0, 40)) : '-'}` ); } diff --git a/script/tmp-push-inbox-robot-intercept.cjs b/script/tmp-push-inbox-robot-intercept.cjs index 5f4140d..29b2932 100644 --- a/script/tmp-push-inbox-robot-intercept.cjs +++ b/script/tmp-push-inbox-robot-intercept.cjs @@ -216,16 +216,24 @@ async function collectSideEffects(conn, waybills) { console.log(`目标服务: ${BASE_URL} 应用: ${app.self_app_key} (warehouse ${app.warehouse_id})`); console.log(`测试群: ${GROUP.group_name} / ${GROUP.group_id} 发送人: ${GROUP.user_name}\n`); - const cases = await findSfCases(conn, CASE_LIMIT); - if (cases.length === 0) { - console.log('❌ 本地库没有可用的未拦截顺丰运单样本'); - await conn.end(); - return; + // 支持临时指定正文(INBOX_CONTENT=...),用于其它规则的端到端复现;不指定则自动挑顺丰运单 + const adhoc = String(process.env.INBOX_CONTENT || '').trim(); + let cases; + if (adhoc) { + cases = [{ tag: 'X', waybill: '-', desc: '自定义正文(INBOX_CONTENT)', content: adhoc }]; + console.log('使用自定义正文(INBOX_CONTENT)'); + } else { + cases = await findSfCases(conn, CASE_LIMIT); + if (cases.length === 0) { + console.log('❌ 本地库没有可用的未拦截顺丰运单样本'); + await conn.end(); + return; + } + console.log(`自动挑选到 ${cases.length} 个真实顺丰运单样本(按运单号形态去重):`); + for (const c of cases) console.log(` - ${c.desc}`); } - console.log(`自动挑选到 ${cases.length} 个真实顺丰运单样本(按运单号形态去重):`); - for (const c of cases) console.log(` - ${c.desc}`); - const waybills = cases.map(c => c.waybill); + const waybills = cases.map(c => c.waybill).filter(code => code && code !== '-'); const results = []; for (const item of cases) {