@larksuiteoapi/node-sdk 1.61.0 → 1.62.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 +26 -4
- package/README.zh.md +170 -78
- package/es/index.js +3766 -9
- package/lib/index.js +3777 -9
- package/package.json +1 -1
- package/types/index.d.ts +592 -18
package/types/index.d.ts
CHANGED
|
@@ -110,6 +110,8 @@ interface IClientParams {
|
|
|
110
110
|
helpDeskId?: string;
|
|
111
111
|
helpDeskToken?: string;
|
|
112
112
|
httpInstance?: HttpInstance;
|
|
113
|
+
/** Caller tag appended to User-Agent as `source/<name>`. */
|
|
114
|
+
source?: string;
|
|
113
115
|
}
|
|
114
116
|
interface IPayload {
|
|
115
117
|
params?: Record<string, any>;
|
|
@@ -5923,7 +5925,7 @@ declare abstract class Client$12 extends Client$13 {
|
|
|
5923
5925
|
} | undefined;
|
|
5924
5926
|
recommend_item_infos?: {
|
|
5925
5927
|
item_id?: string | undefined;
|
|
5926
|
-
item_type?: "
|
|
5928
|
+
item_type?: "link" | "application" | undefined;
|
|
5927
5929
|
name?: string | undefined;
|
|
5928
5930
|
description?: string | undefined;
|
|
5929
5931
|
link_url?: string | undefined;
|
|
@@ -5940,7 +5942,7 @@ declare abstract class Client$12 extends Client$13 {
|
|
|
5940
5942
|
}[] | undefined;
|
|
5941
5943
|
distributed_recommend_item_infos?: {
|
|
5942
5944
|
item_id?: string | undefined;
|
|
5943
|
-
item_type?: "
|
|
5945
|
+
item_type?: "link" | "application" | undefined;
|
|
5944
5946
|
name?: string | undefined;
|
|
5945
5947
|
description?: string | undefined;
|
|
5946
5948
|
link_url?: string | undefined;
|
|
@@ -5989,7 +5991,7 @@ declare abstract class Client$12 extends Client$13 {
|
|
|
5989
5991
|
} | undefined;
|
|
5990
5992
|
recommend_item_infos?: {
|
|
5991
5993
|
item_id?: string | undefined;
|
|
5992
|
-
item_type?: "
|
|
5994
|
+
item_type?: "link" | "application" | undefined;
|
|
5993
5995
|
name?: string | undefined;
|
|
5994
5996
|
description?: string | undefined;
|
|
5995
5997
|
link_url?: string | undefined;
|
|
@@ -6006,7 +6008,7 @@ declare abstract class Client$12 extends Client$13 {
|
|
|
6006
6008
|
}[] | undefined;
|
|
6007
6009
|
distributed_recommend_item_infos?: {
|
|
6008
6010
|
item_id?: string | undefined;
|
|
6009
|
-
item_type?: "
|
|
6011
|
+
item_type?: "link" | "application" | undefined;
|
|
6010
6012
|
name?: string | undefined;
|
|
6011
6013
|
description?: string | undefined;
|
|
6012
6014
|
link_url?: string | undefined;
|
|
@@ -6769,7 +6771,7 @@ declare abstract class Client$12 extends Client$13 {
|
|
|
6769
6771
|
status?: number | undefined;
|
|
6770
6772
|
scene_type?: number | undefined;
|
|
6771
6773
|
payment_type?: number | undefined;
|
|
6772
|
-
create_source?: "developer_console" | "base" | "app_engine" | "bot_builder" | "aily" |
|
|
6774
|
+
create_source?: "unknown" | "developer_console" | "base" | "app_engine" | "bot_builder" | "aily" | undefined;
|
|
6773
6775
|
redirect_urls?: string[] | undefined;
|
|
6774
6776
|
online_version_id?: string | undefined;
|
|
6775
6777
|
unaudit_version_id?: string | undefined;
|
|
@@ -6846,7 +6848,7 @@ declare abstract class Client$12 extends Client$13 {
|
|
|
6846
6848
|
status?: number | undefined;
|
|
6847
6849
|
scene_type?: number | undefined;
|
|
6848
6850
|
payment_type?: number | undefined;
|
|
6849
|
-
create_source?: "developer_console" | "base" | "app_engine" | "bot_builder" | "aily" |
|
|
6851
|
+
create_source?: "unknown" | "developer_console" | "base" | "app_engine" | "bot_builder" | "aily" | undefined;
|
|
6850
6852
|
redirect_urls?: string[] | undefined;
|
|
6851
6853
|
online_version_id?: string | undefined;
|
|
6852
6854
|
unaudit_version_id?: string | undefined;
|
|
@@ -6935,7 +6937,7 @@ declare abstract class Client$12 extends Client$13 {
|
|
|
6935
6937
|
status?: number | undefined;
|
|
6936
6938
|
scene_type?: number | undefined;
|
|
6937
6939
|
payment_type?: number | undefined;
|
|
6938
|
-
create_source?: "developer_console" | "base" | "app_engine" | "bot_builder" | "aily" |
|
|
6940
|
+
create_source?: "unknown" | "developer_console" | "base" | "app_engine" | "bot_builder" | "aily" | undefined;
|
|
6939
6941
|
redirect_urls?: string[] | undefined;
|
|
6940
6942
|
online_version_id?: string | undefined;
|
|
6941
6943
|
unaudit_version_id?: string | undefined;
|
|
@@ -7444,7 +7446,7 @@ declare abstract class Client$12 extends Client$13 {
|
|
|
7444
7446
|
} | undefined;
|
|
7445
7447
|
recommend_item_infos?: {
|
|
7446
7448
|
item_id?: string | undefined;
|
|
7447
|
-
item_type?: "
|
|
7449
|
+
item_type?: "link" | "application" | undefined;
|
|
7448
7450
|
name?: string | undefined;
|
|
7449
7451
|
description?: string | undefined;
|
|
7450
7452
|
link_url?: string | undefined;
|
|
@@ -7461,7 +7463,7 @@ declare abstract class Client$12 extends Client$13 {
|
|
|
7461
7463
|
}[] | undefined;
|
|
7462
7464
|
distributed_recommend_item_infos?: {
|
|
7463
7465
|
item_id?: string | undefined;
|
|
7464
|
-
item_type?: "
|
|
7466
|
+
item_type?: "link" | "application" | undefined;
|
|
7465
7467
|
name?: string | undefined;
|
|
7466
7468
|
description?: string | undefined;
|
|
7467
7469
|
link_url?: string | undefined;
|
|
@@ -7510,7 +7512,7 @@ declare abstract class Client$12 extends Client$13 {
|
|
|
7510
7512
|
} | undefined;
|
|
7511
7513
|
recommend_item_infos?: {
|
|
7512
7514
|
item_id?: string | undefined;
|
|
7513
|
-
item_type?: "
|
|
7515
|
+
item_type?: "link" | "application" | undefined;
|
|
7514
7516
|
name?: string | undefined;
|
|
7515
7517
|
description?: string | undefined;
|
|
7516
7518
|
link_url?: string | undefined;
|
|
@@ -7527,7 +7529,7 @@ declare abstract class Client$12 extends Client$13 {
|
|
|
7527
7529
|
}[] | undefined;
|
|
7528
7530
|
distributed_recommend_item_infos?: {
|
|
7529
7531
|
item_id?: string | undefined;
|
|
7530
|
-
item_type?: "
|
|
7532
|
+
item_type?: "link" | "application" | undefined;
|
|
7531
7533
|
name?: string | undefined;
|
|
7532
7534
|
description?: string | undefined;
|
|
7533
7535
|
link_url?: string | undefined;
|
|
@@ -8290,7 +8292,7 @@ declare abstract class Client$12 extends Client$13 {
|
|
|
8290
8292
|
status?: number | undefined;
|
|
8291
8293
|
scene_type?: number | undefined;
|
|
8292
8294
|
payment_type?: number | undefined;
|
|
8293
|
-
create_source?: "developer_console" | "base" | "app_engine" | "bot_builder" | "aily" |
|
|
8295
|
+
create_source?: "unknown" | "developer_console" | "base" | "app_engine" | "bot_builder" | "aily" | undefined;
|
|
8294
8296
|
redirect_urls?: string[] | undefined;
|
|
8295
8297
|
online_version_id?: string | undefined;
|
|
8296
8298
|
unaudit_version_id?: string | undefined;
|
|
@@ -8367,7 +8369,7 @@ declare abstract class Client$12 extends Client$13 {
|
|
|
8367
8369
|
status?: number | undefined;
|
|
8368
8370
|
scene_type?: number | undefined;
|
|
8369
8371
|
payment_type?: number | undefined;
|
|
8370
|
-
create_source?: "developer_console" | "base" | "app_engine" | "bot_builder" | "aily" |
|
|
8372
|
+
create_source?: "unknown" | "developer_console" | "base" | "app_engine" | "bot_builder" | "aily" | undefined;
|
|
8371
8373
|
redirect_urls?: string[] | undefined;
|
|
8372
8374
|
online_version_id?: string | undefined;
|
|
8373
8375
|
unaudit_version_id?: string | undefined;
|
|
@@ -8456,7 +8458,7 @@ declare abstract class Client$12 extends Client$13 {
|
|
|
8456
8458
|
status?: number | undefined;
|
|
8457
8459
|
scene_type?: number | undefined;
|
|
8458
8460
|
payment_type?: number | undefined;
|
|
8459
|
-
create_source?: "developer_console" | "base" | "app_engine" | "bot_builder" | "aily" |
|
|
8461
|
+
create_source?: "unknown" | "developer_console" | "base" | "app_engine" | "bot_builder" | "aily" | undefined;
|
|
8460
8462
|
redirect_urls?: string[] | undefined;
|
|
8461
8463
|
online_version_id?: string | undefined;
|
|
8462
8464
|
unaudit_version_id?: string | undefined;
|
|
@@ -27583,7 +27585,7 @@ declare abstract class Client$U extends Client$V {
|
|
|
27583
27585
|
height?: number | undefined;
|
|
27584
27586
|
text?: {
|
|
27585
27587
|
text?: string | undefined;
|
|
27586
|
-
font_weight?: "
|
|
27588
|
+
font_weight?: "bold" | "regular" | undefined;
|
|
27587
27589
|
font_size?: number | undefined;
|
|
27588
27590
|
horizontal_align?: "left" | "center" | "right" | undefined;
|
|
27589
27591
|
vertical_align?: "top" | "mid" | "bottom" | undefined;
|
|
@@ -27749,7 +27751,7 @@ declare abstract class Client$U extends Client$V {
|
|
|
27749
27751
|
captions?: {
|
|
27750
27752
|
data?: {
|
|
27751
27753
|
text?: string | undefined;
|
|
27752
|
-
font_weight?: "
|
|
27754
|
+
font_weight?: "bold" | "regular" | undefined;
|
|
27753
27755
|
font_size?: number | undefined;
|
|
27754
27756
|
horizontal_align?: "left" | "center" | "right" | undefined;
|
|
27755
27757
|
vertical_align?: "top" | "mid" | "bottom" | undefined;
|
|
@@ -27948,7 +27950,7 @@ declare abstract class Client$U extends Client$V {
|
|
|
27948
27950
|
children?: string[] | undefined;
|
|
27949
27951
|
text?: {
|
|
27950
27952
|
text?: string | undefined;
|
|
27951
|
-
font_weight?: "
|
|
27953
|
+
font_weight?: "bold" | "regular" | undefined;
|
|
27952
27954
|
font_size?: number | undefined;
|
|
27953
27955
|
horizontal_align?: "left" | "center" | "right" | undefined;
|
|
27954
27956
|
vertical_align?: "top" | "mid" | "bottom" | undefined;
|
|
@@ -284507,6 +284509,7 @@ declare class Client extends Client$1 {
|
|
|
284507
284509
|
domain: string;
|
|
284508
284510
|
httpInstance: HttpInstance;
|
|
284509
284511
|
userAccessToken: UserAccessToken;
|
|
284512
|
+
private readonly userAgent;
|
|
284510
284513
|
constructor(params: IClientParams);
|
|
284511
284514
|
formatPayload(payload?: IPayload, options?: IRequestOptions): Promise<Required<IPayload>>;
|
|
284512
284515
|
request<T = any>(payload: AxiosRequestConfig, options?: IRequestOptions): Promise<T>;
|
|
@@ -293047,6 +293050,20 @@ interface IConstructorParams {
|
|
|
293047
293050
|
httpInstance?: HttpInstance;
|
|
293048
293051
|
autoReconnect?: boolean;
|
|
293049
293052
|
agent?: any;
|
|
293053
|
+
/** Caller tag appended to User-Agent as `source/<name>`. */
|
|
293054
|
+
source?: string;
|
|
293055
|
+
/** Fires once when the first WebSocket handshake succeeds. */
|
|
293056
|
+
onReady?: () => void;
|
|
293057
|
+
/**
|
|
293058
|
+
* Fires when the initial connect fails and the client either cannot retry
|
|
293059
|
+
* (autoReconnect=false) or exhausts `reconnectCount` retries. The callback
|
|
293060
|
+
* receives an Error describing the final failure.
|
|
293061
|
+
*/
|
|
293062
|
+
onError?: (err: Error) => void;
|
|
293063
|
+
/** Fires when the client enters the reconnect loop (i.e., after a disconnect). */
|
|
293064
|
+
onReconnecting?: () => void;
|
|
293065
|
+
/** Fires after the reconnect loop successfully re-establishes the connection. */
|
|
293066
|
+
onReconnected?: () => void;
|
|
293050
293067
|
}
|
|
293051
293068
|
declare class WSClient {
|
|
293052
293069
|
private wsConfig;
|
|
@@ -293060,7 +293077,21 @@ declare class WSClient {
|
|
|
293060
293077
|
private isConnecting;
|
|
293061
293078
|
private reconnectInfo;
|
|
293062
293079
|
private agent?;
|
|
293080
|
+
/** User-supplied state-transition callbacks. All optional. */
|
|
293081
|
+
private onReady?;
|
|
293082
|
+
private onError?;
|
|
293083
|
+
private onReconnecting?;
|
|
293084
|
+
private onReconnected?;
|
|
293085
|
+
private readonly userAgent;
|
|
293086
|
+
/** True if the WS has ever connected successfully in this client's
|
|
293087
|
+
* lifetime — used to distinguish first-connect from reconnect. */
|
|
293088
|
+
private hasEverConnected;
|
|
293063
293089
|
constructor(params: IConstructorParams);
|
|
293090
|
+
/**
|
|
293091
|
+
* Invoke a user-supplied callback safely: no-op if undefined, swallow any
|
|
293092
|
+
* exception to avoid breaking the WS state machine.
|
|
293093
|
+
*/
|
|
293094
|
+
private safeInvoke;
|
|
293064
293095
|
private pullConnectConfig;
|
|
293065
293096
|
private connect;
|
|
293066
293097
|
private reConnect;
|
|
@@ -293224,4 +293255,547 @@ interface RegisterAppResult {
|
|
|
293224
293255
|
|
|
293225
293256
|
declare function registerApp(options: RegisterAppOptions): Promise<RegisterAppResult>;
|
|
293226
293257
|
|
|
293227
|
-
|
|
293258
|
+
type ChatType = 'p2p' | 'group';
|
|
293259
|
+
interface NormalizedMessage {
|
|
293260
|
+
messageId: string;
|
|
293261
|
+
chatId: string;
|
|
293262
|
+
chatType: ChatType;
|
|
293263
|
+
senderId: string;
|
|
293264
|
+
senderName?: string;
|
|
293265
|
+
content: string;
|
|
293266
|
+
rawContentType: string;
|
|
293267
|
+
resources: ResourceDescriptor[];
|
|
293268
|
+
mentions: MentionInfo[];
|
|
293269
|
+
mentionAll: boolean;
|
|
293270
|
+
mentionedBot: boolean;
|
|
293271
|
+
rootId?: string;
|
|
293272
|
+
threadId?: string;
|
|
293273
|
+
replyToMessageId?: string;
|
|
293274
|
+
createTime: number;
|
|
293275
|
+
raw?: unknown;
|
|
293276
|
+
}
|
|
293277
|
+
interface ResourceDescriptor {
|
|
293278
|
+
type: 'image' | 'file' | 'audio' | 'video' | 'sticker';
|
|
293279
|
+
fileKey: string;
|
|
293280
|
+
fileName?: string;
|
|
293281
|
+
durationMs?: number;
|
|
293282
|
+
coverImageKey?: string;
|
|
293283
|
+
}
|
|
293284
|
+
interface MentionInfo {
|
|
293285
|
+
key: string;
|
|
293286
|
+
openId?: string;
|
|
293287
|
+
userId?: string;
|
|
293288
|
+
name?: string;
|
|
293289
|
+
isBot?: boolean;
|
|
293290
|
+
}
|
|
293291
|
+
interface BotIdentity {
|
|
293292
|
+
openId: string;
|
|
293293
|
+
userId?: string;
|
|
293294
|
+
name: string;
|
|
293295
|
+
}
|
|
293296
|
+
type SendInput = {
|
|
293297
|
+
markdown: string;
|
|
293298
|
+
} | {
|
|
293299
|
+
text: string;
|
|
293300
|
+
} | {
|
|
293301
|
+
post: object;
|
|
293302
|
+
} | {
|
|
293303
|
+
image: {
|
|
293304
|
+
source: string | Buffer;
|
|
293305
|
+
};
|
|
293306
|
+
} | {
|
|
293307
|
+
file: {
|
|
293308
|
+
source: string | Buffer;
|
|
293309
|
+
fileName: string;
|
|
293310
|
+
};
|
|
293311
|
+
} | {
|
|
293312
|
+
audio: {
|
|
293313
|
+
source: string | Buffer;
|
|
293314
|
+
duration?: number;
|
|
293315
|
+
};
|
|
293316
|
+
} | {
|
|
293317
|
+
video: {
|
|
293318
|
+
source: string | Buffer;
|
|
293319
|
+
duration?: number;
|
|
293320
|
+
coverImageKey?: string;
|
|
293321
|
+
};
|
|
293322
|
+
} | {
|
|
293323
|
+
card: object;
|
|
293324
|
+
} | {
|
|
293325
|
+
shareChat: {
|
|
293326
|
+
chatId: string;
|
|
293327
|
+
};
|
|
293328
|
+
} | {
|
|
293329
|
+
shareUser: {
|
|
293330
|
+
userId: string;
|
|
293331
|
+
};
|
|
293332
|
+
} | {
|
|
293333
|
+
sticker: {
|
|
293334
|
+
fileKey: string;
|
|
293335
|
+
};
|
|
293336
|
+
};
|
|
293337
|
+
interface MediaSource {
|
|
293338
|
+
source: string | Buffer;
|
|
293339
|
+
}
|
|
293340
|
+
interface SendOptions {
|
|
293341
|
+
replyTo?: string;
|
|
293342
|
+
replyInThread?: boolean;
|
|
293343
|
+
mentions?: MentionInfo[];
|
|
293344
|
+
}
|
|
293345
|
+
interface SendResult {
|
|
293346
|
+
messageId: string;
|
|
293347
|
+
chunkIds?: string[];
|
|
293348
|
+
}
|
|
293349
|
+
type StreamInput = {
|
|
293350
|
+
markdown: MarkdownStreamProducer;
|
|
293351
|
+
} | {
|
|
293352
|
+
card: {
|
|
293353
|
+
initial: object;
|
|
293354
|
+
producer: CardStreamProducer;
|
|
293355
|
+
};
|
|
293356
|
+
};
|
|
293357
|
+
type MarkdownStreamProducer = (controller: MarkdownStreamController) => Promise<void>;
|
|
293358
|
+
type CardStreamProducer = (controller: CardStreamController) => Promise<void>;
|
|
293359
|
+
interface MarkdownStreamController {
|
|
293360
|
+
append(chunk: string): Promise<void>;
|
|
293361
|
+
setContent(full: string): Promise<void>;
|
|
293362
|
+
readonly messageId: string;
|
|
293363
|
+
}
|
|
293364
|
+
interface CardStreamController {
|
|
293365
|
+
update(next: object | ((current: object) => object)): Promise<void>;
|
|
293366
|
+
readonly messageId: string;
|
|
293367
|
+
readonly current: object;
|
|
293368
|
+
}
|
|
293369
|
+
interface EventMap {
|
|
293370
|
+
message: (msg: NormalizedMessage) => void | Promise<void>;
|
|
293371
|
+
reject: (evt: RejectEvent) => void;
|
|
293372
|
+
cardAction: (evt: CardActionEvent) => void | Promise<void>;
|
|
293373
|
+
reaction: (evt: ReactionEvent) => void;
|
|
293374
|
+
botAdded: (evt: BotAddedEvent) => void;
|
|
293375
|
+
comment: (evt: CommentEvent) => void | Promise<void>;
|
|
293376
|
+
error: (err: LarkChannelError) => void;
|
|
293377
|
+
reconnecting: () => void;
|
|
293378
|
+
reconnected: () => void;
|
|
293379
|
+
}
|
|
293380
|
+
type EventName = keyof EventMap;
|
|
293381
|
+
/**
|
|
293382
|
+
* Reason for a {@link RejectEvent}. These are the set of policy-level
|
|
293383
|
+
* decisions that deliberately reject a message and inform the caller.
|
|
293384
|
+
*
|
|
293385
|
+
* Internal defenses (duplicate dedup, stale/expired timestamps, in-flight
|
|
293386
|
+
* processing lock) silently drop their targets — they are not reject
|
|
293387
|
+
* reasons, because the caller cannot act on them meaningfully.
|
|
293388
|
+
*/
|
|
293389
|
+
type RejectReason = 'group_not_allowed' | 'sender_not_allowed' | 'no_mention' | 'dm_disabled' | 'mention_all_blocked';
|
|
293390
|
+
interface RejectEvent {
|
|
293391
|
+
messageId: string;
|
|
293392
|
+
chatId: string;
|
|
293393
|
+
senderId: string;
|
|
293394
|
+
reason: RejectReason;
|
|
293395
|
+
}
|
|
293396
|
+
interface CardActionEvent {
|
|
293397
|
+
messageId: string;
|
|
293398
|
+
chatId: string;
|
|
293399
|
+
operator: {
|
|
293400
|
+
openId: string;
|
|
293401
|
+
userId?: string;
|
|
293402
|
+
name?: string;
|
|
293403
|
+
};
|
|
293404
|
+
action: {
|
|
293405
|
+
value: unknown;
|
|
293406
|
+
tag: string;
|
|
293407
|
+
name?: string;
|
|
293408
|
+
option?: string;
|
|
293409
|
+
};
|
|
293410
|
+
}
|
|
293411
|
+
interface ReactionEvent {
|
|
293412
|
+
messageId: string;
|
|
293413
|
+
operator: {
|
|
293414
|
+
openId: string;
|
|
293415
|
+
userId?: string;
|
|
293416
|
+
};
|
|
293417
|
+
emojiType: string;
|
|
293418
|
+
action: 'added' | 'removed';
|
|
293419
|
+
actionTime?: number;
|
|
293420
|
+
}
|
|
293421
|
+
interface BotAddedEvent {
|
|
293422
|
+
chatId: string;
|
|
293423
|
+
operator: {
|
|
293424
|
+
openId: string;
|
|
293425
|
+
userId?: string;
|
|
293426
|
+
};
|
|
293427
|
+
/**
|
|
293428
|
+
* The bot's own name as carried in the `name` field of the Feishu event.
|
|
293429
|
+
* Not the chat's name — that requires a separate `getChatInfo(chatId)`
|
|
293430
|
+
* call, which callers can do on demand.
|
|
293431
|
+
*/
|
|
293432
|
+
botName?: string;
|
|
293433
|
+
external?: boolean;
|
|
293434
|
+
raw?: unknown;
|
|
293435
|
+
}
|
|
293436
|
+
interface CommentEvent {
|
|
293437
|
+
fileToken: string;
|
|
293438
|
+
fileType: string;
|
|
293439
|
+
commentId: string;
|
|
293440
|
+
replyId?: string;
|
|
293441
|
+
operator: {
|
|
293442
|
+
openId: string;
|
|
293443
|
+
userId?: string;
|
|
293444
|
+
unionId?: string;
|
|
293445
|
+
};
|
|
293446
|
+
mentionedBot: boolean;
|
|
293447
|
+
timestamp: number;
|
|
293448
|
+
raw?: unknown;
|
|
293449
|
+
}
|
|
293450
|
+
type LarkChannelErrorCode = 'format_error' | 'target_revoked' | 'rate_limited' | 'permission_denied' | 'upload_failed' | 'ssrf_blocked' | 'send_timeout' | 'not_connected' | 'unknown';
|
|
293451
|
+
declare class LarkChannelError extends Error {
|
|
293452
|
+
code: LarkChannelErrorCode;
|
|
293453
|
+
cause?: unknown;
|
|
293454
|
+
context?: {
|
|
293455
|
+
to?: string;
|
|
293456
|
+
messageId?: string;
|
|
293457
|
+
attempt?: number;
|
|
293458
|
+
};
|
|
293459
|
+
constructor(code: LarkChannelErrorCode, message: string, opts?: {
|
|
293460
|
+
cause?: unknown;
|
|
293461
|
+
context?: LarkChannelError['context'];
|
|
293462
|
+
});
|
|
293463
|
+
}
|
|
293464
|
+
interface LarkChannelOptions {
|
|
293465
|
+
appId: string;
|
|
293466
|
+
appSecret: string;
|
|
293467
|
+
transport?: 'websocket' | 'webhook';
|
|
293468
|
+
webhook?: WebhookOptions;
|
|
293469
|
+
safety?: SafetyConfig;
|
|
293470
|
+
policy?: PolicyConfig;
|
|
293471
|
+
outbound?: OutboundConfig;
|
|
293472
|
+
logger?: Logger;
|
|
293473
|
+
loggerLevel?: LoggerLevel;
|
|
293474
|
+
cache?: Cache;
|
|
293475
|
+
domain?: Domain | string;
|
|
293476
|
+
httpInstance?: HttpInstance;
|
|
293477
|
+
/** Caller tag appended to User-Agent as `source/<name>`. */
|
|
293478
|
+
source?: string;
|
|
293479
|
+
includeRawInMessage?: boolean;
|
|
293480
|
+
}
|
|
293481
|
+
interface WebhookOptions {
|
|
293482
|
+
verificationToken?: string;
|
|
293483
|
+
encryptKey?: string;
|
|
293484
|
+
adapter?: 'express' | 'koa' | 'koa-router';
|
|
293485
|
+
}
|
|
293486
|
+
interface SafetyConfig {
|
|
293487
|
+
dedup?: {
|
|
293488
|
+
ttl?: number;
|
|
293489
|
+
maxEntries?: number;
|
|
293490
|
+
sweepIntervalMs?: number;
|
|
293491
|
+
};
|
|
293492
|
+
chatQueue?: {
|
|
293493
|
+
enabled?: boolean;
|
|
293494
|
+
};
|
|
293495
|
+
batch?: {
|
|
293496
|
+
text?: {
|
|
293497
|
+
delayMs?: number;
|
|
293498
|
+
longThresholdChars?: number;
|
|
293499
|
+
longDelayMs?: number;
|
|
293500
|
+
maxMessages?: number;
|
|
293501
|
+
maxChars?: number;
|
|
293502
|
+
};
|
|
293503
|
+
media?: {
|
|
293504
|
+
delayMs?: number;
|
|
293505
|
+
maxItems?: number;
|
|
293506
|
+
};
|
|
293507
|
+
};
|
|
293508
|
+
staleMessageWindowMs?: number;
|
|
293509
|
+
}
|
|
293510
|
+
interface PolicyConfig {
|
|
293511
|
+
groupAllowlist?: string[];
|
|
293512
|
+
dmMode?: 'open' | 'allowlist' | 'pair' | 'disabled';
|
|
293513
|
+
dmAllowlist?: string[];
|
|
293514
|
+
requireMention?: boolean;
|
|
293515
|
+
respondToMentionAll?: boolean;
|
|
293516
|
+
}
|
|
293517
|
+
interface OutboundConfig {
|
|
293518
|
+
textChunkLimit?: number;
|
|
293519
|
+
markdownConverter?: 'builtin' | ((md: string) => object);
|
|
293520
|
+
streamThrottleMs?: number;
|
|
293521
|
+
streamThrottleChars?: number;
|
|
293522
|
+
streamInitialText?: string;
|
|
293523
|
+
ssrfGuard?: boolean | {
|
|
293524
|
+
allowlist?: string[];
|
|
293525
|
+
};
|
|
293526
|
+
/**
|
|
293527
|
+
* Restrict local file paths accepted by media `source` to the listed
|
|
293528
|
+
* directories. When unset, only a POSIX blocklist (`/etc/`, `/proc/`,
|
|
293529
|
+
* `/sys/`, `/dev/`) is enforced as a safety net; when set, every path
|
|
293530
|
+
* must be inside one of these directories and symlink targets are
|
|
293531
|
+
* re-checked after `realpath` resolution.
|
|
293532
|
+
*/
|
|
293533
|
+
allowedFileDirs?: string[];
|
|
293534
|
+
retry?: {
|
|
293535
|
+
maxAttempts?: number;
|
|
293536
|
+
baseDelayMs?: number;
|
|
293537
|
+
};
|
|
293538
|
+
}
|
|
293539
|
+
interface ChatInfo {
|
|
293540
|
+
chatId: string;
|
|
293541
|
+
name?: string;
|
|
293542
|
+
description?: string;
|
|
293543
|
+
chatType: 'p2p' | 'group';
|
|
293544
|
+
ownerId?: string;
|
|
293545
|
+
memberCount?: number;
|
|
293546
|
+
}
|
|
293547
|
+
type ResourceType = 'image' | 'file';
|
|
293548
|
+
|
|
293549
|
+
type Unsubscribe = () => void;
|
|
293550
|
+
declare class LarkChannel {
|
|
293551
|
+
readonly rawClient: Client;
|
|
293552
|
+
rawWsClient?: WSClient;
|
|
293553
|
+
botIdentity?: BotIdentity;
|
|
293554
|
+
private readonly opts;
|
|
293555
|
+
private readonly logger;
|
|
293556
|
+
private readonly dispatcher;
|
|
293557
|
+
private readonly handlers;
|
|
293558
|
+
private connectPromise?;
|
|
293559
|
+
private connected;
|
|
293560
|
+
private readonly sender;
|
|
293561
|
+
private readonly safety;
|
|
293562
|
+
constructor(opts: LarkChannelOptions);
|
|
293563
|
+
connect(): Promise<void>;
|
|
293564
|
+
private doConnect;
|
|
293565
|
+
/**
|
|
293566
|
+
* Construct the underlying WSClient and wait for its `onReady` callback —
|
|
293567
|
+
* so `connect()` only resolves after the first WebSocket handshake
|
|
293568
|
+
* actually succeeds. Rejects on `onError` or if the handshake doesn't
|
|
293569
|
+
* complete within `timeoutMs`.
|
|
293570
|
+
*
|
|
293571
|
+
* Also wires `onReconnecting` / `onReconnected` callbacks to emit the
|
|
293572
|
+
* corresponding public events.
|
|
293573
|
+
*/
|
|
293574
|
+
private connectWebSocket;
|
|
293575
|
+
disconnect(): Promise<void>;
|
|
293576
|
+
on<K extends EventName>(name: K, handler: EventMap[K]): Unsubscribe;
|
|
293577
|
+
on(handlers: Partial<EventMap>): Unsubscribe;
|
|
293578
|
+
private attachSingle;
|
|
293579
|
+
send(to: string, input: SendInput, opts?: SendOptions): Promise<SendResult>;
|
|
293580
|
+
stream(to: string, input: StreamInput, opts?: SendOptions): Promise<SendResult>;
|
|
293581
|
+
updateCard(messageId: string, card: object): Promise<void>;
|
|
293582
|
+
/**
|
|
293583
|
+
* Edit an already-sent message's text/post content. Uses `im.v1.message.update`
|
|
293584
|
+
* which (per Feishu docs) only supports editing text and rich-text (post)
|
|
293585
|
+
* messages. For cards, use {@link updateCard} instead — a wrong attempt to
|
|
293586
|
+
* use this on a card would hit the same API and fail with a clearer
|
|
293587
|
+
* Feishu-side error.
|
|
293588
|
+
*/
|
|
293589
|
+
editMessage(messageId: string, text: string): Promise<void>;
|
|
293590
|
+
recallMessage(messageId: string): Promise<void>;
|
|
293591
|
+
/**
|
|
293592
|
+
* Add an emoji reaction to a message. Returns the `reaction_id` Feishu
|
|
293593
|
+
* assigned — stash it if you want to {@link removeReaction} later,
|
|
293594
|
+
* since the raw `im.message.reaction.*_v1` events don't carry the id.
|
|
293595
|
+
* Only the bot's own reactions can be removed.
|
|
293596
|
+
*/
|
|
293597
|
+
addReaction(messageId: string, emojiType: string): Promise<string>;
|
|
293598
|
+
/**
|
|
293599
|
+
* Remove a reaction by its `reaction_id` (the value returned from
|
|
293600
|
+
* {@link addReaction}). Only the bot's own reactions can be removed —
|
|
293601
|
+
* removing a user-added reaction will fail with a Feishu permission
|
|
293602
|
+
* error.
|
|
293603
|
+
*/
|
|
293604
|
+
removeReaction(messageId: string, reactionId: string): Promise<void>;
|
|
293605
|
+
/**
|
|
293606
|
+
* Convenience: remove the bot's reaction on `messageId` matching
|
|
293607
|
+
* `emojiType`, without needing the `reaction_id`. Lists the message's
|
|
293608
|
+
* reactions filtered by emoji, picks the one added by this bot
|
|
293609
|
+
* (operator_type === 'app'), and deletes it. Returns `true` if a
|
|
293610
|
+
* matching reaction was found and deleted, `false` otherwise (including
|
|
293611
|
+
* the case where the bot never added that emoji).
|
|
293612
|
+
*/
|
|
293613
|
+
removeReactionByEmoji(messageId: string, emojiType: string): Promise<boolean>;
|
|
293614
|
+
downloadResource(fileKey: string, type: ResourceType): Promise<Buffer>;
|
|
293615
|
+
getChatInfo(chatId: string): Promise<ChatInfo>;
|
|
293616
|
+
updatePolicy(partial: Partial<PolicyConfig>): void;
|
|
293617
|
+
getPolicy(): Readonly<PolicyConfig>;
|
|
293618
|
+
private fetchBotIdentity;
|
|
293619
|
+
private registerDispatcherHandlers;
|
|
293620
|
+
private emitError;
|
|
293621
|
+
}
|
|
293622
|
+
declare function createLarkChannel(opts: LarkChannelOptions): LarkChannel;
|
|
293623
|
+
|
|
293624
|
+
interface RawMessageEvent {
|
|
293625
|
+
sender: {
|
|
293626
|
+
sender_id: {
|
|
293627
|
+
open_id?: string;
|
|
293628
|
+
user_id?: string;
|
|
293629
|
+
union_id?: string;
|
|
293630
|
+
};
|
|
293631
|
+
sender_type?: string;
|
|
293632
|
+
tenant_key?: string;
|
|
293633
|
+
};
|
|
293634
|
+
message: {
|
|
293635
|
+
message_id: string;
|
|
293636
|
+
root_id?: string;
|
|
293637
|
+
parent_id?: string;
|
|
293638
|
+
create_time?: string;
|
|
293639
|
+
update_time?: string;
|
|
293640
|
+
chat_id: string;
|
|
293641
|
+
thread_id?: string;
|
|
293642
|
+
chat_type: 'p2p' | 'group';
|
|
293643
|
+
message_type: string;
|
|
293644
|
+
content: string;
|
|
293645
|
+
mentions?: RawMention[];
|
|
293646
|
+
};
|
|
293647
|
+
}
|
|
293648
|
+
interface RawMention {
|
|
293649
|
+
key: string;
|
|
293650
|
+
id: {
|
|
293651
|
+
open_id?: string;
|
|
293652
|
+
user_id?: string;
|
|
293653
|
+
union_id?: string;
|
|
293654
|
+
};
|
|
293655
|
+
name?: string;
|
|
293656
|
+
tenant_key?: string;
|
|
293657
|
+
}
|
|
293658
|
+
interface ApiMessageItem {
|
|
293659
|
+
message_id?: string;
|
|
293660
|
+
upper_message_id?: string;
|
|
293661
|
+
msg_type?: string;
|
|
293662
|
+
body?: {
|
|
293663
|
+
content?: string;
|
|
293664
|
+
};
|
|
293665
|
+
mentions?: RawMention[];
|
|
293666
|
+
sender?: {
|
|
293667
|
+
id?: string;
|
|
293668
|
+
id_type?: string;
|
|
293669
|
+
sender_type?: string;
|
|
293670
|
+
};
|
|
293671
|
+
create_time?: string | number;
|
|
293672
|
+
}
|
|
293673
|
+
|
|
293674
|
+
interface RawCardActionEvent {
|
|
293675
|
+
/**
|
|
293676
|
+
* Current shape (observed from `card.action.trigger` v2): message/chat ids
|
|
293677
|
+
* are nested under `context`. Top-level variants kept as fallback in case
|
|
293678
|
+
* older or alternate surfaces (webhook vs WS, older schema) still deliver
|
|
293679
|
+
* them at the root.
|
|
293680
|
+
*/
|
|
293681
|
+
context?: {
|
|
293682
|
+
open_message_id?: string;
|
|
293683
|
+
open_chat_id?: string;
|
|
293684
|
+
};
|
|
293685
|
+
open_message_id?: string;
|
|
293686
|
+
open_chat_id?: string;
|
|
293687
|
+
token?: string;
|
|
293688
|
+
operator?: {
|
|
293689
|
+
open_id?: string;
|
|
293690
|
+
user_id?: string;
|
|
293691
|
+
union_id?: string;
|
|
293692
|
+
name?: string;
|
|
293693
|
+
};
|
|
293694
|
+
action?: {
|
|
293695
|
+
value?: unknown;
|
|
293696
|
+
tag?: string;
|
|
293697
|
+
name?: string;
|
|
293698
|
+
option?: string;
|
|
293699
|
+
timezone?: string;
|
|
293700
|
+
};
|
|
293701
|
+
}
|
|
293702
|
+
declare function normalizeCardAction(event: RawCardActionEvent): CardActionEvent | null;
|
|
293703
|
+
|
|
293704
|
+
interface RawReactionEvent {
|
|
293705
|
+
message_id?: string;
|
|
293706
|
+
reaction_type?: {
|
|
293707
|
+
emoji_type?: string;
|
|
293708
|
+
};
|
|
293709
|
+
operator_type?: string;
|
|
293710
|
+
user_id?: {
|
|
293711
|
+
open_id?: string;
|
|
293712
|
+
user_id?: string | null;
|
|
293713
|
+
union_id?: string;
|
|
293714
|
+
};
|
|
293715
|
+
action_time?: string;
|
|
293716
|
+
}
|
|
293717
|
+
declare function normalizeReaction(event: RawReactionEvent, action: 'added' | 'removed'): ReactionEvent | null;
|
|
293718
|
+
|
|
293719
|
+
interface RawBotAddedEvent {
|
|
293720
|
+
chat_id?: string;
|
|
293721
|
+
operator_id?: {
|
|
293722
|
+
open_id?: string;
|
|
293723
|
+
user_id?: string | null;
|
|
293724
|
+
union_id?: string;
|
|
293725
|
+
};
|
|
293726
|
+
external?: boolean;
|
|
293727
|
+
/** The bot's name (NOT the chat's name). */
|
|
293728
|
+
name?: string;
|
|
293729
|
+
/** The bot's localized names. */
|
|
293730
|
+
i18n_names?: {
|
|
293731
|
+
zh_cn?: string;
|
|
293732
|
+
en_us?: string;
|
|
293733
|
+
ja_jp?: string;
|
|
293734
|
+
};
|
|
293735
|
+
}
|
|
293736
|
+
declare function normalizeBotAdded(event: RawBotAddedEvent, opts?: {
|
|
293737
|
+
includeRaw?: boolean;
|
|
293738
|
+
}): BotAddedEvent | null;
|
|
293739
|
+
|
|
293740
|
+
interface RawCommentEvent {
|
|
293741
|
+
app_id?: string;
|
|
293742
|
+
file_token?: string;
|
|
293743
|
+
file_type?: string;
|
|
293744
|
+
comment_id?: string;
|
|
293745
|
+
reply_id?: string;
|
|
293746
|
+
/** Whether the bot was mentioned. Top-level in current payload. */
|
|
293747
|
+
is_mentioned?: boolean;
|
|
293748
|
+
/** Millisecond timestamp of the event. */
|
|
293749
|
+
create_time?: string;
|
|
293750
|
+
notice_meta?: {
|
|
293751
|
+
from_user_id?: {
|
|
293752
|
+
open_id?: string;
|
|
293753
|
+
user_id?: string | null;
|
|
293754
|
+
union_id?: string;
|
|
293755
|
+
};
|
|
293756
|
+
to_user_id?: {
|
|
293757
|
+
open_id?: string;
|
|
293758
|
+
user_id?: string | null;
|
|
293759
|
+
union_id?: string;
|
|
293760
|
+
};
|
|
293761
|
+
file_token?: string;
|
|
293762
|
+
file_type?: string;
|
|
293763
|
+
timestamp?: string;
|
|
293764
|
+
is_mentioned?: boolean;
|
|
293765
|
+
notice_type?: string;
|
|
293766
|
+
};
|
|
293767
|
+
is_mention?: boolean;
|
|
293768
|
+
user_id?: {
|
|
293769
|
+
open_id?: string;
|
|
293770
|
+
user_id?: string | null;
|
|
293771
|
+
union_id?: string;
|
|
293772
|
+
};
|
|
293773
|
+
action_time?: string;
|
|
293774
|
+
}
|
|
293775
|
+
declare function normalizeComment(event: RawCommentEvent, opts?: {
|
|
293776
|
+
includeRaw?: boolean;
|
|
293777
|
+
}): CommentEvent | null;
|
|
293778
|
+
|
|
293779
|
+
interface NormalizeOptions {
|
|
293780
|
+
botIdentity: BotIdentity;
|
|
293781
|
+
stripBotMentions?: boolean;
|
|
293782
|
+
includeRaw?: boolean;
|
|
293783
|
+
fetchSubMessages?: (messageId: string) => Promise<ApiMessageItem[]>;
|
|
293784
|
+
resolveUserName?: (openId: string) => string | undefined;
|
|
293785
|
+
resolveSenderName?: (openId: string) => string | undefined;
|
|
293786
|
+
batchResolveNames?: (openIds: string[]) => Promise<void>;
|
|
293787
|
+
}
|
|
293788
|
+
/**
|
|
293789
|
+
* Normalize a raw Feishu message event into a NormalizedMessage.
|
|
293790
|
+
*
|
|
293791
|
+
* Pipeline:
|
|
293792
|
+
* 1. Extract mentions → build key/openId maps + bot detection
|
|
293793
|
+
* 2. For `interactive` type, fetch full v2 card content if capability available
|
|
293794
|
+
* 3. Build ConvertContext with injected capabilities
|
|
293795
|
+
* 4. Dispatch to the matching converter (uniform error containment inside)
|
|
293796
|
+
* 5. Run resolveMentions second pass — replace placeholders with @name
|
|
293797
|
+
* 6. Assemble and return NormalizedMessage
|
|
293798
|
+
*/
|
|
293799
|
+
declare function normalize(event: RawMessageEvent, opts: NormalizeOptions): Promise<NormalizedMessage>;
|
|
293800
|
+
|
|
293801
|
+
export { AESCipher, Aily, ApiMessageItem, AppType, BotAddedEvent, BotIdentity, CAppTicket, CTenantAccessToken, Cache, CardActionEvent, CardActionHandler, CardStreamController, CardStreamProducer, ChatInfo, ChatType, Client, CommentEvent, Domain, EventDispatcher, IHandles as EventHandles, EventMap, EventName, HttpInstance, HttpRequestOptions, InteractiveCard, InteractiveCardActionEvent, InteractiveCardActionItem, InteractiveCardButtonActionItem, InteractiveCardDatePickerActionItem, InteractiveCardDivElement, InteractiveCardDividerElement, InteractiveCardElement, InteractiveCardField, InteractiveCardImageElement, InteractiveCardImageItem, InteractiveCardLarkMdItem, InteractiveCardMarkdownElement, InteractiveCardNoteElement, InteractiveCardOverflowActionItem, InteractiveCardPlainTextItem, InteractiveCardSelectMenuActionItem, InteractiveCardTextItem, InteractiveCardTitle, InteractiveCardUrlItem, InterfaceCardActionElement, LarkChannel, LarkChannelError, LarkChannelErrorCode, LarkChannelOptions, LoggerLevel, MarkdownStreamController, MarkdownStreamProducer, MediaSource, MentionInfo, NormalizeOptions, NormalizedMessage, OutboundConfig, PolicyConfig, RawBotAddedEvent, RawCardActionEvent, RawCommentEvent, RawMessageEvent, RawReactionEvent, ReactionEvent, RejectEvent, RejectReason, ResourceDescriptor, ResourceType, SafetyConfig, SendInput, SendOptions, SendResult, StreamInput, WSClient, WebhookOptions, adaptDefault, adaptExpress, adaptKoa, adaptKoaRouter, createLarkChannel, defaultHttpInstance, generateChallenge, messageCard, normalize, normalizeBotAdded, normalizeCardAction, normalizeComment, normalizeReaction, registerApp, withAll, withHelpDeskCredential, withTenantKey, withTenantToken, withUserAccessToken };
|