feat: 完成P6-P8后端能力与P9路由重构(V1-V2,D1,D3,B1-B2,B4,I1-I4,P9A2-P9A3)

这个提交包含在:
2026-02-10 11:28:28 +08:00
父节点 bec21e1b38
当前提交 6bc09f557b
共修改 33 个文件,包含 3467 行新增和 13 行删除
@@ -0,0 +1,75 @@
const { dispatchOutboxEvent } = require("../integrations/dispatcher");
function applyTemplate(template, context) {
if (typeof template !== "string") {
return "";
}
return template.replace(/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/g, (_, key) => {
const value = context[key];
return value == null ? "" : String(value);
});
}
function buildNotificationMessage(channel, payload) {
const context = {
title: String(payload?.title ?? "系统通知").slice(0, 200),
body: String(payload?.body ?? "").slice(0, 2000),
targetType: payload?.targetType ?? "",
targetId: payload?.targetId ?? "",
};
const template =
channel?.template_json && typeof channel.template_json === "object"
? channel.template_json
: null;
const templatedTitle = template?.title ? applyTemplate(template.title, context) : "";
const templatedBody = template?.body ? applyTemplate(template.body, context) : "";
return {
title: (templatedTitle || context.title).slice(0, 200),
body: (templatedBody || context.body).slice(0, 2000),
targetType: context.targetType || null,
targetId: context.targetId || null,
};
}
async function sendInstantMessageByChannel({ config, channel, payload }) {
if (!config.imNotifierEnabled) {
return {
ok: false,
code: "im_notifier_disabled",
message: "IM notifier disabled",
};
}
if (!channel?.enabled) {
return {
ok: false,
code: "channel_disabled",
message: "notification channel disabled",
};
}
const message = buildNotificationMessage(channel, payload);
const result = await dispatchOutboxEvent({
config,
eventType: "notification.im",
payload: {
channelType: channel.channel_type,
channelName: channel.name,
message,
},
});
return {
ok: true,
code: result.code,
response: result.response,
};
}
module.exports = {
sendInstantMessageByChannel,
};