chatccc 0.2.33 → 0.2.35
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/package.json +1 -1
- package/src/__tests__/feishu-platform.test.ts +55 -0
- package/src/__tests__/sim-agent.test.ts +174 -0
- package/src/__tests__/sim-platform.test.ts +77 -0
- package/src/__tests__/sim-store.test.ts +214 -0
- package/src/agent-file-rpc.ts +1 -1
- package/src/agent-image-rpc.ts +1 -1
- package/src/config.ts +1 -0
- package/src/feishu-api.ts +27 -0
- package/src/feishu-platform.ts +134 -0
- package/src/index.ts +121 -49
- package/src/session.ts +1 -1
- package/src/sim-agent.ts +156 -0
- package/src/sim-platform.ts +148 -0
- package/src/sim-store.ts +313 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sim-platform.ts — SimulatedPlatform: 零飞书依赖的本地模拟实现
|
|
3
|
+
*
|
|
4
|
+
* 所有飞书 API 调用都由本地 SimStore 替代:
|
|
5
|
+
* - 消息通过 SimStore 写入内存 + JSONL + 事件推送
|
|
6
|
+
* - 群聊/账户信息由 SimStore 统一管理
|
|
7
|
+
* - createGroupChat 生成 "sim_<uuid>" 格式的 chat_id
|
|
8
|
+
*
|
|
9
|
+
* 纯函数(extractSessionInfo / formatDelayNotice / reportPermissionResults)
|
|
10
|
+
* 直接从 feishu-api.ts re-export,不重新实现。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
extractSessionInfo as realExtractSessionInfo,
|
|
17
|
+
extractSessionId as realExtractSessionId,
|
|
18
|
+
formatDelayNotice as realFormatDelayNotice,
|
|
19
|
+
reportPermissionResults as realReportPermissionResults,
|
|
20
|
+
} from "./feishu-api.ts";
|
|
21
|
+
import type { FeishuPlatform } from "./feishu-platform.ts";
|
|
22
|
+
import { simStore } from "./sim-store.ts";
|
|
23
|
+
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// 持久化路径
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
import { homedir } from "node:os";
|
|
29
|
+
const SIM_DIR = join(homedir(), ".chatccc", "sim");
|
|
30
|
+
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
// 工具函数
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
function ts(): string {
|
|
36
|
+
return new Date().toISOString().replace("T", " ").slice(0, 19);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// SimulatedPlatform
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
|
|
43
|
+
export const SimulatedPlatform: FeishuPlatform = {
|
|
44
|
+
// ---- 认证 ----
|
|
45
|
+
async getTenantAccessToken() {
|
|
46
|
+
return "sim_token";
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
// ---- 消息发送:委托给 simStore ----
|
|
50
|
+
async sendTextReply(_token, chatId, text) {
|
|
51
|
+
console.log(`[${ts()}] [SIM:SEND] text → ${chatId}: ${text.slice(0, 80)}`);
|
|
52
|
+
simStore.sendReply(chatId, "text", text);
|
|
53
|
+
return true;
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
async sendCardReply(_token, chatId, title, content, _template) {
|
|
57
|
+
console.log(`[${ts()}] [SIM:SEND] card → ${chatId}: [${title}]`);
|
|
58
|
+
const text = `**[${title}]**\n${content}`;
|
|
59
|
+
simStore.sendReply(chatId, "card", text);
|
|
60
|
+
return true;
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
async sendImageReply(_token, chatId, imagePath) {
|
|
64
|
+
console.log(`[${ts()}] [SIM:SEND] image → ${chatId}: ${imagePath}`);
|
|
65
|
+
simStore.sendReply(chatId, "image", imagePath);
|
|
66
|
+
return true;
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
async sendFileReply(_token, chatId, filePath) {
|
|
70
|
+
console.log(`[${ts()}] [SIM:SEND] file → ${chatId}: ${filePath}`);
|
|
71
|
+
simStore.sendReply(chatId, "file", filePath);
|
|
72
|
+
return true;
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
async sendRawCard(_token, chatId, cardJson) {
|
|
76
|
+
console.log(`[${ts()}] [SIM:SEND] raw_card → ${chatId}: ${cardJson.slice(0, 80)}...`);
|
|
77
|
+
simStore.sendReply(chatId, "raw_card", cardJson.slice(0, 500));
|
|
78
|
+
return true;
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
// ---- 消息管理 ----
|
|
82
|
+
async addReaction(_token, _messageId, _emojiType) {
|
|
83
|
+
// 模拟模式不需要表情回应
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
async recallMessage(_token, _messageId) {
|
|
87
|
+
return true;
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
async updateCardMessage(_token, _messageId, content) {
|
|
91
|
+
// 模拟模式:记录卡片更新到控制台(无 chatId,不写入消息历史)
|
|
92
|
+
console.log(`[${ts()}] [SIM:CARD] update: msgId=${_messageId} preview=${content.slice(0, 80)}`);
|
|
93
|
+
return true;
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
// ---- 群聊管理 ----
|
|
97
|
+
async createGroupChat(_token, name, userIds) {
|
|
98
|
+
const chat = simStore.createGroupChat(name, userIds);
|
|
99
|
+
console.log(`[${ts()}] [SIM:CHAT] created: ${chat.id} name="${name}" members=${userIds.length}`);
|
|
100
|
+
return chat.id;
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
async updateChatInfo(_token, chatId, name, description) {
|
|
104
|
+
simStore.updateChatInfo(chatId, name, description);
|
|
105
|
+
console.log(`[${ts()}] [SIM:CHAT] updated: ${chatId} name="${name}"`);
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
async getChatInfo(_token, chatId) {
|
|
109
|
+
const chat = simStore.getChat(chatId);
|
|
110
|
+
if (!chat) throw new Error(`[99999] chat not found: ${chatId}`);
|
|
111
|
+
return { name: chat.name, description: chat.description };
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
// ---- 头像 ----
|
|
115
|
+
async setChatAvatar(_token, _chatId, _tool, _status) {
|
|
116
|
+
// 模拟模式不需要头像
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
// ---- 图片下载 ----
|
|
120
|
+
async getOrDownloadImage(_token, _messageId, fileKey) {
|
|
121
|
+
return join(SIM_DIR, "images", fileKey);
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
// ---- 权限验证 ----
|
|
125
|
+
async verifyAllPermissions(_token) {
|
|
126
|
+
return [
|
|
127
|
+
{ scope: "im:chat", description: "模拟", ok: true, detail: "模拟模式跳过" },
|
|
128
|
+
{ scope: "im:message:send_as_bot", description: "模拟", ok: true, detail: "模拟模式跳过" },
|
|
129
|
+
{ scope: "im:message:reaction", description: "模拟", ok: true, detail: "模拟模式跳过" },
|
|
130
|
+
{ scope: "im:message", description: "模拟", ok: true, detail: "模拟模式跳过" },
|
|
131
|
+
{ scope: "cardkit:card", description: "模拟", ok: true, detail: "模拟模式跳过" },
|
|
132
|
+
];
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
// ---- 纯函数:直接从真实实现 re-export ----
|
|
136
|
+
extractSessionInfo: realExtractSessionInfo,
|
|
137
|
+
extractSessionId: realExtractSessionId,
|
|
138
|
+
formatDelayNotice: realFormatDelayNotice,
|
|
139
|
+
reportPermissionResults: realReportPermissionResults,
|
|
140
|
+
|
|
141
|
+
// ---- 其他 ----
|
|
142
|
+
async sendRestartCard(_token) {
|
|
143
|
+
// 模拟模式不需要重启通知
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/** 模拟模式下的默认 chat_id(重新导出以保持向后兼容) */
|
|
148
|
+
export { SIM_DEFAULT_CHAT_ID } from "./sim-store.ts";
|
package/src/sim-store.ts
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sim-store.ts — 模拟飞书环境的状态管理核心
|
|
3
|
+
*
|
|
4
|
+
* SimStore 是一个单例的 EventEmitter,管理所有模拟状态:
|
|
5
|
+
* - 账户(bot + 多个用户)
|
|
6
|
+
* - 会话(群聊 + 私聊)
|
|
7
|
+
* - 消息历史(内存 + JSONL 持久化)
|
|
8
|
+
*
|
|
9
|
+
* 同时暴露 setMessageHandler / dispatchMessage,让 SimAgent 进程内触发
|
|
10
|
+
* handleCommand 而无需通过 HTTP。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { randomUUID } from "node:crypto";
|
|
14
|
+
import { appendFile, mkdir } from "node:fs/promises";
|
|
15
|
+
import { homedir } from "node:os";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { EventEmitter } from "node:events";
|
|
18
|
+
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// 类型定义
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
export interface SimAccount {
|
|
24
|
+
id: string; // "bot" | "sim_user_001" | "alice"
|
|
25
|
+
kind: "bot" | "user";
|
|
26
|
+
name: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface SimMessage {
|
|
30
|
+
id: string; // UUID
|
|
31
|
+
chatId: string;
|
|
32
|
+
senderId: string; // SimAccount.id
|
|
33
|
+
type: "text" | "card" | "image" | "file" | "raw_card" | "system";
|
|
34
|
+
content: string; // 文本内容或 JSON 字符串
|
|
35
|
+
timestamp: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface SimChat {
|
|
39
|
+
id: string; // "sim_default" | "sim_<uuid8>" | "p2p_alice_bot"
|
|
40
|
+
type: "group" | "p2p";
|
|
41
|
+
name: string;
|
|
42
|
+
description: string;
|
|
43
|
+
memberIds: string[]; // 所有成员,第一个是创建者
|
|
44
|
+
messages: SimMessage[]; // 消息历史(按时间排序)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** handleCommand 的回调签名 */
|
|
48
|
+
export type MessageHandler = (
|
|
49
|
+
text: string,
|
|
50
|
+
chatId: string,
|
|
51
|
+
openId: string,
|
|
52
|
+
timestamp: number,
|
|
53
|
+
chatType: string,
|
|
54
|
+
traceId?: string,
|
|
55
|
+
) => Promise<void>;
|
|
56
|
+
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// 持久化路径
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
|
|
61
|
+
const SIM_DIR = join(homedir(), ".chatccc", "sim");
|
|
62
|
+
const MESSAGES_FILE = join(SIM_DIR, "messages.jsonl");
|
|
63
|
+
|
|
64
|
+
async function ensureDir(): Promise<void> {
|
|
65
|
+
await mkdir(SIM_DIR, { recursive: true });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function appendJsonl(line: Record<string, unknown>): Promise<void> {
|
|
69
|
+
await ensureDir();
|
|
70
|
+
await appendFile(MESSAGES_FILE, JSON.stringify(line) + "\n", "utf-8");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
// SimStore
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
|
|
77
|
+
export class SimStore extends EventEmitter {
|
|
78
|
+
accounts = new Map<string, SimAccount>();
|
|
79
|
+
chats = new Map<string, SimChat>();
|
|
80
|
+
|
|
81
|
+
// ---- 初始化 ----
|
|
82
|
+
|
|
83
|
+
constructor() {
|
|
84
|
+
super();
|
|
85
|
+
this._initDefaults();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private _initDefaults(): void {
|
|
89
|
+
// 注册 bot 账户
|
|
90
|
+
this.accounts.set("bot", { id: "bot", kind: "bot", name: "ChatCCC" });
|
|
91
|
+
|
|
92
|
+
// 注册默认用户
|
|
93
|
+
this.accounts.set("sim_user_001", { id: "sim_user_001", kind: "user", name: "Developer" });
|
|
94
|
+
|
|
95
|
+
// 创建默认群聊
|
|
96
|
+
const defaultChatId = "sim_default";
|
|
97
|
+
this.chats.set(defaultChatId, {
|
|
98
|
+
id: defaultChatId,
|
|
99
|
+
type: "group",
|
|
100
|
+
name: "默认模拟会话",
|
|
101
|
+
description: "",
|
|
102
|
+
memberIds: ["bot", "sim_user_001"],
|
|
103
|
+
messages: [],
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ---- 账户管理 ----
|
|
108
|
+
|
|
109
|
+
registerAccount(account: SimAccount): void {
|
|
110
|
+
if (this.accounts.has(account.id)) {
|
|
111
|
+
throw new Error(`Account "${account.id}" already exists`);
|
|
112
|
+
}
|
|
113
|
+
this.accounts.set(account.id, account);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
getAccount(id: string): SimAccount | undefined {
|
|
117
|
+
return this.accounts.get(id);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ---- 会话管理 ----
|
|
121
|
+
|
|
122
|
+
createGroupChat(name: string, memberIds: string[]): SimChat {
|
|
123
|
+
const chatId = `sim_${randomUUID().slice(0, 8)}`;
|
|
124
|
+
// bot 始终是成员
|
|
125
|
+
const allMembers = ["bot", ...memberIds.filter((id) => id !== "bot")];
|
|
126
|
+
const chat: SimChat = {
|
|
127
|
+
id: chatId,
|
|
128
|
+
type: "group",
|
|
129
|
+
name,
|
|
130
|
+
description: "",
|
|
131
|
+
memberIds: allMembers,
|
|
132
|
+
messages: [],
|
|
133
|
+
};
|
|
134
|
+
this.chats.set(chatId, chat);
|
|
135
|
+
|
|
136
|
+
// 通知被拉入群的用户
|
|
137
|
+
for (const uid of memberIds) {
|
|
138
|
+
this.emit("member_added", { chatId, userId: uid });
|
|
139
|
+
}
|
|
140
|
+
this.emit("chat_created", { chat });
|
|
141
|
+
|
|
142
|
+
return chat;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
createP2pChat(userId: string): SimChat {
|
|
146
|
+
// p2p 命名规则:p2p_<userId>_bot
|
|
147
|
+
const chatId = `p2p_${userId}_bot`;
|
|
148
|
+
const existing = this.chats.get(chatId);
|
|
149
|
+
if (existing) return existing;
|
|
150
|
+
|
|
151
|
+
const user = this.accounts.get(userId);
|
|
152
|
+
const chat: SimChat = {
|
|
153
|
+
id: chatId,
|
|
154
|
+
type: "p2p",
|
|
155
|
+
name: user ? `${user.name} 的私聊` : `私聊`,
|
|
156
|
+
description: "",
|
|
157
|
+
memberIds: ["bot", userId],
|
|
158
|
+
messages: [],
|
|
159
|
+
};
|
|
160
|
+
this.chats.set(chatId, chat);
|
|
161
|
+
this.emit("chat_created", { chat });
|
|
162
|
+
return chat;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
getChat(chatId: string): SimChat | undefined {
|
|
166
|
+
return this.chats.get(chatId);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
getChatsForUser(userId: string): SimChat[] {
|
|
170
|
+
return [...this.chats.values()].filter((c) => c.memberIds.includes(userId));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
addMember(chatId: string, userId: string): void {
|
|
174
|
+
const chat = this.chats.get(chatId);
|
|
175
|
+
if (!chat) throw new Error(`Chat not found: ${chatId}`);
|
|
176
|
+
if (!chat.memberIds.includes(userId)) {
|
|
177
|
+
chat.memberIds.push(userId);
|
|
178
|
+
this.emit("member_added", { chatId, userId });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
updateChatInfo(chatId: string, name: string, description: string): void {
|
|
183
|
+
const chat = this.chats.get(chatId);
|
|
184
|
+
if (chat) {
|
|
185
|
+
chat.name = name;
|
|
186
|
+
chat.description = description;
|
|
187
|
+
} else {
|
|
188
|
+
// 模拟模式下机器人可能尝试更新不存在的群(比如从旧状态恢复),兼容处理
|
|
189
|
+
this.chats.set(chatId, {
|
|
190
|
+
id: chatId,
|
|
191
|
+
type: "group",
|
|
192
|
+
name,
|
|
193
|
+
description,
|
|
194
|
+
memberIds: ["bot", "sim_user_001"],
|
|
195
|
+
messages: [],
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ---- 消息管理 ----
|
|
201
|
+
|
|
202
|
+
/** 任何参与者发送消息 */
|
|
203
|
+
recordMessage(
|
|
204
|
+
chatId: string,
|
|
205
|
+
senderId: string,
|
|
206
|
+
type: SimMessage["type"],
|
|
207
|
+
content: string,
|
|
208
|
+
): SimMessage {
|
|
209
|
+
const chat = this.chats.get(chatId);
|
|
210
|
+
if (!chat) throw new Error(`Chat not found: ${chatId}`);
|
|
211
|
+
|
|
212
|
+
const msg: SimMessage = {
|
|
213
|
+
id: randomUUID(),
|
|
214
|
+
chatId,
|
|
215
|
+
senderId,
|
|
216
|
+
type,
|
|
217
|
+
content,
|
|
218
|
+
timestamp: Date.now(),
|
|
219
|
+
};
|
|
220
|
+
chat.messages.push(msg);
|
|
221
|
+
|
|
222
|
+
// 写 JSONL
|
|
223
|
+
appendJsonl({
|
|
224
|
+
direction: senderId === "bot" ? "send" : "recv",
|
|
225
|
+
chat_id: chatId,
|
|
226
|
+
sender_id: senderId,
|
|
227
|
+
msg_type: type,
|
|
228
|
+
content,
|
|
229
|
+
timestamp: msg.timestamp,
|
|
230
|
+
}).catch(() => {});
|
|
231
|
+
|
|
232
|
+
// 通知所有订阅者
|
|
233
|
+
this.emit("message", { chatId, message: msg });
|
|
234
|
+
|
|
235
|
+
return msg;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** bot 发送回复——即使 chat 不存在也记录(兼容未知 chat) */
|
|
239
|
+
sendReply(chatId: string, type: SimMessage["type"], content: string): SimMessage {
|
|
240
|
+
const msg: SimMessage = {
|
|
241
|
+
id: randomUUID(),
|
|
242
|
+
chatId,
|
|
243
|
+
senderId: "bot",
|
|
244
|
+
type,
|
|
245
|
+
content,
|
|
246
|
+
timestamp: Date.now(),
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// 如果 chat 存在,追加到消息历史
|
|
250
|
+
const chat = this.chats.get(chatId);
|
|
251
|
+
if (chat) {
|
|
252
|
+
chat.messages.push(msg);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// 写 JSONL
|
|
256
|
+
appendJsonl({
|
|
257
|
+
direction: "send",
|
|
258
|
+
chat_id: chatId,
|
|
259
|
+
msg_type: type,
|
|
260
|
+
content,
|
|
261
|
+
timestamp: msg.timestamp,
|
|
262
|
+
}).catch(() => {});
|
|
263
|
+
|
|
264
|
+
// 通知订阅者
|
|
265
|
+
this.emit("message", { chatId, message: msg });
|
|
266
|
+
|
|
267
|
+
return msg;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** 获取指定会话的消息 */
|
|
271
|
+
getMessages(chatId: string, requesterId: string): SimMessage[] {
|
|
272
|
+
const chat = this.chats.get(chatId);
|
|
273
|
+
if (!chat) return [];
|
|
274
|
+
// 只有成员能看消息
|
|
275
|
+
if (!chat.memberIds.includes(requesterId)) return [];
|
|
276
|
+
return chat.messages;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** 重置所有状态(测试用) */
|
|
280
|
+
reset(): void {
|
|
281
|
+
this.accounts.clear();
|
|
282
|
+
this.chats.clear();
|
|
283
|
+
this.removeAllListeners();
|
|
284
|
+
this._initDefaults();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// ---------------------------------------------------------------------------
|
|
289
|
+
// 单例 + 消息分发
|
|
290
|
+
// ---------------------------------------------------------------------------
|
|
291
|
+
|
|
292
|
+
export const simStore = new SimStore();
|
|
293
|
+
|
|
294
|
+
export const SIM_DEFAULT_CHAT_ID = "sim_default";
|
|
295
|
+
|
|
296
|
+
let _messageHandler: MessageHandler | null = null;
|
|
297
|
+
|
|
298
|
+
/** 注册 handleCommand 回调(由 index.ts 在模拟模式启动时调用) */
|
|
299
|
+
export function setMessageHandler(handler: MessageHandler): void {
|
|
300
|
+
_messageHandler = handler;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** 模拟用户发送消息 → 记录消息 + 触发 bot 处理 */
|
|
304
|
+
export async function dispatchMessage(
|
|
305
|
+
text: string,
|
|
306
|
+
chatId: string,
|
|
307
|
+
openId: string,
|
|
308
|
+
chatType: string,
|
|
309
|
+
): Promise<void> {
|
|
310
|
+
if (!_messageHandler) throw new Error("Message handler not registered — is simulate mode running?");
|
|
311
|
+
simStore.recordMessage(chatId, openId, "text", text);
|
|
312
|
+
await _messageHandler(text, chatId, openId, Date.now(), chatType);
|
|
313
|
+
}
|