dsh-message-gateway 0.1.14 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +29 -0
- package/lib/index.js.map +3 -3
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -5063,6 +5063,30 @@ ${content}` : content;
|
|
|
5063
5063
|
return { ok: false, detail: `platform "${platform}" does not support push` };
|
|
5064
5064
|
}
|
|
5065
5065
|
}
|
|
5066
|
+
/**
|
|
5067
|
+
* 向已配置的 Outbound Webhooks 广播事件(异步投递,失败不阻塞)。
|
|
5068
|
+
*/
|
|
5069
|
+
async broadcastEvent(event, payload) {
|
|
5070
|
+
const webhooks = this.config.outboundWebhooks ?? [];
|
|
5071
|
+
if (webhooks.length === 0) return;
|
|
5072
|
+
const { createHmac: createHmac2 } = await import("node:crypto");
|
|
5073
|
+
const bodyStr = JSON.stringify({ event, timestamp: Date.now(), ...payload });
|
|
5074
|
+
for (const hook of webhooks) {
|
|
5075
|
+
const allowed = hook.events ?? ["*"];
|
|
5076
|
+
if (!allowed.includes("*") && !allowed.includes(event)) continue;
|
|
5077
|
+
void (async () => {
|
|
5078
|
+
try {
|
|
5079
|
+
const headers = { "content-type": "application/json" };
|
|
5080
|
+
if (hook.secret) {
|
|
5081
|
+
headers["x-gateway-signature"] = createHmac2("sha256", hook.secret).update(bodyStr, "utf8").digest("hex");
|
|
5082
|
+
}
|
|
5083
|
+
await fetch(hook.url, { method: "POST", headers, body: bodyStr, signal: AbortSignal.timeout(1e4) });
|
|
5084
|
+
} catch (error) {
|
|
5085
|
+
console.warn("[dsh-message-gateway] outbound webhook post failed", hook.url, String(error));
|
|
5086
|
+
}
|
|
5087
|
+
})();
|
|
5088
|
+
}
|
|
5089
|
+
}
|
|
5066
5090
|
// ==================== Telegram / Discord / QQ / Email ====================
|
|
5067
5091
|
telegram = null;
|
|
5068
5092
|
discord = null;
|
|
@@ -6244,6 +6268,11 @@ var Config = Schema.object({
|
|
|
6244
6268
|
autoStartEmail: Schema.boolean().default(true).description("\u542F\u52A8\u65F6\u81EA\u52A8\u7528\u5DF2\u4FDD\u5B58\u7684 Email \u51ED\u636E\u5EFA\u7ACB\u5E38\u9A7B\u8FDE\u63A5\uFF08IMAP \u8F6E\u8BE2\uFF09"),
|
|
6245
6269
|
groupReply: Schema.boolean().default(true).description("\u662F\u5426\u56DE\u590D\u7FA4\u804A\u6D88\u606F\uFF08false \u65F6\u53EA\u5904\u7406\u5355\u804A\uFF09"),
|
|
6246
6270
|
welcomeReply: Schema.boolean().default(false).description("\u662F\u5426\u5728\u7528\u6237\u5F53\u5929\u9996\u6B21\u8FDB\u5165\u5355\u804A\u65F6\u81EA\u52A8\u53D1\u9001\u6B22\u8FCE\u8BED\uFF08\u9ED8\u8BA4 false \u4FDD\u6301\u514D\u6253\u6270\uFF0C\u8BBE\u4E3A true \u5F00\u542F\uFF09"),
|
|
6271
|
+
outboundWebhooks: Schema.array(Schema.object({
|
|
6272
|
+
url: Schema.string().required().description("\u76EE\u6807 Webhook \u63A5\u6536 URL"),
|
|
6273
|
+
secret: Schema.string().description("\u53EF\u9009 HMAC-SHA256 \u7B7E\u540D\u5BC6\u94A5\uFF08\u5C06\u5728 X-Gateway-Signature \u5934\u9644\u5E26 hex \u7B7E\u540D\uFF09"),
|
|
6274
|
+
events: Schema.array(Schema.string()).default(["*"]).description('\u8BA2\u9605\u7684\u4E8B\u4EF6\u7C7B\u578B\uFF08\u5982 ["message.in", "message.out", "agent.done"]\uFF0C\u9ED8\u8BA4 ["*"]\uFF09')
|
|
6275
|
+
})).default([]).description("Outbound Webhooks \u5916\u90E8\u4E8B\u4EF6\u8BA2\u9605\u5E7F\u64AD\u5217\u8868"),
|
|
6247
6276
|
routes: Schema.array(Schema.object({
|
|
6248
6277
|
id: Schema.string().required().description("\u89C4\u5219 id\uFF08\u552F\u4E00\u6807\u8BC6\uFF09"),
|
|
6249
6278
|
matchPlatform: Schema.string().description("\u5339\u914D\u5E73\u53F0 id\uFF08telegram/discord/qq/wecom-aibot/email/webhook \u7B49\uFF09\uFF1B\u7F3A\u7701=\u5168\u90E8\u5E73\u53F0"),
|