467 lines
23 KiB
JavaScript
467 lines
23 KiB
JavaScript
'use strict';
|
||
|
||
/* eslint-disable no-use-before-define */
|
||
/* 规则表/常量按“配置在后、逻辑在前”组织,类方法通过函数声明提升访问,此处禁用声明顺序检查 */
|
||
|
||
const Service = require('egg').Service;
|
||
|
||
/**
|
||
* 站内信关键词规则引擎(主回复路径,替代 AI 推理)。
|
||
*
|
||
* 设计参考 PHP Chat.php 的规则表结构:
|
||
* - 按群类型(store/warehouse/express)维护规则表,顺序即优先级,先命中先执行;
|
||
* - 每条规则:关键词数组 → inbox 函数,命中后从消息中提取运单号/订单号直接调用函数;
|
||
* - 函数返回的模板消息(direct_reply/message)原样回信;
|
||
* - 确认/感谢类短消息、未命中消息默认静默,不触发 AI,节省推理费用;
|
||
* - AI 仅在 config.inbox.aiFallback=true 时作为兜底。
|
||
*/
|
||
class InboxRulesService extends Service {
|
||
|
||
/**
|
||
* 规则引擎主入口:关键词匹配 + 参数提取 + 函数调用。
|
||
*
|
||
* @param {string} content 消息正文。
|
||
* @return {Promise<Object>} 处理结果:
|
||
* - { handled: false }:未命中任何规则(由调用方决定是否 AI 兜底/静默)。
|
||
* - { handled: true, silent: true }:命中静默规则,不回复。
|
||
* - { handled: true, reply: string, fn, params, result, matchedKey, thoughts }:已执行函数并生成回复。
|
||
*/
|
||
async handle(content) {
|
||
const { ctx } = this;
|
||
const text = String(content || '').trim();
|
||
if (!text) return { handled: false };
|
||
|
||
const groupType = String(ctx.inboxContext?.group_type || '').trim();
|
||
const rules = RULE_TABLES[groupType];
|
||
if (!Array.isArray(rules) || rules.length === 0) {
|
||
ctx.logger.info(`[inbox rules] 无规则表 group_type=${groupType || '-'}`);
|
||
return { handled: false };
|
||
}
|
||
|
||
const groupsSvc = ctx.service.inbox.groups;
|
||
const funcSvc = ctx.service.inbox.functions;
|
||
const activeGroups = groupsSvc.resolveActiveGroups();
|
||
|
||
// 收集所有命中规则:命中关键词最长者优先(长词优先)。
|
||
// 相反语义的短词(如“拦截”vs“取消拦截”)不再依赖人工排序,
|
||
// 长词“取消拦截”天然排在短词“拦截”之前,短词不会吞掉长词语义。
|
||
const candidates = [];
|
||
for (const rule of rules) {
|
||
if (rule.any) {
|
||
candidates.push({ rule, key: 'any', keyLen: Infinity });
|
||
continue;
|
||
}
|
||
const hitKey = rule.keys.find(k => text.includes(k));
|
||
if (hitKey) candidates.push({ rule, key: hitKey, keyLen: hitKey.length });
|
||
}
|
||
// 稳定排序:keyLen 相同保持规则表顺序(先定义者优先)
|
||
candidates.sort((a, b) => b.keyLen - a.keyLen);
|
||
|
||
for (const cand of candidates) {
|
||
const rule = cand.rule;
|
||
|
||
// 防误判守卫(如拦截 vs 查询物流)
|
||
if (rule.guard && !rule.guard(text)) {
|
||
ctx.logger.info(`[inbox rules] 规则 ${rule.fn} 未通过防误判守卫: ${text.slice(0, 50)}`);
|
||
continue;
|
||
}
|
||
|
||
// 内置帮助指令
|
||
if (rule.fn === '__help__') {
|
||
const reply = HELP_TEXTS[groupType] || '当前群暂无可用的快捷指令';
|
||
return {
|
||
handled: true, reply, fn: '__help__', params: {}, result: null, matchedKey: 'help',
|
||
thoughts: [{ round: 0, action: 'rule', function: '__help__', params: {}, reason: '帮助指令命中: help', functionResult: null }],
|
||
};
|
||
}
|
||
|
||
// 函数可用性校验(复用群分组权限,防止越权调用)
|
||
const def = funcSvc.registry.get(rule.fn);
|
||
if (!def || !groupsSvc.isFunctionAvailable(def, activeGroups)) {
|
||
ctx.logger.info(
|
||
`[inbox rules] 函数 ${rule.fn} 当前群不可用,跳过 groups=${def ? def.groups.join(',') : '-'} active=${activeGroups.join(',')}`
|
||
);
|
||
continue;
|
||
}
|
||
|
||
// 参数提取
|
||
const params = {};
|
||
if (rule.waybill) {
|
||
const waybills = extractWaybills(text);
|
||
if (waybills.length === 0) {
|
||
if (rule.noWaybillSilent) {
|
||
return { handled: true, silent: true };
|
||
}
|
||
return {
|
||
handled: true,
|
||
reply: rule.tip || '请提供运单号(发送:指令+运单号,多个单号用逗号或空格分隔)',
|
||
fn: rule.fn, params: {}, result: null, matchedKey: rule.keys?.[0],
|
||
thoughts: [{ round: 0, action: 'rule', function: rule.fn, params: {}, reason: '参数不足-引导提示', functionResult: null }],
|
||
};
|
||
}
|
||
// 默认参数名 keyword,个别函数(如 queryReturn)用 waybill_code
|
||
params[rule.paramName || 'keyword'] = waybills.join(',');
|
||
}
|
||
if (rule.order) {
|
||
const orders = extractOrders(text);
|
||
if (orders.length === 0) {
|
||
return {
|
||
handled: true,
|
||
reply: rule.tip || '请提供订单号(发货单号或平台单号)',
|
||
fn: rule.fn, params: {}, result: null, matchedKey: rule.keys?.[0],
|
||
thoughts: [{ round: 0, action: 'rule', function: rule.fn, params: {}, reason: '参数不足-引导提示', functionResult: null }],
|
||
};
|
||
}
|
||
params[rule.paramName || 'keyword'] = orders.join(',');
|
||
}
|
||
if (rule.issueType) params.issue_type = rule.issueType;
|
||
if (rule.express) params.express = rule.express;
|
||
if (rule.expressSubType) {
|
||
const sub = resolveExpressSubType(text);
|
||
if (sub) params.as_sub_type = sub;
|
||
}
|
||
if (rule.expressFromText) {
|
||
const expressName = extractExpressName(text);
|
||
if (!expressName) {
|
||
return {
|
||
handled: true,
|
||
reply: rule.tip || '请指定目标快递(圆通/中通/申通/顺丰/韵达/极兔/邮政/EMS/京东)',
|
||
fn: rule.fn, params: {}, result: null, matchedKey: rule.keys?.[0],
|
||
thoughts: [{ round: 0, action: 'rule', function: rule.fn, params: {}, reason: '参数不足-引导提示', functionResult: null }],
|
||
};
|
||
}
|
||
params.express = expressName;
|
||
}
|
||
if (rule.stockSearch) {
|
||
const kw = stripKeyword(text, rule.keys || []);
|
||
if (!kw) {
|
||
return {
|
||
handled: true,
|
||
reply: rule.tip || '请提供商品名称、编码或条码',
|
||
fn: rule.fn, params: {}, result: null, matchedKey: rule.keys?.[0],
|
||
thoughts: [{ round: 0, action: 'rule', function: rule.fn, params: {}, reason: '参数不足-引导提示', functionResult: null }],
|
||
};
|
||
}
|
||
params.keyword = kw;
|
||
}
|
||
|
||
// 执行函数
|
||
const result = await funcSvc.callFunction(rule.fn, params);
|
||
const reply = this.buildReply(rule.fn, result);
|
||
|
||
const matchedKey = cand.key;
|
||
ctx.logger.info(
|
||
`[inbox rules] HIT fn=${rule.fn} key=${matchedKey} params=${JSON.stringify(params)} success=${!!result.success}`
|
||
);
|
||
|
||
return {
|
||
handled: true,
|
||
fn: rule.fn,
|
||
params,
|
||
result,
|
||
reply,
|
||
matchedKey,
|
||
thoughts: [{
|
||
round: 0,
|
||
action: 'rule',
|
||
function: rule.fn,
|
||
params,
|
||
reason: `关键词规则命中: ${matchedKey}`,
|
||
functionResult: result,
|
||
}],
|
||
};
|
||
}
|
||
|
||
// 确认/感谢类短消息 → 静默(PHP nothing 规则)
|
||
if (SILENT_RE.test(text)) {
|
||
ctx.logger.info(`[inbox rules] 静默规则命中: ${text.slice(0, 50)}`);
|
||
return { handled: true, silent: true };
|
||
}
|
||
|
||
return { handled: false };
|
||
}
|
||
|
||
/**
|
||
* 根据函数执行结果构建回复文本。
|
||
* 优先 direct_reply 模板消息(支持 messages 数组多行回复),其次 data.message,商品搜索做格式化,失败返回错误文案。
|
||
*
|
||
* @param {string} fn 函数名。
|
||
* @param {Object} result callFunction 返回结果。
|
||
* @return {string|string[]|null} 回复文本(数组表示多条消息逐个回复),null 表示无需回复。
|
||
*/
|
||
buildReply(fn, result) {
|
||
if (!result || typeof result !== 'object') return null;
|
||
if (result.success === false) {
|
||
return String(result.error || '操作失败,请联系客服处理');
|
||
}
|
||
const data = result.data || {};
|
||
if (data.direct_reply === true && Array.isArray(data.messages) && data.messages.length > 0) {
|
||
return data.messages.map(m => String(m));
|
||
}
|
||
if (data.direct_reply === true && typeof data.message === 'string' && data.message) {
|
||
return data.message;
|
||
}
|
||
if (typeof data.message === 'string' && data.message) {
|
||
return data.message;
|
||
}
|
||
if (fn === 'searchStock' || fn === 'searchWarehouseStock') {
|
||
return this.formatStock(data);
|
||
}
|
||
return null;
|
||
}
|
||
|
||
/**
|
||
* 商品搜索结果的纯文本格式化。
|
||
* @param {Object} data 函数返回的 data。
|
||
* @return {string} 格式化文本。
|
||
*/
|
||
formatStock(data = {}) {
|
||
const items = Array.isArray(data.items) ? data.items : [];
|
||
if (items.length === 0) {
|
||
return String(data.hint || '未找到匹配商品,请尝试其他关键词');
|
||
}
|
||
const lines = items.slice(0, 10).map((s, i) => {
|
||
const code = s.item_code || '';
|
||
const name = s.item_name || '';
|
||
const available = s.stock_available != null ? s.stock_available : 0;
|
||
const extra = s.prohibited_type ? `(违禁品:${s.prohibited_type})` : '';
|
||
return `${i + 1}. ${code} ${name} 可用库存:${available}${extra}`;
|
||
});
|
||
return `找到 ${items.length} 个商品:\n${lines.join('\n')}`;
|
||
}
|
||
}
|
||
|
||
// ============================ 提取工具 ============================
|
||
|
||
/**
|
||
* 提取运单号(参考 PHP Chat.php getPostNums,结合 Node 运单特征)。
|
||
* 排除:售后工单号(AS开头)、手机号、日期时间戳、纯字母串。
|
||
* @param {string} text 消息正文。
|
||
* @return {string[]} 去重后的运单号列表。
|
||
*/
|
||
function extractWaybills(text) {
|
||
const raw = text.match(/[A-Za-z0-9_-]{10,24}/g) || [];
|
||
return [ ...new Set(raw) ].filter(t => {
|
||
if (/^AS\d+$/i.test(t)) return false; // 售后工单号
|
||
if (/^1\d{10}$/.test(t)) return false; // 手机号
|
||
if (/^\+?86[- ]?1\d{10}$/.test(t)) return false; // 国际区号手机(含/不含 +)
|
||
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; // 日期时间戳
|
||
if (/^[A-Za-z_-]+$/.test(t)) return false; // 纯字母
|
||
return true;
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 提取订单号(发货单/平台单)。
|
||
* 优先 SYS/SO/DD 前缀及字母数字混合号,兜底 12~20 位纯数字。
|
||
* 前缀需独立成词(前不能紧邻字母数字),避免从长字符串中截取尾部
|
||
* (如 NOTEXISTPOSTNUM20260814 误截成 TPOSTNUM20260814)。
|
||
* @param {string} text 消息正文。
|
||
* @return {string[]} 去重后的订单号列表。
|
||
*/
|
||
function extractOrders(text) {
|
||
const raw = text.match(/(?<![A-Za-z0-9])SYS\d{4,}|(?<![A-Za-z0-9])SO[A-Za-z0-9-]{4,}|(?<![A-Za-z0-9])DD[A-Za-z0-9-]{4,}|(?<![A-Za-z0-9])[A-Z]{2,8}-?\d{4,}/g) || [];
|
||
const list = [ ...new Set(raw) ];
|
||
if (list.length > 0) return list;
|
||
const nums = text.match(/(?<!\d)\d{12,20}(?!\d)/g) || [];
|
||
return [ ...new Set(nums) ].filter(t => !/^1\d{10}$/.test(t));
|
||
}
|
||
|
||
/** 改快递规则支持的目标快递名(长名在前,优先提取完整名称,避免“中通快运”被短名截断) */
|
||
const EXPRESS_NAMES = [ '中通快运', '中通快递', '极兔速递', '京东快递', '圆通快递', '申通快递', '顺丰速运', '韵达快递', '邮政小包', '圆通', '中通', '申通', '顺丰', '韵达', '极兔', '邮政', 'EMS', '京东', '德邦' ];
|
||
|
||
/**
|
||
* 快递反馈 → 售后子类型映射(长词优先,避免“核实签收”被“签收”截断)。
|
||
* 未命中保持默认 logistics_issue(物流异常)。
|
||
*/
|
||
const EXPRESS_SUB_TYPE_RULES = [
|
||
{ keys: [ '核实签收', '签收核实', '已签收', '签收' ], sub: 'verify_delivery' },
|
||
{ keys: [ '破损', '坏了', '破损件' ], sub: 'damage' },
|
||
{ keys: [ '少发', '漏发', '发少' ], sub: 'missing_item' },
|
||
{ keys: [ '改地址', '地址更改', '改址' ], sub: 'change_address' },
|
||
{ keys: [ '换快递', '改快递' ], sub: 'change_carrier' },
|
||
{ keys: [ '催件', '催派', '催促' ], sub: 'urge' },
|
||
{ keys: [ '发货延迟', '延迟发货', '催发货' ], sub: 'delivery_delay' },
|
||
{ keys: [ '拒收' ], sub: 'rejected' },
|
||
];
|
||
|
||
/**
|
||
* 从快递反馈文本推断售后子类型(长词优先)。
|
||
* @param {string} text 消息正文。
|
||
* @return {string|null} 售后子类型,未命中返回 null(由函数默认 logistics_issue)。
|
||
*/
|
||
function resolveExpressSubType(text) {
|
||
let best = null;
|
||
let bestLen = 0;
|
||
for (const item of EXPRESS_SUB_TYPE_RULES) {
|
||
for (const k of item.keys) {
|
||
if (text.includes(k) && k.length > bestLen) {
|
||
best = item.sub;
|
||
bestLen = k.length;
|
||
}
|
||
}
|
||
}
|
||
return best;
|
||
}
|
||
|
||
/**
|
||
* 从消息文本中解析目标快递名称(通用“改快递/换快递”规则用)。
|
||
* @param {string} text 消息正文。
|
||
* @return {string|null} 快递名称,未命中返回 null。
|
||
*/
|
||
function extractExpressName(text) {
|
||
const lower = String(text || '').toLowerCase();
|
||
return EXPRESS_NAMES.find(name => lower.includes(name.toLowerCase())) || null;
|
||
}
|
||
|
||
/**
|
||
* 去除命中的关键词,取剩余文本作为查询词(查库存场景)。
|
||
* @param {string} text 消息正文。
|
||
* @param {string[]} keys 命中关键词列表。
|
||
* @return {string} 剩余文本。
|
||
*/
|
||
function stripKeyword(text, keys) {
|
||
let t = String(text || '');
|
||
for (const k of keys) {
|
||
t = t.split(k).join(' ');
|
||
}
|
||
return t.replace(/\s+/g, ' ').trim();
|
||
}
|
||
|
||
/** 确认/感谢类短消息 → 静默 */
|
||
const SILENT_RE = /^(好|好的|好的呢|好嘞|嗯|嗯嗯|哦|哦哦|ok|okay|收到|谢谢|感谢|谢谢啦|谢了|好了|可以|行|行了|对啊|是的|对|知道了|明白|了解了|1)\s*[!!。.,~~👍🙏❤️]*$/i;
|
||
|
||
// ============================ 规则表(顺序即优先级) ============================
|
||
|
||
/**
|
||
* 拦截类规则的防误判守卫:询问物流进度/查快递等不是拦截请求,
|
||
* 取消/撤销类语义属于 cancelIntercept(双保险,长词优先已能保证)
|
||
* @param {string} t 消息正文
|
||
* @return {boolean} 是否允许命中拦截规则
|
||
*/
|
||
const INTERCEPT_GUARD = t => !/(到哪|在哪|哪里|快递到|物流|轨迹|查单|查快递|查物流|到哪里|取消拦截|撤销拦截|解除拦截|不拦截|不用拦截)/.test(t);
|
||
|
||
/** 货主群(store) */
|
||
const STORE_RULES = [
|
||
{ keys: [ '取消拦截', '撤销拦截', '解除拦截', '不拦截', '不用拦截' ], fn: 'cancelIntercept', waybill: true,
|
||
tip: '如需取消拦截,发送:取消拦截+运单号(多个单号用逗号或空格分隔)\n例:取消拦截 SF123,SF456' },
|
||
{ keys: [ '拦截', '追回', '召回' ], fn: 'interceptWaybill', waybill: true, guard: INTERCEPT_GUARD,
|
||
tip: '如需拦截运单,发送:拦截+运单号(多个单号用逗号或空格分隔)\n例:拦截 SF123,SF456' },
|
||
{ keys: [ '揽收', '上门取件', '退货取件', '让快递来拿' ], fn: 'requestPickup', waybill: true,
|
||
tip: '如需安排上门揽收,发送:揽收+运单号\n例:揽收 SF123' },
|
||
{ keys: [ '少发', '发少' ], fn: 'handleStoreFeedback', issueType: 'missing', waybill: true,
|
||
tip: '如需反馈少发,发送:少发+运单号\n例:少发 SF123' },
|
||
{ keys: [ '重量', '查重', '核实重量', '核重', '称重' ], fn: 'queryWeight', waybill: true,
|
||
tip: '如需查询库内称重,发送:称重+运单号\n例:称重 SF123' },
|
||
{ keys: [ '错发', '发错' ], fn: 'handleStoreFeedback', issueType: 'wrong', waybill: true,
|
||
tip: '如需反馈错发,发送:错发+运单号\n例:错发 SF123' },
|
||
{ keys: [ '破损', '坏了' ], fn: 'handleStoreFeedback', issueType: 'damaged', waybill: true,
|
||
tip: '如需反馈破损,发送:破损+运单号\n例:破损 SF123' },
|
||
{ keys: [ '多发', '发多' ], fn: 'handleStoreFeedback', issueType: 'multiple', waybill: true,
|
||
tip: '如需反馈多发,发送:多发+运单号\n例:多发 SF123' },
|
||
{ keys: [ '改地址', '改电话', '改联系人', '改收件人', '地址更改', '改手机' ], fn: 'changeAddr', issueType: 'addr', waybill: true,
|
||
tip: '如需修改地址,发送:改地址+运单号\n例:改地址 SF123' },
|
||
// 注意顺序:催退回/催促退回 必须在 催件/催促 之前("催促退回"含"催促")
|
||
{ keys: [ '催退回', '催促退回' ], fn: 'changeAddr', issueType: 'return', waybill: true,
|
||
tip: '如需催退回,发送:催退回+运单号\n例:催退回 SF123' },
|
||
{ keys: [ '催件', '催派', '催促', '尽快安排派送', '未中转', '物流停滞' ], fn: 'changeAddr', issueType: 'urge', waybill: true,
|
||
tip: '如需催件,发送:催件+运单号\n例:催件 SF123' },
|
||
{ keys: [ '查退回', '是否已退回' ], fn: 'queryReturn', waybill: true, paramName: 'waybill_code',
|
||
tip: '如需查退回,发送:查退回+运单号\n例:查退回 SF123' },
|
||
{ keys: [ '退回', '拒收' ], fn: 'queryReturn', waybill: true, paramName: 'waybill_code',
|
||
tip: '如需查退回,发送:查退回+运单号\n例:查退回 SF123' },
|
||
{ keys: [ '核实签收', '未收到', '是否发出', '是否已经发货', '没有找到快递' ], fn: 'weishoudao', waybill: true,
|
||
tip: '如需核实签收,发送:核实签收+运单号\n例:核实签收 SF123' },
|
||
{ keys: [ '出单', '打单', '打印单', '催发货', '分配快递号' ], fn: 'createPostnum', order: true,
|
||
tip: '如需出单/分配快递号,发送:出单+订单号\n例:出单 SYS2026010100001' },
|
||
// 通用格式:改快递+订单号+快递名(放在固定“改圆通”等规则之前,两者关键词互不冲突)
|
||
{ keys: [ '改快递', '换快递' ], fn: 'changeExpress', expressFromText: true, order: true,
|
||
tip: '如需改快递,发送:改快递+订单号+快递名称\n例:改快递 SYS2026010100001 圆通' },
|
||
{ keys: [ '改圆通' ], fn: 'changeExpress', express: '圆通', order: true,
|
||
tip: '如需改快递,发送:改圆通+订单号\n例:改圆通 SYS2026010100001' },
|
||
{ keys: [ '改中通' ], fn: 'changeExpress', express: '中通', order: true,
|
||
tip: '如需改快递,发送:改中通+订单号' },
|
||
{ keys: [ '改申通' ], fn: 'changeExpress', express: '申通', order: true,
|
||
tip: '如需改快递,发送:改申通+订单号' },
|
||
{ keys: [ '改极兔' ], fn: 'changeExpress', express: '极兔', order: true,
|
||
tip: '如需改快递,发送:改极兔+订单号' },
|
||
{ keys: [ '改韵达' ], fn: 'changeExpress', express: '韵达', order: true,
|
||
tip: '如需改快递,发送:改韵达+订单号' },
|
||
{ keys: [ '改顺丰' ], fn: 'changeExpress', express: '顺丰', order: true,
|
||
tip: '如需改快递,发送:改顺丰+订单号' },
|
||
{ keys: [ '改邮政' ], fn: 'changeExpress', express: '邮政', order: true,
|
||
tip: '如需改快递,发送:改邮政+订单号' },
|
||
{ keys: [ '改EMS', '改ems' ], fn: 'changeExpress', express: 'EMS', order: true,
|
||
tip: '如需改快递,发送:改EMS+订单号' },
|
||
{ keys: [ '改京东' ], fn: 'changeExpress', express: '京东', order: true,
|
||
tip: '如需改快递,发送:改京东+订单号' },
|
||
{ keys: [ '仓库地址', '退货地址', '退件地址', '寄回地址', '收货地址' ], fn: 'queryWarehouseAddress' },
|
||
{ keys: [ '打包视频', '装箱视频' ], fn: 'queryPackVideo', waybill: true,
|
||
tip: '如需查询打包视频,发送:打包视频+运单号\n例:打包视频 SF123' },
|
||
{ keys: [ '查库存' ], fn: 'searchStock', stockSearch: true,
|
||
tip: '如需查库存,发送:查库存+商品名称/编码/条码' },
|
||
{ keys: [ 'help', '指令', '帮助' ], fn: '__help__' },
|
||
];
|
||
|
||
/** 仓库内部群(warehouse,客服子类型可用的函数较多,不可用函数自动跳过) */
|
||
const WAREHOUSE_RULES = [
|
||
{ keys: [ '取消拦截', '撤销拦截', '解除拦截', '不拦截', '不用拦截' ], fn: 'cancelIntercept', waybill: true,
|
||
tip: '如需取消拦截,发送:取消拦截+运单号' },
|
||
{ keys: [ '拦截', '追回', '召回' ], fn: 'interceptWaybill', waybill: true, guard: INTERCEPT_GUARD,
|
||
tip: '如需拦截运单,发送:拦截+运单号' },
|
||
{ keys: [ '揽收', '上门取件' ], fn: 'requestPickup', waybill: true,
|
||
tip: '如需安排上门揽收,发送:揽收+运单号' },
|
||
{ keys: [ '查退回', '是否已退回' ], fn: 'queryReturn', waybill: true, paramName: 'waybill_code',
|
||
tip: '如需查退回,发送:查退回+运单号' },
|
||
{ keys: [ '重量', '查重', '核实重量', '核重', '称重' ], fn: 'queryWeight', waybill: true,
|
||
tip: '如需查询库内称重,发送:称重+运单号' },
|
||
{ keys: [ '打包视频', '装箱视频' ], fn: 'queryPackVideo', waybill: true,
|
||
tip: '如需查询打包视频,发送:打包视频+运单号' },
|
||
{ keys: [ '仓库地址', '退货地址', '退件地址', '寄回地址', '收货地址' ], fn: 'queryWarehouseAddress' },
|
||
{ keys: [ '查库存' ], fn: 'searchWarehouseStock', stockSearch: true,
|
||
tip: '如需查库存,发送:查库存+商品名称/编码/条码' },
|
||
{ keys: [ 'help', '指令', '帮助' ], fn: '__help__' },
|
||
];
|
||
|
||
/** 快递售后群(express)规则表:消息含运单号即按反馈处理(按关键词推断子类型),无运单号静默 */
|
||
const EXPRESS_RULES = [
|
||
{ any: true, fn: 'handleExpressFeedback', waybill: true, noWaybillSilent: true, expressSubType: true },
|
||
];
|
||
|
||
/** 规则表:按群类型选择 */
|
||
const RULE_TABLES = {
|
||
store: STORE_RULES,
|
||
warehouse: WAREHOUSE_RULES,
|
||
express: EXPRESS_RULES,
|
||
};
|
||
|
||
// ============================ 帮助文本 ============================
|
||
|
||
const HELP_TEXTS = {
|
||
store: '当前群支持以下指令(发送:指令+单号,多个单号用逗号或空格分隔):\n'
|
||
+ '· 拦截+运单号 / 取消拦截+运单号\n'
|
||
+ '· 揽收+运单号\n'
|
||
+ '· 催件+运单号 / 催退回+运单号\n'
|
||
+ '· 改地址+运单号\n'
|
||
+ '· 称重+运单号 / 查退回+运单号 / 核实签收+运单号\n'
|
||
+ '· 打包视频+运单号\n'
|
||
+ '· 少发/错发/破损/多发+运单号\n'
|
||
+ '· 出单+订单号\n'
|
||
+ '· 改圆通/改中通/改申通/改顺丰/改韵达/改极兔/改邮政/改EMS/改京东+订单号\n'
|
||
+ '· 仓库地址\n'
|
||
+ '· 查库存+商品名称或条码',
|
||
warehouse: '当前群支持以下指令:\n'
|
||
+ '· 拦截+运单号 / 取消拦截+运单号\n'
|
||
+ '· 揽收+运单号\n'
|
||
+ '· 查退回+运单号 / 称重+运单号\n'
|
||
+ '· 打包视频+运单号\n'
|
||
+ '· 仓库地址\n'
|
||
+ '· 查库存+商品名称或条码',
|
||
express: '发送运单号+处理情况,系统将自动记录并回信货主群。',
|
||
};
|
||
|
||
module.exports = InboxRulesService;
|