@meet-im/meet-bot-jssdk 0.0.7 → 1.1.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/dist/index.d.cts CHANGED
@@ -26,12 +26,21 @@ interface MsgContent {
26
26
  timestamp?: number;
27
27
  fromUid?: number;
28
28
  atIds?: number[];
29
+ quoteSeqID?: number;
29
30
  extraInfo?: ExtraInfo;
30
31
  sessionInfo?: SessionInfo;
31
32
  }
32
33
  interface BotUpdate {
33
34
  message?: MsgContent;
34
35
  }
36
+ interface BotMsgUpdate {
37
+ message: MsgContent;
38
+ }
39
+ type QuoteMsgMap = Record<string, MsgContent>;
40
+ interface GetUpdatesV2Result {
41
+ msgs: BotMsgUpdate[];
42
+ quoteMsgMap: QuoteMsgMap;
43
+ }
35
44
  interface BotUser {
36
45
  id: number;
37
46
  name: string;
@@ -81,6 +90,7 @@ interface MeetBotConfig {
81
90
  pollingLimit?: number;
82
91
  longPollingTimeout?: number;
83
92
  logLevel?: LogLevel;
93
+ useV2?: boolean;
84
94
  }
85
95
  interface GetUpdatesOptions {
86
96
  token: string;
@@ -161,9 +171,14 @@ interface GetAccessURLParams {
161
171
  sessionType: number;
162
172
  seqId: number;
163
173
  fileId: number;
174
+ companyId?: number;
164
175
  'x-oss-process'?: string;
165
- origin?: string;
166
- bestDomain?: string;
176
+ printResult?: string;
177
+ }
178
+ interface GetAccessURLBySessionParams {
179
+ sessionInfo: SessionInfo;
180
+ seqId: number;
181
+ fileId: number;
167
182
  printResult?: string;
168
183
  }
169
184
  interface AccessURLResult {
@@ -201,6 +216,37 @@ interface ReceivedAttachmentInfo {
201
216
  mimeType?: string;
202
217
  }
203
218
 
219
+ interface MeetUser {
220
+ userID: number;
221
+ nickName: string;
222
+ nickNamePinyin?: string;
223
+ aliasName?: string;
224
+ aliasNamePinyin?: string;
225
+ gender?: number;
226
+ birthday?: string;
227
+ avatar?: string;
228
+ avatarUrl?: string;
229
+ email?: string;
230
+ mobile?: string;
231
+ jobNumber?: string;
232
+ tag?: string;
233
+ tags?: string[];
234
+ companyId?: number;
235
+ status?: number;
236
+ statusMsg?: string[];
237
+ sourceType?: number;
238
+ employeeStatus?: number;
239
+ cleanStatus?: number;
240
+ deletedAt?: number;
241
+ isDepartmentAdmin?: boolean;
242
+ isHide?: boolean;
243
+ sort?: number;
244
+ oaUID?: number;
245
+ msgDelTimeStamp?: number;
246
+ userType?: number;
247
+ updatedAt?: number;
248
+ }
249
+
204
250
  declare class MeetBotError extends Error {
205
251
  readonly code: ErrorCode;
206
252
  constructor(message: string, code: ErrorCode);
@@ -212,10 +258,13 @@ declare class ApiError extends MeetBotError {
212
258
  }
213
259
  declare class NetworkError extends MeetBotError {
214
260
  readonly cause?: Error;
215
- constructor(message: string, cause?: Error);
261
+ readonly httpStatus?: number;
262
+ readonly responseSnippet?: string;
263
+ constructor(message: string, cause?: Error, httpStatus?: number, responseSnippet?: string);
216
264
  }
217
265
  declare class TimeoutError extends MeetBotError {
218
- constructor(message: string);
266
+ readonly isLocal: boolean;
267
+ constructor(message: string, isLocal?: boolean);
219
268
  }
220
269
  declare class ValidationError extends MeetBotError {
221
270
  readonly field: string;
@@ -223,9 +272,34 @@ declare class ValidationError extends MeetBotError {
223
272
  constructor(message: string, field: string, value: unknown);
224
273
  }
225
274
 
275
+ interface UserCacheOptions {
276
+ ttl?: number;
277
+ }
278
+ declare class UserCache {
279
+ private byId;
280
+ private byNickName;
281
+ private byAliasName;
282
+ private loadedAt;
283
+ private readonly ttl;
284
+ private loading;
285
+ constructor(options?: UserCacheOptions);
286
+ isExpired(): boolean;
287
+ load(fetchAll: () => Promise<MeetUser[]>): Promise<void>;
288
+ private rebuild;
289
+ ensureLoaded(fetchAll: () => Promise<MeetUser[]>): Promise<void>;
290
+ getById(userId: number): MeetUser | undefined;
291
+ getByIds(userIds: number[]): Map<number, MeetUser>;
292
+ getByName(name: string): MeetUser[];
293
+ searchByName(query: string): MeetUser[];
294
+ get size(): number;
295
+ }
296
+
226
297
  type EventHandler<T = unknown> = (data: T) => void;
227
298
  interface Events {
228
- message: BotUpdate['message'];
299
+ message: {
300
+ message: MsgContent;
301
+ quoteMsgMap: QuoteMsgMap;
302
+ };
229
303
  error: Error;
230
304
  polling_start: void;
231
305
  polling_stop: void;
@@ -235,11 +309,15 @@ declare class MeetBot {
235
309
  private readonly baseUrl;
236
310
  private readonly pollingLimit;
237
311
  private readonly longPollingTimeout;
312
+ private readonly useV2;
238
313
  private readonly eventHandlers;
239
314
  private polling;
240
315
  private offset;
241
316
  private abortController;
242
- constructor(config: MeetBotConfig);
317
+ private readonly userCache;
318
+ constructor(config: MeetBotConfig & {
319
+ userCacheOptions?: UserCacheOptions;
320
+ });
243
321
  on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
244
322
  off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
245
323
  private emit;
@@ -251,13 +329,23 @@ declare class MeetBot {
251
329
  offset?: number;
252
330
  limit?: number;
253
331
  }): Promise<BotUpdate[]>;
332
+ getUpdatesV2(options?: {
333
+ timeout?: number;
334
+ limit?: number;
335
+ }): Promise<GetUpdatesV2Result>;
254
336
  sendMessage(sessionInfo: SessionInfo, msgContent: MsgContent): Promise<SendMessageResult>;
255
337
  getUploadURL(params: Omit<GetUploadURLParams, 'fileType'>): Promise<UploadURLResult>;
256
338
  getMultiPartUploadURL(params: Omit<GetMultiPartUploadURLParams, 'fileType'>): Promise<MultiPartUploadURLResult>;
257
339
  completeMultipartUpload(params: CompleteMultipartUploadParams): Promise<CompleteMultipartUploadResult>;
258
- getAccessURL(params: GetAccessURLParams): Promise<AccessURLResult>;
340
+ getAccessURL(params: GetAccessURLParams | GetAccessURLBySessionParams): Promise<AccessURLResult>;
259
341
  uploadFile(buffer: Buffer, options: UploadFileOptions): Promise<UploadFileResult>;
260
342
  sendMedia(sessionInfo: SessionInfo, options: SendMediaOptions): Promise<SendMessageResult>;
343
+ refreshUserCache(): Promise<void>;
344
+ getUserById(userId: number): Promise<MeetUser | undefined>;
345
+ getUserByIds(userIds: number[]): Promise<Map<number, MeetUser>>;
346
+ getUserByName(name: string): Promise<MeetUser[]>;
347
+ searchUserByName(query: string): Promise<MeetUser[]>;
348
+ get userCacheSize(): number;
261
349
  private sleep;
262
350
  }
263
351
 
@@ -286,6 +374,11 @@ declare function computeMD5(buffer: Buffer): Promise<string>;
286
374
  declare function uploadFile(token: string, buffer: Buffer, options: UploadFileOptions, baseUrl?: string): Promise<UploadFileResult>;
287
375
  declare function sendMediaMessage(token: string, sessionInfo: SessionInfo, options: SendMediaOptions, baseUrl?: string): Promise<SendMessageResult>;
288
376
 
377
+ declare function getUsers(params: {
378
+ token: string;
379
+ baseUrl?: string;
380
+ }): Promise<MeetUser[]>;
381
+
289
382
  interface GetUpdatesParams {
290
383
  token: string;
291
384
  baseUrl?: string;
@@ -294,6 +387,13 @@ interface GetUpdatesParams {
294
387
  limit?: number;
295
388
  }
296
389
  declare function getUpdates(params: GetUpdatesParams): Promise<BotUpdate[]>;
390
+ interface GetUpdatesV2Params {
391
+ token: string;
392
+ baseUrl?: string;
393
+ timeout?: number;
394
+ limit?: number;
395
+ }
396
+ declare function getUpdatesV2(params: GetUpdatesV2Params): Promise<GetUpdatesV2Result>;
297
397
  interface SendMessageParams {
298
398
  token: string;
299
399
  baseUrl?: string;
@@ -339,6 +439,13 @@ declare const CHUNK_RULES: readonly [{
339
439
  readonly maxSize: number;
340
440
  readonly chunks: 50;
341
441
  }];
442
+ declare const SESSION_TYPE: {
443
+ readonly PRIVATE: 1;
444
+ readonly GROUP: 3;
445
+ readonly CHANNEL: 4;
446
+ };
342
447
  declare function getChunkNum(size: number): number;
448
+ declare function getConvID(firstID: number, secondID: number, sessionType: number, companyID?: number): string;
449
+ declare function getQuoteMsgKey(convID: string, seqID: number): string;
343
450
 
344
- export { API, type AccessURLResult, ApiError, type ApiErrorResponse, type ApiResponse, type AttachmentInfo, type BotChat, type BotFile, type BotMsg, type BotUpdate, type BotUser, CHUNK_RULES, type ChatType, type CompleteMultipartUploadParams, type CompleteMultipartUploadResult, DEFAULT_BASE_URL, type ErrorCode, type ExtraInfo, type GetAccessURLParams, type GetMultiPartUploadURLParams, type GetUpdatesOptions, type GetUploadURLParams, HTTP, type LogLevel, MeetBot, type MeetBotConfig, MeetBotError, type MsgContent, type MsgType, type MultiPartUploadURLResult, NetworkError, POLLING, type PollingOptions, type ReceivedAttachmentInfo, type SendMediaOptions, type SendMessageOptions, type SendMessageResult, type SessionInfo, type SessionType, TimeoutError, UPLOAD, type UploadFileOptions, type UploadFileResult, type UploadPart, type UploadProgress, type UploadURLResult, ValidationError, completeMultipartUpload, computeMD5, getAccessURL, getChunkNum, getMultiPartUploadURL, getUpdates, getUploadURL, sendMediaMessage, sendMessage, uploadFile };
451
+ export { API, type AccessURLResult, ApiError, type ApiErrorResponse, type ApiResponse, type AttachmentInfo, type BotChat, type BotFile, type BotMsg, type BotMsgUpdate, type BotUpdate, type BotUser, CHUNK_RULES, type ChatType, type CompleteMultipartUploadParams, type CompleteMultipartUploadResult, DEFAULT_BASE_URL, type ErrorCode, type ExtraInfo, type GetAccessURLBySessionParams, type GetAccessURLParams, type GetMultiPartUploadURLParams, type GetUpdatesOptions, type GetUpdatesV2Result, type GetUploadURLParams, HTTP, type LogLevel, MeetBot, type MeetBotConfig, MeetBotError, type MeetUser, type MsgContent, type MsgType, type MultiPartUploadURLResult, NetworkError, POLLING, type PollingOptions, type QuoteMsgMap, type ReceivedAttachmentInfo, SESSION_TYPE, type SendMediaOptions, type SendMessageOptions, type SendMessageResult, type SessionInfo, type SessionType, TimeoutError, UPLOAD, type UploadFileOptions, type UploadFileResult, type UploadPart, type UploadProgress, type UploadURLResult, UserCache, type UserCacheOptions, ValidationError, completeMultipartUpload, computeMD5, getAccessURL, getChunkNum, getConvID, getMultiPartUploadURL, getQuoteMsgKey, getUpdates, getUpdatesV2, getUploadURL, getUsers, sendMediaMessage, sendMessage, uploadFile };
package/dist/index.d.ts CHANGED
@@ -26,12 +26,21 @@ interface MsgContent {
26
26
  timestamp?: number;
27
27
  fromUid?: number;
28
28
  atIds?: number[];
29
+ quoteSeqID?: number;
29
30
  extraInfo?: ExtraInfo;
30
31
  sessionInfo?: SessionInfo;
31
32
  }
32
33
  interface BotUpdate {
33
34
  message?: MsgContent;
34
35
  }
36
+ interface BotMsgUpdate {
37
+ message: MsgContent;
38
+ }
39
+ type QuoteMsgMap = Record<string, MsgContent>;
40
+ interface GetUpdatesV2Result {
41
+ msgs: BotMsgUpdate[];
42
+ quoteMsgMap: QuoteMsgMap;
43
+ }
35
44
  interface BotUser {
36
45
  id: number;
37
46
  name: string;
@@ -81,6 +90,7 @@ interface MeetBotConfig {
81
90
  pollingLimit?: number;
82
91
  longPollingTimeout?: number;
83
92
  logLevel?: LogLevel;
93
+ useV2?: boolean;
84
94
  }
85
95
  interface GetUpdatesOptions {
86
96
  token: string;
@@ -161,9 +171,14 @@ interface GetAccessURLParams {
161
171
  sessionType: number;
162
172
  seqId: number;
163
173
  fileId: number;
174
+ companyId?: number;
164
175
  'x-oss-process'?: string;
165
- origin?: string;
166
- bestDomain?: string;
176
+ printResult?: string;
177
+ }
178
+ interface GetAccessURLBySessionParams {
179
+ sessionInfo: SessionInfo;
180
+ seqId: number;
181
+ fileId: number;
167
182
  printResult?: string;
168
183
  }
169
184
  interface AccessURLResult {
@@ -201,6 +216,37 @@ interface ReceivedAttachmentInfo {
201
216
  mimeType?: string;
202
217
  }
203
218
 
219
+ interface MeetUser {
220
+ userID: number;
221
+ nickName: string;
222
+ nickNamePinyin?: string;
223
+ aliasName?: string;
224
+ aliasNamePinyin?: string;
225
+ gender?: number;
226
+ birthday?: string;
227
+ avatar?: string;
228
+ avatarUrl?: string;
229
+ email?: string;
230
+ mobile?: string;
231
+ jobNumber?: string;
232
+ tag?: string;
233
+ tags?: string[];
234
+ companyId?: number;
235
+ status?: number;
236
+ statusMsg?: string[];
237
+ sourceType?: number;
238
+ employeeStatus?: number;
239
+ cleanStatus?: number;
240
+ deletedAt?: number;
241
+ isDepartmentAdmin?: boolean;
242
+ isHide?: boolean;
243
+ sort?: number;
244
+ oaUID?: number;
245
+ msgDelTimeStamp?: number;
246
+ userType?: number;
247
+ updatedAt?: number;
248
+ }
249
+
204
250
  declare class MeetBotError extends Error {
205
251
  readonly code: ErrorCode;
206
252
  constructor(message: string, code: ErrorCode);
@@ -212,10 +258,13 @@ declare class ApiError extends MeetBotError {
212
258
  }
213
259
  declare class NetworkError extends MeetBotError {
214
260
  readonly cause?: Error;
215
- constructor(message: string, cause?: Error);
261
+ readonly httpStatus?: number;
262
+ readonly responseSnippet?: string;
263
+ constructor(message: string, cause?: Error, httpStatus?: number, responseSnippet?: string);
216
264
  }
217
265
  declare class TimeoutError extends MeetBotError {
218
- constructor(message: string);
266
+ readonly isLocal: boolean;
267
+ constructor(message: string, isLocal?: boolean);
219
268
  }
220
269
  declare class ValidationError extends MeetBotError {
221
270
  readonly field: string;
@@ -223,9 +272,34 @@ declare class ValidationError extends MeetBotError {
223
272
  constructor(message: string, field: string, value: unknown);
224
273
  }
225
274
 
275
+ interface UserCacheOptions {
276
+ ttl?: number;
277
+ }
278
+ declare class UserCache {
279
+ private byId;
280
+ private byNickName;
281
+ private byAliasName;
282
+ private loadedAt;
283
+ private readonly ttl;
284
+ private loading;
285
+ constructor(options?: UserCacheOptions);
286
+ isExpired(): boolean;
287
+ load(fetchAll: () => Promise<MeetUser[]>): Promise<void>;
288
+ private rebuild;
289
+ ensureLoaded(fetchAll: () => Promise<MeetUser[]>): Promise<void>;
290
+ getById(userId: number): MeetUser | undefined;
291
+ getByIds(userIds: number[]): Map<number, MeetUser>;
292
+ getByName(name: string): MeetUser[];
293
+ searchByName(query: string): MeetUser[];
294
+ get size(): number;
295
+ }
296
+
226
297
  type EventHandler<T = unknown> = (data: T) => void;
227
298
  interface Events {
228
- message: BotUpdate['message'];
299
+ message: {
300
+ message: MsgContent;
301
+ quoteMsgMap: QuoteMsgMap;
302
+ };
229
303
  error: Error;
230
304
  polling_start: void;
231
305
  polling_stop: void;
@@ -235,11 +309,15 @@ declare class MeetBot {
235
309
  private readonly baseUrl;
236
310
  private readonly pollingLimit;
237
311
  private readonly longPollingTimeout;
312
+ private readonly useV2;
238
313
  private readonly eventHandlers;
239
314
  private polling;
240
315
  private offset;
241
316
  private abortController;
242
- constructor(config: MeetBotConfig);
317
+ private readonly userCache;
318
+ constructor(config: MeetBotConfig & {
319
+ userCacheOptions?: UserCacheOptions;
320
+ });
243
321
  on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
244
322
  off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
245
323
  private emit;
@@ -251,13 +329,23 @@ declare class MeetBot {
251
329
  offset?: number;
252
330
  limit?: number;
253
331
  }): Promise<BotUpdate[]>;
332
+ getUpdatesV2(options?: {
333
+ timeout?: number;
334
+ limit?: number;
335
+ }): Promise<GetUpdatesV2Result>;
254
336
  sendMessage(sessionInfo: SessionInfo, msgContent: MsgContent): Promise<SendMessageResult>;
255
337
  getUploadURL(params: Omit<GetUploadURLParams, 'fileType'>): Promise<UploadURLResult>;
256
338
  getMultiPartUploadURL(params: Omit<GetMultiPartUploadURLParams, 'fileType'>): Promise<MultiPartUploadURLResult>;
257
339
  completeMultipartUpload(params: CompleteMultipartUploadParams): Promise<CompleteMultipartUploadResult>;
258
- getAccessURL(params: GetAccessURLParams): Promise<AccessURLResult>;
340
+ getAccessURL(params: GetAccessURLParams | GetAccessURLBySessionParams): Promise<AccessURLResult>;
259
341
  uploadFile(buffer: Buffer, options: UploadFileOptions): Promise<UploadFileResult>;
260
342
  sendMedia(sessionInfo: SessionInfo, options: SendMediaOptions): Promise<SendMessageResult>;
343
+ refreshUserCache(): Promise<void>;
344
+ getUserById(userId: number): Promise<MeetUser | undefined>;
345
+ getUserByIds(userIds: number[]): Promise<Map<number, MeetUser>>;
346
+ getUserByName(name: string): Promise<MeetUser[]>;
347
+ searchUserByName(query: string): Promise<MeetUser[]>;
348
+ get userCacheSize(): number;
261
349
  private sleep;
262
350
  }
263
351
 
@@ -286,6 +374,11 @@ declare function computeMD5(buffer: Buffer): Promise<string>;
286
374
  declare function uploadFile(token: string, buffer: Buffer, options: UploadFileOptions, baseUrl?: string): Promise<UploadFileResult>;
287
375
  declare function sendMediaMessage(token: string, sessionInfo: SessionInfo, options: SendMediaOptions, baseUrl?: string): Promise<SendMessageResult>;
288
376
 
377
+ declare function getUsers(params: {
378
+ token: string;
379
+ baseUrl?: string;
380
+ }): Promise<MeetUser[]>;
381
+
289
382
  interface GetUpdatesParams {
290
383
  token: string;
291
384
  baseUrl?: string;
@@ -294,6 +387,13 @@ interface GetUpdatesParams {
294
387
  limit?: number;
295
388
  }
296
389
  declare function getUpdates(params: GetUpdatesParams): Promise<BotUpdate[]>;
390
+ interface GetUpdatesV2Params {
391
+ token: string;
392
+ baseUrl?: string;
393
+ timeout?: number;
394
+ limit?: number;
395
+ }
396
+ declare function getUpdatesV2(params: GetUpdatesV2Params): Promise<GetUpdatesV2Result>;
297
397
  interface SendMessageParams {
298
398
  token: string;
299
399
  baseUrl?: string;
@@ -339,6 +439,13 @@ declare const CHUNK_RULES: readonly [{
339
439
  readonly maxSize: number;
340
440
  readonly chunks: 50;
341
441
  }];
442
+ declare const SESSION_TYPE: {
443
+ readonly PRIVATE: 1;
444
+ readonly GROUP: 3;
445
+ readonly CHANNEL: 4;
446
+ };
342
447
  declare function getChunkNum(size: number): number;
448
+ declare function getConvID(firstID: number, secondID: number, sessionType: number, companyID?: number): string;
449
+ declare function getQuoteMsgKey(convID: string, seqID: number): string;
343
450
 
344
- export { API, type AccessURLResult, ApiError, type ApiErrorResponse, type ApiResponse, type AttachmentInfo, type BotChat, type BotFile, type BotMsg, type BotUpdate, type BotUser, CHUNK_RULES, type ChatType, type CompleteMultipartUploadParams, type CompleteMultipartUploadResult, DEFAULT_BASE_URL, type ErrorCode, type ExtraInfo, type GetAccessURLParams, type GetMultiPartUploadURLParams, type GetUpdatesOptions, type GetUploadURLParams, HTTP, type LogLevel, MeetBot, type MeetBotConfig, MeetBotError, type MsgContent, type MsgType, type MultiPartUploadURLResult, NetworkError, POLLING, type PollingOptions, type ReceivedAttachmentInfo, type SendMediaOptions, type SendMessageOptions, type SendMessageResult, type SessionInfo, type SessionType, TimeoutError, UPLOAD, type UploadFileOptions, type UploadFileResult, type UploadPart, type UploadProgress, type UploadURLResult, ValidationError, completeMultipartUpload, computeMD5, getAccessURL, getChunkNum, getMultiPartUploadURL, getUpdates, getUploadURL, sendMediaMessage, sendMessage, uploadFile };
451
+ export { API, type AccessURLResult, ApiError, type ApiErrorResponse, type ApiResponse, type AttachmentInfo, type BotChat, type BotFile, type BotMsg, type BotMsgUpdate, type BotUpdate, type BotUser, CHUNK_RULES, type ChatType, type CompleteMultipartUploadParams, type CompleteMultipartUploadResult, DEFAULT_BASE_URL, type ErrorCode, type ExtraInfo, type GetAccessURLBySessionParams, type GetAccessURLParams, type GetMultiPartUploadURLParams, type GetUpdatesOptions, type GetUpdatesV2Result, type GetUploadURLParams, HTTP, type LogLevel, MeetBot, type MeetBotConfig, MeetBotError, type MeetUser, type MsgContent, type MsgType, type MultiPartUploadURLResult, NetworkError, POLLING, type PollingOptions, type QuoteMsgMap, type ReceivedAttachmentInfo, SESSION_TYPE, type SendMediaOptions, type SendMessageOptions, type SendMessageResult, type SessionInfo, type SessionType, TimeoutError, UPLOAD, type UploadFileOptions, type UploadFileResult, type UploadPart, type UploadProgress, type UploadURLResult, UserCache, type UserCacheOptions, ValidationError, completeMultipartUpload, computeMD5, getAccessURL, getChunkNum, getConvID, getMultiPartUploadURL, getQuoteMsgKey, getUpdates, getUpdatesV2, getUploadURL, getUsers, sendMediaMessage, sendMessage, uploadFile };