@tobeyoureyes/feishu 1.0.0
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/README.md +290 -0
- package/index.ts +18 -0
- package/openclaw.plugin.json +9 -0
- package/package.json +42 -0
- package/src/api.ts +1160 -0
- package/src/auth.ts +133 -0
- package/src/channel.ts +883 -0
- package/src/context.ts +292 -0
- package/src/dedupe.ts +85 -0
- package/src/dispatch.ts +185 -0
- package/src/history.ts +130 -0
- package/src/inbound.ts +83 -0
- package/src/message.ts +386 -0
- package/src/runtime.ts +14 -0
- package/src/types.ts +330 -0
- package/src/webhook.ts +549 -0
- package/src/websocket.ts +372 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feishu channel types
|
|
3
|
+
*
|
|
4
|
+
* This module consolidates all public types for the Feishu channel plugin.
|
|
5
|
+
* Types are organized into the following categories:
|
|
6
|
+
* - Configuration Types: Plugin and account configuration
|
|
7
|
+
* - API Types: Request/response structures for Feishu API
|
|
8
|
+
* - Message Types: Message content formats (text, post, card)
|
|
9
|
+
* - Event Types: Webhook and WebSocket event structures
|
|
10
|
+
* - Utility Types: Helper types for common operations
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// ============ Configuration Types ============
|
|
14
|
+
|
|
15
|
+
/** API Domain: "feishu" for China, "lark" for International */
|
|
16
|
+
export type FeishuDomain = "feishu" | "lark";
|
|
17
|
+
|
|
18
|
+
/** Connection mode for receiving events */
|
|
19
|
+
export type FeishuConnectionMode = "websocket" | "webhook";
|
|
20
|
+
|
|
21
|
+
/** Render mode for outgoing messages */
|
|
22
|
+
export type FeishuRenderMode = "auto" | "raw" | "card";
|
|
23
|
+
|
|
24
|
+
/** DM policy */
|
|
25
|
+
export type FeishuDmPolicy = "open" | "pairing" | "allowlist";
|
|
26
|
+
|
|
27
|
+
/** Group policy */
|
|
28
|
+
export type FeishuGroupPolicy = "open" | "allowlist" | "disabled";
|
|
29
|
+
|
|
30
|
+
export interface FeishuAccountConfig {
|
|
31
|
+
/** Application ID from Feishu Open Platform */
|
|
32
|
+
appId?: string;
|
|
33
|
+
/** Application Secret from Feishu Open Platform */
|
|
34
|
+
appSecret?: string;
|
|
35
|
+
/** API Domain: "feishu" (China) or "lark" (International). Default: "feishu" */
|
|
36
|
+
domain?: FeishuDomain;
|
|
37
|
+
/** Connection mode: "websocket" (recommended) or "webhook". Default: "websocket" */
|
|
38
|
+
connectionMode?: FeishuConnectionMode;
|
|
39
|
+
/** Webhook path for receiving events (only used when connectionMode is "webhook") */
|
|
40
|
+
webhookPath?: string;
|
|
41
|
+
/** Verification token for event validation */
|
|
42
|
+
verificationToken?: string;
|
|
43
|
+
/** Encrypt key for event decryption (optional) */
|
|
44
|
+
encryptKey?: string;
|
|
45
|
+
/** DM policy: "pairing" | "open" | "allowlist". Default: "pairing" */
|
|
46
|
+
dmPolicy?: FeishuDmPolicy;
|
|
47
|
+
/** Allowed senders for DM (when dmPolicy is "allowlist") */
|
|
48
|
+
allowFrom?: string[];
|
|
49
|
+
/** Group policy: "open" | "allowlist" | "disabled". Default: "allowlist" */
|
|
50
|
+
groupPolicy?: FeishuGroupPolicy;
|
|
51
|
+
/** Whether to require @mention in group chats. Default: true */
|
|
52
|
+
requireMention?: boolean;
|
|
53
|
+
/** Max media size in MB. Default: 30 */
|
|
54
|
+
mediaMaxMb?: number;
|
|
55
|
+
/** Render mode: "auto" | "raw" | "card". Default: "auto" */
|
|
56
|
+
renderMode?: FeishuRenderMode;
|
|
57
|
+
/** Allowed groups (when groupPolicy is "allowlist") */
|
|
58
|
+
groups?: Record<string, { enabled?: boolean; name?: string }>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface FeishuChannelConfig {
|
|
62
|
+
enabled?: boolean;
|
|
63
|
+
/** Default account configuration */
|
|
64
|
+
appId?: string;
|
|
65
|
+
appSecret?: string;
|
|
66
|
+
domain?: FeishuDomain;
|
|
67
|
+
connectionMode?: FeishuConnectionMode;
|
|
68
|
+
webhookPath?: string;
|
|
69
|
+
verificationToken?: string;
|
|
70
|
+
encryptKey?: string;
|
|
71
|
+
dmPolicy?: FeishuDmPolicy;
|
|
72
|
+
allowFrom?: string[];
|
|
73
|
+
groupPolicy?: FeishuGroupPolicy;
|
|
74
|
+
requireMention?: boolean;
|
|
75
|
+
mediaMaxMb?: number;
|
|
76
|
+
renderMode?: FeishuRenderMode;
|
|
77
|
+
groups?: Record<string, { enabled?: boolean; name?: string }>;
|
|
78
|
+
/** Named accounts */
|
|
79
|
+
accounts?: Record<string, FeishuAccountConfig & { enabled?: boolean; name?: string }>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface ResolvedFeishuAccount {
|
|
83
|
+
accountId: string;
|
|
84
|
+
name?: string;
|
|
85
|
+
enabled: boolean;
|
|
86
|
+
configured: boolean;
|
|
87
|
+
appId?: string;
|
|
88
|
+
appSecret?: string;
|
|
89
|
+
appIdSource: "config" | "env" | "none";
|
|
90
|
+
appSecretSource: "config" | "env" | "none";
|
|
91
|
+
/** API base URL based on domain */
|
|
92
|
+
apiBase: string;
|
|
93
|
+
/** WebSocket URL for long connection */
|
|
94
|
+
wsUrl: string;
|
|
95
|
+
domain: FeishuDomain;
|
|
96
|
+
connectionMode: FeishuConnectionMode;
|
|
97
|
+
webhookPath?: string;
|
|
98
|
+
verificationToken?: string;
|
|
99
|
+
encryptKey?: string;
|
|
100
|
+
renderMode: FeishuRenderMode;
|
|
101
|
+
requireMention: boolean;
|
|
102
|
+
config: FeishuAccountConfig;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ============ API Types ============
|
|
106
|
+
|
|
107
|
+
export interface FeishuTokenResponse {
|
|
108
|
+
code: number;
|
|
109
|
+
msg: string;
|
|
110
|
+
tenant_access_token?: string;
|
|
111
|
+
expire?: number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface FeishuApiResponse<T = unknown> {
|
|
115
|
+
code: number;
|
|
116
|
+
msg: string;
|
|
117
|
+
data?: T;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export type FeishuReceiveIdType = "open_id" | "user_id" | "union_id" | "email" | "chat_id";
|
|
121
|
+
|
|
122
|
+
export type FeishuMsgType = "text" | "post" | "image" | "file" | "audio" | "media" | "sticker" | "interactive" | "share_chat" | "share_user";
|
|
123
|
+
|
|
124
|
+
// ============ Message Types ============
|
|
125
|
+
|
|
126
|
+
export interface FeishuTextContent {
|
|
127
|
+
text: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface FeishuPostContent {
|
|
131
|
+
zh_cn?: FeishuPostBody;
|
|
132
|
+
en_us?: FeishuPostBody;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface FeishuPostBody {
|
|
136
|
+
title?: string;
|
|
137
|
+
content: FeishuPostElement[][];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export type FeishuPostElement =
|
|
141
|
+
| { tag: "text"; text: string; un_escape?: boolean }
|
|
142
|
+
| { tag: "a"; text: string; href: string }
|
|
143
|
+
| { tag: "at"; user_id: string; user_name?: string }
|
|
144
|
+
| { tag: "img"; image_key: string; width?: number; height?: number }
|
|
145
|
+
| { tag: "media"; file_key: string; image_key?: string }
|
|
146
|
+
| { tag: "emotion"; emoji_type: string };
|
|
147
|
+
|
|
148
|
+
export interface FeishuInteractiveContent {
|
|
149
|
+
config?: {
|
|
150
|
+
wide_screen_mode?: boolean;
|
|
151
|
+
enable_forward?: boolean;
|
|
152
|
+
};
|
|
153
|
+
header?: {
|
|
154
|
+
title?: {
|
|
155
|
+
tag: "plain_text" | "lark_md";
|
|
156
|
+
content: string;
|
|
157
|
+
};
|
|
158
|
+
template?: string;
|
|
159
|
+
};
|
|
160
|
+
elements?: FeishuCardElement[];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export type FeishuCardElement =
|
|
164
|
+
| { tag: "div"; text?: { tag: string; content: string }; fields?: Array<{ is_short: boolean; text: { tag: string; content: string } }> }
|
|
165
|
+
| { tag: "hr" }
|
|
166
|
+
| { tag: "action"; actions: Array<{ tag: string; text?: { tag: string; content: string }; url?: string; type?: string; value?: unknown }> }
|
|
167
|
+
| { tag: "note"; elements: Array<{ tag: string; content?: string; img_key?: string }> }
|
|
168
|
+
| { tag: "markdown"; content: string };
|
|
169
|
+
|
|
170
|
+
export interface FeishuSendMessageRequest {
|
|
171
|
+
receive_id: string;
|
|
172
|
+
msg_type: FeishuMsgType;
|
|
173
|
+
content: string;
|
|
174
|
+
uuid?: string;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export interface FeishuSendMessageResponse {
|
|
178
|
+
message_id: string;
|
|
179
|
+
root_id?: string;
|
|
180
|
+
parent_id?: string;
|
|
181
|
+
msg_type: string;
|
|
182
|
+
create_time: string;
|
|
183
|
+
update_time: string;
|
|
184
|
+
deleted: boolean;
|
|
185
|
+
updated: boolean;
|
|
186
|
+
chat_id: string;
|
|
187
|
+
sender: {
|
|
188
|
+
id: string;
|
|
189
|
+
id_type: string;
|
|
190
|
+
sender_type: string;
|
|
191
|
+
tenant_key: string;
|
|
192
|
+
};
|
|
193
|
+
body: {
|
|
194
|
+
content: string;
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ============ Event Types ============
|
|
199
|
+
|
|
200
|
+
export interface FeishuEventHeader {
|
|
201
|
+
event_id: string;
|
|
202
|
+
event_type: string;
|
|
203
|
+
create_time: string;
|
|
204
|
+
token: string;
|
|
205
|
+
app_id: string;
|
|
206
|
+
tenant_key: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface FeishuEventBase {
|
|
210
|
+
schema: string;
|
|
211
|
+
header: FeishuEventHeader;
|
|
212
|
+
event: unknown;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export interface FeishuUrlVerificationEvent {
|
|
216
|
+
challenge: string;
|
|
217
|
+
token: string;
|
|
218
|
+
type: "url_verification";
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export interface FeishuMessageReceiveEvent extends FeishuEventBase {
|
|
222
|
+
header: FeishuEventHeader & { event_type: "im.message.receive_v1" };
|
|
223
|
+
event: {
|
|
224
|
+
sender: {
|
|
225
|
+
sender_id: {
|
|
226
|
+
union_id?: string;
|
|
227
|
+
user_id?: string;
|
|
228
|
+
open_id?: string;
|
|
229
|
+
};
|
|
230
|
+
sender_type: string;
|
|
231
|
+
tenant_key: string;
|
|
232
|
+
};
|
|
233
|
+
message: {
|
|
234
|
+
message_id: string;
|
|
235
|
+
root_id?: string;
|
|
236
|
+
parent_id?: string;
|
|
237
|
+
create_time: string;
|
|
238
|
+
update_time?: string;
|
|
239
|
+
chat_id: string;
|
|
240
|
+
chat_type: "p2p" | "group";
|
|
241
|
+
message_type: FeishuMsgType;
|
|
242
|
+
content: string;
|
|
243
|
+
mentions?: Array<{
|
|
244
|
+
key: string;
|
|
245
|
+
id: {
|
|
246
|
+
union_id?: string;
|
|
247
|
+
user_id?: string;
|
|
248
|
+
open_id?: string;
|
|
249
|
+
};
|
|
250
|
+
name: string;
|
|
251
|
+
tenant_key?: string;
|
|
252
|
+
}>;
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface FeishuBotAddedEvent extends FeishuEventBase {
|
|
258
|
+
header: FeishuEventHeader & { event_type: "im.chat.member.bot.added_v1" };
|
|
259
|
+
event: {
|
|
260
|
+
chat_id: string;
|
|
261
|
+
operator_id: {
|
|
262
|
+
union_id?: string;
|
|
263
|
+
user_id?: string;
|
|
264
|
+
open_id?: string;
|
|
265
|
+
};
|
|
266
|
+
external: boolean;
|
|
267
|
+
operator_tenant_key: string;
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export interface FeishuBotRemovedEvent extends FeishuEventBase {
|
|
272
|
+
header: FeishuEventHeader & { event_type: "im.chat.member.bot.deleted_v1" };
|
|
273
|
+
event: {
|
|
274
|
+
chat_id: string;
|
|
275
|
+
operator_id: {
|
|
276
|
+
union_id?: string;
|
|
277
|
+
user_id?: string;
|
|
278
|
+
open_id?: string;
|
|
279
|
+
};
|
|
280
|
+
external: boolean;
|
|
281
|
+
operator_tenant_key: string;
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export type FeishuEvent =
|
|
286
|
+
| FeishuUrlVerificationEvent
|
|
287
|
+
| FeishuMessageReceiveEvent
|
|
288
|
+
| FeishuBotAddedEvent
|
|
289
|
+
| FeishuBotRemovedEvent;
|
|
290
|
+
|
|
291
|
+
// ============ Utility Types ============
|
|
292
|
+
|
|
293
|
+
export interface FeishuTokenCache {
|
|
294
|
+
token: string;
|
|
295
|
+
expiresAt: number;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export interface FeishuSendOptions {
|
|
299
|
+
accountId?: string;
|
|
300
|
+
receiveIdType?: FeishuReceiveIdType;
|
|
301
|
+
replyToId?: string;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export interface FeishuSendResult {
|
|
305
|
+
ok: boolean;
|
|
306
|
+
messageId?: string;
|
|
307
|
+
error?: string;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// ============ Re-exports from Other Modules ============
|
|
311
|
+
// For unified type access, we re-export commonly used types
|
|
312
|
+
|
|
313
|
+
/** Re-export inbound message type from webhook module */
|
|
314
|
+
export type { FeishuInboundMessage, FeishuWebhookResult } from "./webhook.js";
|
|
315
|
+
|
|
316
|
+
/** Re-export WebSocket types */
|
|
317
|
+
export type { WSConnectionState, FeishuWSClient, WSClientOptions } from "./websocket.js";
|
|
318
|
+
|
|
319
|
+
/** Re-export deduplication types */
|
|
320
|
+
export type { DedupeCache, DedupeCacheOptions } from "./dedupe.js";
|
|
321
|
+
|
|
322
|
+
/** Re-export history management types */
|
|
323
|
+
export type {
|
|
324
|
+
HistoryEntry,
|
|
325
|
+
GroupHistoryManager,
|
|
326
|
+
GroupHistoryManagerOptions,
|
|
327
|
+
} from "./history.js";
|
|
328
|
+
|
|
329
|
+
/** Re-export card building types from api module */
|
|
330
|
+
export type { CardColor, CardBaseOptions, CardButton, CardSection } from "./api.js";
|