问题:wms_inbox_group.ext_data.source 与群ID格式(@chatroom=wx / 纯数字=qiwe)不符时, 出站回执/通知会把错误渠道原样透传给桥接,投递到错误渠道(qiwe offline 503)而丢失。 生产实测错配出站记录 4018 条(2026-08-15 20:48 ~ 09-14 15:23),涉及 11 个群。 - 新增 app/lib/inbox_channel.js:resolveChannelSource / normalizeExtDataSource - processor.writeOutboundReply:回执落库与回调体统一使用校正后的 ext_data,不一致时打 warn - processor._loadGroupInfo:ext_data 写回群配置前先按群ID校正 - systems/warehouseNotify.pushSystemMessage:sys:notice 链路同样校正 - 新增 script/fix-inbox-group-channel.cjs:存量修复脚本(默认 dry-run,--apply 写入, --messages 连消息表一起修,写入前自动备份到 temp/,幂等)
55 lines
1.7 KiB
JavaScript
55 lines
1.7 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 站内信 IM 渠道来源工具。
|
||
*
|
||
* 群ID 格式与渠道来源一一对应(生产 11 万+ 入站消息 100% 满足该对应关系):
|
||
* - `xxx@chatroom` 结尾 → wx(个人微信)
|
||
* - 纯数字(如 10845468709699144)→ qiwe(企业微信)
|
||
*
|
||
* ext_data.source 决定回执/通知透传给哪个桥接渠道;一旦与群ID格式不符,
|
||
* 回执会被投递到错误渠道(典型现象:wx 群用 qiwe 渠道投递 → "qiwe offline" 503)。
|
||
*/
|
||
|
||
/** 个人微信群ID 后缀 */
|
||
const WX_GROUP_ID_SUFFIX = '@chatroom';
|
||
|
||
/**
|
||
* 按群ID格式推导渠道来源。
|
||
* @param {string} groupId 外部群ID。
|
||
* @return {string|null} wx / qiwe;无法判定时返回 null。
|
||
*/
|
||
function resolveChannelSource(groupId) {
|
||
const id = String(groupId || '').trim();
|
||
if (!id) return null;
|
||
if (id.endsWith(WX_GROUP_ID_SUFFIX)) return 'wx';
|
||
if (/^\d+$/.test(id)) return 'qiwe';
|
||
return null;
|
||
}
|
||
|
||
/**
|
||
* 按群ID格式校正 ext_data.source(不修改入参)。
|
||
* 仅在 ext_data 已带 source 且与群ID格式不符时返回新对象;
|
||
* 无 ext_data / 无 source / 群ID无法判定 / 已一致时原样返回。
|
||
* @param {string} groupId 外部群ID。
|
||
* @param {Object|null} extData 原始透传数据。
|
||
* @return {Object|null} 校正后的透传数据。
|
||
*/
|
||
function normalizeExtDataSource(groupId, extData) {
|
||
if (!extData || typeof extData !== 'object' || Array.isArray(extData)) {
|
||
return extData || null;
|
||
}
|
||
const expected = resolveChannelSource(groupId);
|
||
const current = extData.source;
|
||
if (!expected || !current || current === expected) {
|
||
return extData;
|
||
}
|
||
return { ...extData, source: expected };
|
||
}
|
||
|
||
module.exports = {
|
||
WX_GROUP_ID_SUFFIX,
|
||
resolveChannelSource,
|
||
normalizeExtDataSource,
|
||
};
|