@elizaos/plugin-wechat 2.0.0-alpha.537 → 2.0.0-beta.1

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.
@@ -1,135 +0,0 @@
1
- import type { Content } from "@elizaos/core";
2
- import { describe, expect, it, vi } from "vitest";
3
- import { deliverIncomingWechatMessage } from "./runtime-bridge";
4
- import type { WechatMessageContext } from "./types";
5
-
6
- function createMessage(
7
- overrides: Partial<WechatMessageContext> = {},
8
- ): WechatMessageContext {
9
- return {
10
- id: "wechat-msg-1",
11
- type: "text",
12
- sender: "wxid-alice",
13
- recipient: "wxid-agent",
14
- content: "hello agent",
15
- timestamp: 123,
16
- raw: { type: 60001 },
17
- ...overrides,
18
- };
19
- }
20
-
21
- function createRuntime(overrides: Record<string, unknown> = {}) {
22
- return {
23
- agentId: "00000000-0000-0000-0000-000000000001",
24
- ensureConnection: vi.fn().mockResolvedValue(undefined),
25
- createMemory: vi.fn().mockResolvedValue(undefined),
26
- emitEvent: vi.fn().mockResolvedValue(undefined),
27
- logger: {
28
- warn: vi.fn(),
29
- error: vi.fn(),
30
- },
31
- ...overrides,
32
- };
33
- }
34
-
35
- describe("deliverIncomingWechatMessage", () => {
36
- it("routes incoming messages through the runtime message API and reply callback", async () => {
37
- const sendText = vi.fn().mockResolvedValue(undefined);
38
- const sendMessage = vi.fn(
39
- async (
40
- _runtime: unknown,
41
- _memory: unknown,
42
- options?: {
43
- onResponse?: (content: Content) => Promise<unknown>;
44
- },
45
- ) => {
46
- await options?.onResponse?.({ text: "reply from agent" } as Content);
47
- return { responseContent: { text: "reply from agent" } as Content };
48
- },
49
- );
50
- const runtime = createRuntime({
51
- elizaOS: { sendMessage },
52
- });
53
-
54
- await deliverIncomingWechatMessage({
55
- runtime,
56
- accountId: "main",
57
- message: createMessage(),
58
- sendText,
59
- });
60
-
61
- expect(runtime.ensureConnection).toHaveBeenCalledWith(
62
- expect.objectContaining({
63
- entityId: expect.any(String),
64
- roomId: expect.any(String),
65
- userName: "wxid-alice",
66
- userId: "wxid-alice",
67
- source: "wechat",
68
- channelId: "wxid-alice",
69
- worldName: "WeChat",
70
- }),
71
- );
72
- expect(sendMessage).toHaveBeenCalledTimes(1);
73
-
74
- const [, memory] = sendMessage.mock.calls[0];
75
- expect(memory).toEqual(
76
- expect.objectContaining({
77
- content: expect.objectContaining({
78
- text: "hello agent",
79
- source: "wechat",
80
- channelType: "DM",
81
- }),
82
- metadata: expect.objectContaining({
83
- type: "message",
84
- source: "wechat",
85
- provider: "wechat",
86
- fromId: "wxid-alice",
87
- wechat: expect.objectContaining({
88
- userId: "wxid-alice",
89
- messageId: "wechat-msg-1",
90
- }),
91
- }),
92
- }),
93
- );
94
-
95
- expect(sendText).toHaveBeenCalledTimes(1);
96
- expect(sendText).toHaveBeenCalledWith(
97
- "main",
98
- "wxid-alice",
99
- "reply from agent",
100
- );
101
- expect(runtime.createMemory).toHaveBeenCalledWith(
102
- expect.objectContaining({
103
- content: expect.objectContaining({
104
- text: "reply from agent",
105
- source: "wechat",
106
- channelType: "DM",
107
- }),
108
- }),
109
- "messages",
110
- );
111
- });
112
-
113
- it("falls back to MESSAGE_RECEIVED events when no message pipeline is available", async () => {
114
- const runtime = createRuntime();
115
-
116
- await deliverIncomingWechatMessage({
117
- runtime,
118
- accountId: "main",
119
- message: createMessage(),
120
- sendText: vi.fn().mockResolvedValue(undefined),
121
- });
122
-
123
- expect(runtime.emitEvent).toHaveBeenCalledWith(["MESSAGE_RECEIVED"], {
124
- runtime,
125
- message: expect.objectContaining({
126
- content: expect.objectContaining({
127
- text: "hello agent",
128
- source: "wechat",
129
- }),
130
- }),
131
- callback: expect.any(Function),
132
- source: "wechat",
133
- });
134
- });
135
- });