@meet-im/meet-bot-jssdk 1.0.0 → 1.2.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
@@ -91,6 +91,7 @@ interface MeetBotConfig {
91
91
  longPollingTimeout?: number;
92
92
  logLevel?: LogLevel;
93
93
  useV2?: boolean;
94
+ userAgent?: string;
94
95
  }
95
96
  interface GetUpdatesOptions {
96
97
  token: string;
@@ -216,6 +217,37 @@ interface ReceivedAttachmentInfo {
216
217
  mimeType?: string;
217
218
  }
218
219
 
220
+ interface MeetUser {
221
+ userID: number;
222
+ nickName: string;
223
+ nickNamePinyin?: string;
224
+ aliasName?: string;
225
+ aliasNamePinyin?: string;
226
+ gender?: number;
227
+ birthday?: string;
228
+ avatar?: string;
229
+ avatarUrl?: string;
230
+ email?: string;
231
+ mobile?: string;
232
+ jobNumber?: string;
233
+ tag?: string;
234
+ tags?: string[];
235
+ companyId?: number;
236
+ status?: number;
237
+ statusMsg?: string[];
238
+ sourceType?: number;
239
+ employeeStatus?: number;
240
+ cleanStatus?: number;
241
+ deletedAt?: number;
242
+ isDepartmentAdmin?: boolean;
243
+ isHide?: boolean;
244
+ sort?: number;
245
+ oaUID?: number;
246
+ msgDelTimeStamp?: number;
247
+ userType?: number;
248
+ updatedAt?: number;
249
+ }
250
+
219
251
  declare class MeetBotError extends Error {
220
252
  readonly code: ErrorCode;
221
253
  constructor(message: string, code: ErrorCode);
@@ -227,10 +259,13 @@ declare class ApiError extends MeetBotError {
227
259
  }
228
260
  declare class NetworkError extends MeetBotError {
229
261
  readonly cause?: Error;
230
- constructor(message: string, cause?: Error);
262
+ readonly httpStatus?: number;
263
+ readonly responseSnippet?: string;
264
+ constructor(message: string, cause?: Error, httpStatus?: number, responseSnippet?: string);
231
265
  }
232
266
  declare class TimeoutError extends MeetBotError {
233
- constructor(message: string);
267
+ readonly isLocal: boolean;
268
+ constructor(message: string, isLocal?: boolean);
234
269
  }
235
270
  declare class ValidationError extends MeetBotError {
236
271
  readonly field: string;
@@ -238,6 +273,28 @@ declare class ValidationError extends MeetBotError {
238
273
  constructor(message: string, field: string, value: unknown);
239
274
  }
240
275
 
276
+ interface UserCacheOptions {
277
+ ttl?: number;
278
+ }
279
+ declare class UserCache {
280
+ private byId;
281
+ private byNickName;
282
+ private byAliasName;
283
+ private loadedAt;
284
+ private readonly ttl;
285
+ private loading;
286
+ constructor(options?: UserCacheOptions);
287
+ isExpired(): boolean;
288
+ load(fetchAll: () => Promise<MeetUser[]>): Promise<void>;
289
+ private rebuild;
290
+ ensureLoaded(fetchAll: () => Promise<MeetUser[]>): Promise<void>;
291
+ getById(userId: number): MeetUser | undefined;
292
+ getByIds(userIds: number[]): Map<number, MeetUser>;
293
+ getByName(name: string): MeetUser[];
294
+ searchByName(query: string): MeetUser[];
295
+ get size(): number;
296
+ }
297
+
241
298
  type EventHandler<T = unknown> = (data: T) => void;
242
299
  interface Events {
243
300
  message: {
@@ -254,11 +311,15 @@ declare class MeetBot {
254
311
  private readonly pollingLimit;
255
312
  private readonly longPollingTimeout;
256
313
  private readonly useV2;
314
+ private readonly userAgent?;
257
315
  private readonly eventHandlers;
258
316
  private polling;
259
317
  private offset;
260
318
  private abortController;
261
- constructor(config: MeetBotConfig);
319
+ private readonly userCache;
320
+ constructor(config: MeetBotConfig & {
321
+ userCacheOptions?: UserCacheOptions;
322
+ });
262
323
  on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
263
324
  off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
264
325
  private emit;
@@ -281,37 +342,54 @@ declare class MeetBot {
281
342
  getAccessURL(params: GetAccessURLParams | GetAccessURLBySessionParams): Promise<AccessURLResult>;
282
343
  uploadFile(buffer: Buffer, options: UploadFileOptions): Promise<UploadFileResult>;
283
344
  sendMedia(sessionInfo: SessionInfo, options: SendMediaOptions): Promise<SendMessageResult>;
345
+ refreshUserCache(): Promise<void>;
346
+ getUserById(userId: number): Promise<MeetUser | undefined>;
347
+ getUserByIds(userIds: number[]): Promise<Map<number, MeetUser>>;
348
+ getUserByName(name: string): Promise<MeetUser[]>;
349
+ searchUserByName(query: string): Promise<MeetUser[]>;
350
+ get userCacheSize(): number;
284
351
  private sleep;
285
352
  }
286
353
 
287
354
  interface GetUploadURLApiParams extends GetUploadURLParams {
288
355
  token: string;
289
356
  baseUrl?: string;
357
+ userAgent?: string;
290
358
  }
291
359
  declare function getUploadURL(params: GetUploadURLApiParams): Promise<UploadURLResult>;
292
360
  interface GetMultiPartUploadURLApiParams extends GetMultiPartUploadURLParams {
293
361
  token: string;
294
362
  baseUrl?: string;
363
+ userAgent?: string;
295
364
  }
296
365
  declare function getMultiPartUploadURL(params: GetMultiPartUploadURLApiParams): Promise<MultiPartUploadURLResult>;
297
366
  interface CompleteMultipartUploadApiParams extends CompleteMultipartUploadParams {
298
367
  token: string;
299
368
  baseUrl?: string;
369
+ userAgent?: string;
300
370
  }
301
371
  declare function completeMultipartUpload(params: CompleteMultipartUploadApiParams): Promise<CompleteMultipartUploadResult>;
302
372
  interface GetAccessURLApiParams extends GetAccessURLParams {
303
373
  token: string;
304
374
  baseUrl?: string;
375
+ userAgent?: string;
305
376
  }
306
377
  declare function getAccessURL(params: GetAccessURLApiParams): Promise<AccessURLResult>;
307
378
 
308
379
  declare function computeMD5(buffer: Buffer): Promise<string>;
309
- declare function uploadFile(token: string, buffer: Buffer, options: UploadFileOptions, baseUrl?: string): Promise<UploadFileResult>;
310
- declare function sendMediaMessage(token: string, sessionInfo: SessionInfo, options: SendMediaOptions, baseUrl?: string): Promise<SendMessageResult>;
380
+ declare function uploadFile(token: string, buffer: Buffer, options: UploadFileOptions, baseUrl?: string, userAgent?: string): Promise<UploadFileResult>;
381
+ declare function sendMediaMessage(token: string, sessionInfo: SessionInfo, options: SendMediaOptions, baseUrl?: string, userAgent?: string): Promise<SendMessageResult>;
382
+
383
+ declare function getUsers(params: {
384
+ token: string;
385
+ baseUrl?: string;
386
+ userAgent?: string;
387
+ }): Promise<MeetUser[]>;
311
388
 
312
389
  interface GetUpdatesParams {
313
390
  token: string;
314
391
  baseUrl?: string;
392
+ userAgent?: string;
315
393
  timeout?: number;
316
394
  offset?: number;
317
395
  limit?: number;
@@ -320,6 +398,7 @@ declare function getUpdates(params: GetUpdatesParams): Promise<BotUpdate[]>;
320
398
  interface GetUpdatesV2Params {
321
399
  token: string;
322
400
  baseUrl?: string;
401
+ userAgent?: string;
323
402
  timeout?: number;
324
403
  limit?: number;
325
404
  }
@@ -327,6 +406,7 @@ declare function getUpdatesV2(params: GetUpdatesV2Params): Promise<GetUpdatesV2R
327
406
  interface SendMessageParams {
328
407
  token: string;
329
408
  baseUrl?: string;
409
+ userAgent?: string;
330
410
  sessionInfo: SessionInfo;
331
411
  msgContent: MsgContent;
332
412
  }
@@ -378,4 +458,4 @@ declare function getChunkNum(size: number): number;
378
458
  declare function getConvID(firstID: number, secondID: number, sessionType: number, companyID?: number): string;
379
459
  declare function getQuoteMsgKey(convID: string, seqID: number): string;
380
460
 
381
- 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 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, ValidationError, completeMultipartUpload, computeMD5, getAccessURL, getChunkNum, getConvID, getMultiPartUploadURL, getQuoteMsgKey, getUpdates, getUpdatesV2, getUploadURL, sendMediaMessage, sendMessage, uploadFile };
461
+ 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
@@ -91,6 +91,7 @@ interface MeetBotConfig {
91
91
  longPollingTimeout?: number;
92
92
  logLevel?: LogLevel;
93
93
  useV2?: boolean;
94
+ userAgent?: string;
94
95
  }
95
96
  interface GetUpdatesOptions {
96
97
  token: string;
@@ -216,6 +217,37 @@ interface ReceivedAttachmentInfo {
216
217
  mimeType?: string;
217
218
  }
218
219
 
220
+ interface MeetUser {
221
+ userID: number;
222
+ nickName: string;
223
+ nickNamePinyin?: string;
224
+ aliasName?: string;
225
+ aliasNamePinyin?: string;
226
+ gender?: number;
227
+ birthday?: string;
228
+ avatar?: string;
229
+ avatarUrl?: string;
230
+ email?: string;
231
+ mobile?: string;
232
+ jobNumber?: string;
233
+ tag?: string;
234
+ tags?: string[];
235
+ companyId?: number;
236
+ status?: number;
237
+ statusMsg?: string[];
238
+ sourceType?: number;
239
+ employeeStatus?: number;
240
+ cleanStatus?: number;
241
+ deletedAt?: number;
242
+ isDepartmentAdmin?: boolean;
243
+ isHide?: boolean;
244
+ sort?: number;
245
+ oaUID?: number;
246
+ msgDelTimeStamp?: number;
247
+ userType?: number;
248
+ updatedAt?: number;
249
+ }
250
+
219
251
  declare class MeetBotError extends Error {
220
252
  readonly code: ErrorCode;
221
253
  constructor(message: string, code: ErrorCode);
@@ -227,10 +259,13 @@ declare class ApiError extends MeetBotError {
227
259
  }
228
260
  declare class NetworkError extends MeetBotError {
229
261
  readonly cause?: Error;
230
- constructor(message: string, cause?: Error);
262
+ readonly httpStatus?: number;
263
+ readonly responseSnippet?: string;
264
+ constructor(message: string, cause?: Error, httpStatus?: number, responseSnippet?: string);
231
265
  }
232
266
  declare class TimeoutError extends MeetBotError {
233
- constructor(message: string);
267
+ readonly isLocal: boolean;
268
+ constructor(message: string, isLocal?: boolean);
234
269
  }
235
270
  declare class ValidationError extends MeetBotError {
236
271
  readonly field: string;
@@ -238,6 +273,28 @@ declare class ValidationError extends MeetBotError {
238
273
  constructor(message: string, field: string, value: unknown);
239
274
  }
240
275
 
276
+ interface UserCacheOptions {
277
+ ttl?: number;
278
+ }
279
+ declare class UserCache {
280
+ private byId;
281
+ private byNickName;
282
+ private byAliasName;
283
+ private loadedAt;
284
+ private readonly ttl;
285
+ private loading;
286
+ constructor(options?: UserCacheOptions);
287
+ isExpired(): boolean;
288
+ load(fetchAll: () => Promise<MeetUser[]>): Promise<void>;
289
+ private rebuild;
290
+ ensureLoaded(fetchAll: () => Promise<MeetUser[]>): Promise<void>;
291
+ getById(userId: number): MeetUser | undefined;
292
+ getByIds(userIds: number[]): Map<number, MeetUser>;
293
+ getByName(name: string): MeetUser[];
294
+ searchByName(query: string): MeetUser[];
295
+ get size(): number;
296
+ }
297
+
241
298
  type EventHandler<T = unknown> = (data: T) => void;
242
299
  interface Events {
243
300
  message: {
@@ -254,11 +311,15 @@ declare class MeetBot {
254
311
  private readonly pollingLimit;
255
312
  private readonly longPollingTimeout;
256
313
  private readonly useV2;
314
+ private readonly userAgent?;
257
315
  private readonly eventHandlers;
258
316
  private polling;
259
317
  private offset;
260
318
  private abortController;
261
- constructor(config: MeetBotConfig);
319
+ private readonly userCache;
320
+ constructor(config: MeetBotConfig & {
321
+ userCacheOptions?: UserCacheOptions;
322
+ });
262
323
  on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
263
324
  off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
264
325
  private emit;
@@ -281,37 +342,54 @@ declare class MeetBot {
281
342
  getAccessURL(params: GetAccessURLParams | GetAccessURLBySessionParams): Promise<AccessURLResult>;
282
343
  uploadFile(buffer: Buffer, options: UploadFileOptions): Promise<UploadFileResult>;
283
344
  sendMedia(sessionInfo: SessionInfo, options: SendMediaOptions): Promise<SendMessageResult>;
345
+ refreshUserCache(): Promise<void>;
346
+ getUserById(userId: number): Promise<MeetUser | undefined>;
347
+ getUserByIds(userIds: number[]): Promise<Map<number, MeetUser>>;
348
+ getUserByName(name: string): Promise<MeetUser[]>;
349
+ searchUserByName(query: string): Promise<MeetUser[]>;
350
+ get userCacheSize(): number;
284
351
  private sleep;
285
352
  }
286
353
 
287
354
  interface GetUploadURLApiParams extends GetUploadURLParams {
288
355
  token: string;
289
356
  baseUrl?: string;
357
+ userAgent?: string;
290
358
  }
291
359
  declare function getUploadURL(params: GetUploadURLApiParams): Promise<UploadURLResult>;
292
360
  interface GetMultiPartUploadURLApiParams extends GetMultiPartUploadURLParams {
293
361
  token: string;
294
362
  baseUrl?: string;
363
+ userAgent?: string;
295
364
  }
296
365
  declare function getMultiPartUploadURL(params: GetMultiPartUploadURLApiParams): Promise<MultiPartUploadURLResult>;
297
366
  interface CompleteMultipartUploadApiParams extends CompleteMultipartUploadParams {
298
367
  token: string;
299
368
  baseUrl?: string;
369
+ userAgent?: string;
300
370
  }
301
371
  declare function completeMultipartUpload(params: CompleteMultipartUploadApiParams): Promise<CompleteMultipartUploadResult>;
302
372
  interface GetAccessURLApiParams extends GetAccessURLParams {
303
373
  token: string;
304
374
  baseUrl?: string;
375
+ userAgent?: string;
305
376
  }
306
377
  declare function getAccessURL(params: GetAccessURLApiParams): Promise<AccessURLResult>;
307
378
 
308
379
  declare function computeMD5(buffer: Buffer): Promise<string>;
309
- declare function uploadFile(token: string, buffer: Buffer, options: UploadFileOptions, baseUrl?: string): Promise<UploadFileResult>;
310
- declare function sendMediaMessage(token: string, sessionInfo: SessionInfo, options: SendMediaOptions, baseUrl?: string): Promise<SendMessageResult>;
380
+ declare function uploadFile(token: string, buffer: Buffer, options: UploadFileOptions, baseUrl?: string, userAgent?: string): Promise<UploadFileResult>;
381
+ declare function sendMediaMessage(token: string, sessionInfo: SessionInfo, options: SendMediaOptions, baseUrl?: string, userAgent?: string): Promise<SendMessageResult>;
382
+
383
+ declare function getUsers(params: {
384
+ token: string;
385
+ baseUrl?: string;
386
+ userAgent?: string;
387
+ }): Promise<MeetUser[]>;
311
388
 
312
389
  interface GetUpdatesParams {
313
390
  token: string;
314
391
  baseUrl?: string;
392
+ userAgent?: string;
315
393
  timeout?: number;
316
394
  offset?: number;
317
395
  limit?: number;
@@ -320,6 +398,7 @@ declare function getUpdates(params: GetUpdatesParams): Promise<BotUpdate[]>;
320
398
  interface GetUpdatesV2Params {
321
399
  token: string;
322
400
  baseUrl?: string;
401
+ userAgent?: string;
323
402
  timeout?: number;
324
403
  limit?: number;
325
404
  }
@@ -327,6 +406,7 @@ declare function getUpdatesV2(params: GetUpdatesV2Params): Promise<GetUpdatesV2R
327
406
  interface SendMessageParams {
328
407
  token: string;
329
408
  baseUrl?: string;
409
+ userAgent?: string;
330
410
  sessionInfo: SessionInfo;
331
411
  msgContent: MsgContent;
332
412
  }
@@ -378,4 +458,4 @@ declare function getChunkNum(size: number): number;
378
458
  declare function getConvID(firstID: number, secondID: number, sessionType: number, companyID?: number): string;
379
459
  declare function getQuoteMsgKey(convID: string, seqID: number): string;
380
460
 
381
- 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 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, ValidationError, completeMultipartUpload, computeMD5, getAccessURL, getChunkNum, getConvID, getMultiPartUploadURL, getQuoteMsgKey, getUpdates, getUpdatesV2, getUploadURL, sendMediaMessage, sendMessage, uploadFile };
461
+ 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 };