@mocrane/wecom 2026.2.5 → 2026.3.4
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/LICENSE +4 -18
- package/README.md +572 -0
- package/assets/01.bot-add.png +0 -0
- package/assets/01.bot-setp2.png +0 -0
- package/assets/01.image.jpg +0 -0
- package/assets/02.agent.add.png +0 -0
- package/assets/02.agent.api-set.png +0 -0
- package/assets/02.image.jpg +0 -0
- package/assets/03.agent.page.png +0 -0
- package/assets/03.bot.page.png +0 -0
- package/assets/link-me.jpg +0 -0
- package/assets/register.png +0 -0
- package/changelog/v2.2.28.md +70 -0
- package/changelog/v2.3.2.md +28 -0
- package/changelog/v2.3.4.md +20 -0
- package/index.ts +11 -3
- package/package.json +4 -2
- package/src/accounts.ts +17 -55
- package/src/agent/api-client.ts +84 -37
- package/src/agent/api-client.upload.test.ts +110 -0
- package/src/agent/handler.event-filter.test.ts +50 -0
- package/src/agent/handler.ts +166 -143
- package/src/channel.config.test.ts +147 -0
- package/src/channel.lifecycle.test.ts +252 -0
- package/src/channel.ts +95 -140
- package/src/config/accounts.resolve.test.ts +38 -0
- package/src/config/accounts.ts +257 -22
- package/src/config/index.ts +6 -0
- package/src/config/network.ts +9 -5
- package/src/config/routing.test.ts +88 -0
- package/src/config/routing.ts +26 -0
- package/src/config/schema.ts +52 -4
- package/src/config-schema.ts +5 -41
- package/src/dynamic-agent.account-scope.test.ts +17 -0
- package/src/dynamic-agent.ts +178 -0
- package/src/gateway-monitor.ts +238 -0
- package/src/http.ts +16 -2
- package/src/media.test.ts +28 -1
- package/src/media.ts +59 -1
- package/src/monitor/state.queue.test.ts +1 -1
- package/src/monitor/state.ts +1 -1
- package/src/monitor/types.ts +1 -1
- package/src/monitor.active.test.ts +15 -9
- package/src/monitor.inbound-filter.test.ts +63 -0
- package/src/monitor.integration.test.ts +4 -2
- package/src/monitor.ts +988 -125
- package/src/monitor.webhook.test.ts +381 -3
- package/src/onboarding.ts +229 -53
- package/src/outbound.test.ts +130 -0
- package/src/outbound.ts +44 -9
- package/src/shared/command-auth.ts +4 -2
- package/src/shared/xml-parser.test.ts +21 -1
- package/src/shared/xml-parser.ts +18 -0
- package/src/types/account.ts +43 -14
- package/src/types/config.ts +51 -2
- package/src/types/constants.ts +7 -3
- package/src/types/index.ts +3 -0
- package/src/types.ts +29 -147
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { shouldProcessBotInboundMessage } from "./monitor.js";
|
|
4
|
+
|
|
5
|
+
describe("shouldProcessBotInboundMessage", () => {
|
|
6
|
+
it("skips payloads without sender id", () => {
|
|
7
|
+
const result = shouldProcessBotInboundMessage({
|
|
8
|
+
msgtype: "text",
|
|
9
|
+
from: {},
|
|
10
|
+
text: { content: "hello" },
|
|
11
|
+
});
|
|
12
|
+
expect(result.shouldProcess).toBe(false);
|
|
13
|
+
expect(result.reason).toBe("missing_sender");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("skips system sender payloads", () => {
|
|
17
|
+
const result = shouldProcessBotInboundMessage({
|
|
18
|
+
msgtype: "text",
|
|
19
|
+
from: { userid: "sys" },
|
|
20
|
+
text: { content: "hello" },
|
|
21
|
+
});
|
|
22
|
+
expect(result.shouldProcess).toBe(false);
|
|
23
|
+
expect(result.reason).toBe("system_sender");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("skips group payloads without chatid", () => {
|
|
27
|
+
const result = shouldProcessBotInboundMessage({
|
|
28
|
+
msgtype: "text",
|
|
29
|
+
chattype: "group",
|
|
30
|
+
from: { userid: "zhangsan" },
|
|
31
|
+
text: { content: "hello" },
|
|
32
|
+
});
|
|
33
|
+
expect(result.shouldProcess).toBe(false);
|
|
34
|
+
expect(result.reason).toBe("missing_chatid");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("accepts normal direct-user messages", () => {
|
|
38
|
+
const result = shouldProcessBotInboundMessage({
|
|
39
|
+
msgtype: "text",
|
|
40
|
+
chattype: "single",
|
|
41
|
+
from: { userid: "zhangsan" },
|
|
42
|
+
text: { content: "hello" },
|
|
43
|
+
});
|
|
44
|
+
expect(result.shouldProcess).toBe(true);
|
|
45
|
+
expect(result.reason).toBe("user_message");
|
|
46
|
+
expect(result.senderUserId).toBe("zhangsan");
|
|
47
|
+
expect(result.chatId).toBe("zhangsan");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("accepts normal group messages with chatid", () => {
|
|
51
|
+
const result = shouldProcessBotInboundMessage({
|
|
52
|
+
msgtype: "text",
|
|
53
|
+
chattype: "group",
|
|
54
|
+
chatid: "wr123",
|
|
55
|
+
from: { userid: "zhangsan" },
|
|
56
|
+
text: { content: "hello" },
|
|
57
|
+
});
|
|
58
|
+
expect(result.shouldProcess).toBe(true);
|
|
59
|
+
expect(result.reason).toBe("user_message");
|
|
60
|
+
expect(result.senderUserId).toBe("zhangsan");
|
|
61
|
+
expect(result.chatId).toBe("wr123");
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -21,7 +21,7 @@ function createMockRequest(bodyObj: any, query: URLSearchParams): IncomingMessag
|
|
|
21
21
|
const socket = new Socket();
|
|
22
22
|
const req = new IncomingMessage(socket);
|
|
23
23
|
req.method = "POST";
|
|
24
|
-
req.url = `/wecom?${query.toString()}`;
|
|
24
|
+
req.url = `/plugins/wecom/bot/default?${query.toString()}`;
|
|
25
25
|
req.push(JSON.stringify(bodyObj));
|
|
26
26
|
req.push(null);
|
|
27
27
|
return req;
|
|
@@ -108,7 +108,7 @@ describe("Monitor Integration: Inbound Image", () => {
|
|
|
108
108
|
config: {} as any,
|
|
109
109
|
runtime: { log: console.log, error: console.error },
|
|
110
110
|
core: mockCore as any,
|
|
111
|
-
path: "/wecom"
|
|
111
|
+
path: "/plugins/wecom/bot/default"
|
|
112
112
|
});
|
|
113
113
|
});
|
|
114
114
|
|
|
@@ -198,6 +198,8 @@ describe("Monitor Integration: Inbound Image", () => {
|
|
|
198
198
|
// Expect Context Injection
|
|
199
199
|
expect(ctx.MediaPath).toBe("/tmp/saved-image.jpg");
|
|
200
200
|
expect(ctx.MediaType).toBe("image/jpeg");
|
|
201
|
+
expect(ctx.Surface).toBe("wecom");
|
|
202
|
+
expect(ctx.OriginatingChannel).toBe("wecom");
|
|
201
203
|
|
|
202
204
|
expect(undiciFetch).toHaveBeenCalledWith(
|
|
203
205
|
imageUrl,
|