W1-W3 实现企业微信个人应用消息通知
这个提交包含在:
@@ -39,7 +39,40 @@ function buildNotificationMessage(channel, payload) {
|
||||
};
|
||||
}
|
||||
|
||||
async function sendInstantMessageByChannel({ config, channel, payload }) {
|
||||
function uniqStrings(values) {
|
||||
return Array.from(
|
||||
new Set(
|
||||
(values ?? [])
|
||||
.map((value) => String(value ?? '').trim())
|
||||
.filter(Boolean),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
async function resolveRecipientExternalUserIds({ prisma, payload }) {
|
||||
const explicitExternalUserIds = uniqStrings(payload?.recipientExternalUserIds);
|
||||
if (explicitExternalUserIds.length) {
|
||||
return explicitExternalUserIds;
|
||||
}
|
||||
|
||||
const employeeIds = uniqStrings(payload?.recipientEmployeeIds);
|
||||
if (!prisma?.wecomIdentityBinding?.findMany || !employeeIds.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const bindings = await prisma.wecomIdentityBinding.findMany({
|
||||
where: {
|
||||
employee_id: { in: employeeIds },
|
||||
},
|
||||
select: {
|
||||
external_user_id: true,
|
||||
},
|
||||
});
|
||||
|
||||
return uniqStrings(bindings.map((binding) => binding.external_user_id));
|
||||
}
|
||||
|
||||
async function sendInstantMessageByChannel({ config, channel, payload, prisma }) {
|
||||
const normalizedChannelType = normalizeChannelType(channel?.channel_type ?? payload?.channelType ?? '');
|
||||
|
||||
if (!config?.imNotifierEnabled) {
|
||||
@@ -91,11 +124,24 @@ async function sendInstantMessageByChannel({ config, channel, payload }) {
|
||||
}
|
||||
|
||||
const message = buildNotificationMessage(channel, payload);
|
||||
return sendWecomMessage({ config, channel, message });
|
||||
const configJson = channel?.config_json && typeof channel.config_json === 'object' ? channel.config_json : {};
|
||||
const mode = String(configJson.mode ?? 'mock').trim() || 'mock';
|
||||
const recipientExternalUserIds =
|
||||
mode === 'wecom_app_message'
|
||||
? await resolveRecipientExternalUserIds({ prisma, payload })
|
||||
: [];
|
||||
|
||||
return sendWecomMessage({
|
||||
config,
|
||||
channel,
|
||||
message,
|
||||
recipientExternalUserIds,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
applyTemplate,
|
||||
buildNotificationMessage,
|
||||
resolveRecipientExternalUserIds,
|
||||
sendInstantMessageByChannel,
|
||||
};
|
||||
|
||||
在新工单中引用
屏蔽一个用户