whatsapp-web-jf.js 1.31.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.
Files changed (55) hide show
  1. package/.env.example +3 -0
  2. package/CODE_OF_CONDUCT.md +133 -0
  3. package/LICENSE +201 -0
  4. package/README.md +185 -0
  5. package/example.js +680 -0
  6. package/index.d.ts +2069 -0
  7. package/index.js +34 -0
  8. package/package.json +55 -0
  9. package/shell.js +36 -0
  10. package/src/Client.js +2188 -0
  11. package/src/authStrategies/BaseAuthStrategy.js +27 -0
  12. package/src/authStrategies/LocalAuth.js +58 -0
  13. package/src/authStrategies/NoAuth.js +12 -0
  14. package/src/authStrategies/RemoteAuth.js +210 -0
  15. package/src/factories/ChatFactory.js +21 -0
  16. package/src/factories/ContactFactory.js +16 -0
  17. package/src/structures/Base.js +22 -0
  18. package/src/structures/Broadcast.js +69 -0
  19. package/src/structures/BusinessContact.js +21 -0
  20. package/src/structures/Buttons.js +82 -0
  21. package/src/structures/Call.js +76 -0
  22. package/src/structures/Channel.js +382 -0
  23. package/src/structures/Chat.js +291 -0
  24. package/src/structures/ClientInfo.js +71 -0
  25. package/src/structures/Contact.js +208 -0
  26. package/src/structures/GroupChat.js +473 -0
  27. package/src/structures/GroupNotification.js +104 -0
  28. package/src/structures/Label.js +50 -0
  29. package/src/structures/List.js +79 -0
  30. package/src/structures/Location.js +62 -0
  31. package/src/structures/Message.js +704 -0
  32. package/src/structures/MessageMedia.js +111 -0
  33. package/src/structures/Order.js +52 -0
  34. package/src/structures/Payment.js +79 -0
  35. package/src/structures/Poll.js +44 -0
  36. package/src/structures/PollVote.js +61 -0
  37. package/src/structures/PrivateChat.js +13 -0
  38. package/src/structures/PrivateContact.js +13 -0
  39. package/src/structures/Product.js +68 -0
  40. package/src/structures/ProductMetadata.js +25 -0
  41. package/src/structures/Reaction.js +69 -0
  42. package/src/structures/index.js +26 -0
  43. package/src/util/Constants.js +176 -0
  44. package/src/util/Injected/AuthStore/AuthStore.js +17 -0
  45. package/src/util/Injected/AuthStore/LegacyAuthStore.js +22 -0
  46. package/src/util/Injected/LegacyStore.js +146 -0
  47. package/src/util/Injected/Store.js +215 -0
  48. package/src/util/Injected/Utils.js +1139 -0
  49. package/src/util/InterfaceController.js +126 -0
  50. package/src/util/Puppeteer.js +23 -0
  51. package/src/util/Util.js +186 -0
  52. package/src/webCache/LocalWebCache.js +40 -0
  53. package/src/webCache/RemoteWebCache.js +40 -0
  54. package/src/webCache/WebCache.js +14 -0
  55. package/src/webCache/WebCacheFactory.js +20 -0
package/index.d.ts ADDED
@@ -0,0 +1,2069 @@
1
+
2
+ import { EventEmitter } from 'events'
3
+ import { RequestInit } from 'node-fetch'
4
+ import * as puppeteer from 'puppeteer'
5
+ import InterfaceController from './src/util/InterfaceController'
6
+
7
+ declare namespace WAWebJS {
8
+
9
+ export class Client extends EventEmitter {
10
+ constructor(options: ClientOptions)
11
+
12
+ /** Current connection information */
13
+ public info: ClientInfo
14
+
15
+ /** Puppeteer page running WhatsApp Web */
16
+ pupPage?: puppeteer.Page
17
+
18
+ /** Puppeteer browser running WhatsApp Web */
19
+ pupBrowser?: puppeteer.Browser
20
+
21
+ /** Client interactivity interface */
22
+ interface?: InterfaceController
23
+
24
+ /**Accepts an invitation to join a group */
25
+ acceptInvite(inviteCode: string): Promise<string>
26
+
27
+ /** Accepts a channel admin invitation and promotes the current user to a channel admin */
28
+ acceptChannelAdminInvite(channelId: string): Promise<boolean>
29
+
30
+ /** Revokes a channel admin invitation sent to a user by a channel owner */
31
+ revokeChannelAdminInvite(channelId: string, userId: string): Promise<boolean>
32
+
33
+ /** Demotes a channel admin to a regular subscriber (can be used also for self-demotion) */
34
+ demoteChannelAdmin(channelId: string, userId: string): Promise<boolean>
35
+
36
+ /** Accepts a private invitation to join a group (v4 invite) */
37
+ acceptGroupV4Invite: (inviteV4: InviteV4Data) => Promise<{status: number}>
38
+
39
+ /**Returns an object with information about the invite code's group */
40
+ getInviteInfo(inviteCode: string): Promise<object>
41
+
42
+ /** Enables and returns the archive state of the Chat */
43
+ archiveChat(chatId: string): Promise<boolean>
44
+
45
+ /** Pins the Chat and returns its new Pin state */
46
+ pinChat(chatId: string): Promise<boolean>
47
+
48
+ /** Unpins the Chat and returns its new Pin state */
49
+ unpinChat(chatId: string): Promise<boolean>
50
+
51
+ /** Creates a new group */
52
+ createGroup(title: string, participants?: string | Contact | Contact[] | string[], options?: CreateGroupOptions): Promise<CreateGroupResult|string>
53
+
54
+ /** Creates a new channel */
55
+ createChannel(title: string, options?: CreateChannelOptions): Promise<CreateChannelResult | string>
56
+
57
+ /** Deletes the channel you created */
58
+ deleteChannel(channelId: string): Promise<boolean>;
59
+
60
+ /** Subscribe to channel */
61
+ subscribeToChannel(channelId: string): Promise<boolean>
62
+
63
+ /** Unsubscribe from channel */
64
+ unsubscribeFromChannel(channelId: string, options?: UnsubscribeOptions): Promise<boolean>
65
+
66
+ /**
67
+ * Searches for channels based on search criteria, there are some notes:
68
+ * 1. The method finds only channels you are not subscribed to currently
69
+ * 2. If you have never been subscribed to a found channel
70
+ * or you have unsubscribed from it with {@link UnsubscribeOptions.deleteLocalModels} set to 'true',
71
+ * the lastMessage property of a found channel will be 'null'
72
+ */
73
+ searchChannels(searchOptions: SearchChannelsOptions): Promise<Array<Channel> | []>
74
+
75
+ /** Closes the client */
76
+ destroy(): Promise<void>
77
+
78
+ /** Logs out the client, closing the current session */
79
+ logout(): Promise<void>
80
+
81
+ /** Get all blocked contacts by host account */
82
+ getBlockedContacts(): Promise<Contact[]>
83
+
84
+ /** Gets chat or channel instance by ID */
85
+ getChatById(chatId: string): Promise<Chat>
86
+
87
+ /** Gets a {@link Channel} instance by invite code */
88
+ getChannelByInviteCode(inviteCode: string): Promise<Channel>
89
+
90
+ /** Get all current chat instances */
91
+ getChats(): Promise<Chat[]>
92
+
93
+ /** Gets all cached {@link Channel} instances */
94
+ getChannels(): Promise<Channel[]>
95
+
96
+ /** Get contact instance by ID */
97
+ getContactById(contactId: string): Promise<Contact>
98
+
99
+ /** Get message by ID */
100
+ getMessageById(messageId: string): Promise<Message>
101
+
102
+ /** Get all current contact instances */
103
+ getContacts(): Promise<Contact[]>
104
+
105
+ /** Get the country code of a WhatsApp ID. (154185968@c.us) => (1) */
106
+ getCountryCode(number: string): Promise<string>
107
+
108
+ /** Get the formatted number of a WhatsApp ID. (12345678901@c.us) => (+1 (234) 5678-901) */
109
+ getFormattedNumber(number: string): Promise<string>
110
+
111
+ /** Get all current Labels */
112
+ getLabels(): Promise<Label[]>
113
+
114
+ /** Get all current Broadcasts */
115
+ getBroadcasts(): Promise<Broadcast[]>
116
+
117
+ /** Change labels in chats */
118
+ addOrRemoveLabels(labelIds: Array<number|string>, chatIds: Array<string>): Promise<void>
119
+
120
+ /** Get Label instance by ID */
121
+ getLabelById(labelId: string): Promise<Label>
122
+
123
+ /** Get all Labels assigned to a Chat */
124
+ getChatLabels(chatId: string): Promise<Label[]>
125
+
126
+ /** Get all Chats for a specific Label */
127
+ getChatsByLabelId(labelId: string): Promise<Chat[]>
128
+
129
+ /** Returns the contact ID's profile picture URL, if privacy settings allow it */
130
+ getProfilePicUrl(contactId: string): Promise<string>
131
+
132
+ /** Gets the Contact's common groups with you. Returns empty array if you don't have any common group. */
133
+ getCommonGroups(contactId: string): Promise<ChatId[]>
134
+
135
+ /** Gets the current connection state for the client */
136
+ getState(): Promise<WAState>
137
+
138
+ /** Returns the version of WhatsApp Web currently being run */
139
+ getWWebVersion(): Promise<string>
140
+
141
+ /** Sets up events and requirements, kicks off authentication request */
142
+ initialize(): Promise<void>
143
+
144
+ /** Check if a given ID is registered in whatsapp */
145
+ isRegisteredUser(contactId: string): Promise<boolean>
146
+
147
+ /** Get the registered WhatsApp ID for a number. Returns null if the number is not registered on WhatsApp. */
148
+ getNumberId(number: string): Promise<ContactId | null>
149
+
150
+ /**
151
+ * Mutes this chat forever, unless a date is specified
152
+ * @param chatId ID of the chat that will be muted
153
+ * @param unmuteDate Date when the chat will be unmuted, leave as is to mute forever
154
+ */
155
+ muteChat(chatId: string, unmuteDate?: Date): Promise<{ isMuted: boolean, muteExpiration: number }>
156
+
157
+ /**
158
+ * Request authentication via pairing code instead of QR code
159
+ * @param phoneNumber - Phone number in international, symbol-free format (e.g. 12025550108 for US, 551155501234 for Brazil)
160
+ * @param showNotification - Show notification to pair on phone number
161
+ * @returns {Promise<string>} - Returns a pairing code in format "ABCDEFGH"
162
+ */
163
+ requestPairingCode(phoneNumber: string, showNotification = true): Promise<string>
164
+
165
+ /** Force reset of connection state for the client */
166
+ resetState(): Promise<void>
167
+
168
+ /** Send a message to a specific chatId */
169
+ sendMessage(chatId: string, content: MessageContent, options?: MessageSendOptions): Promise<Message>
170
+
171
+ /** Sends a channel admin invitation to a user, allowing them to become an admin of the channel */
172
+ sendChannelAdminInvite(chatId: string, channelId: string, options?: { comment?: string }): Promise<boolean>
173
+
174
+ /** Searches for messages */
175
+ searchMessages(query: string, options?: { chatId?: string, page?: number, limit?: number }): Promise<Message[]>
176
+
177
+ /** Marks the client as online */
178
+ sendPresenceAvailable(): Promise<void>
179
+
180
+ /** Marks the client as offline */
181
+ sendPresenceUnavailable(): Promise<void>
182
+
183
+ /** Mark as seen for the Chat */
184
+ sendSeen(chatId: string): Promise<boolean>
185
+
186
+ /** Mark the Chat as unread */
187
+ markChatUnread(chatId: string): Promise<void>
188
+
189
+ /**
190
+ * Sets the current user's status message
191
+ * @param status New status message
192
+ */
193
+ setStatus(status: string): Promise<void>
194
+
195
+ /**
196
+ * Sets the current user's display name
197
+ * @param displayName New display name
198
+ */
199
+ setDisplayName(displayName: string): Promise<boolean>
200
+
201
+ /**
202
+ * Changes the autoload Audio
203
+ * @param flag true/false on or off
204
+ */
205
+ setAutoDownloadAudio(flag: boolean): Promise<void>
206
+ /**
207
+ * Changes the autoload Documents
208
+ * @param flag true/false on or off
209
+ */
210
+ setAutoDownloadDocuments(flag: boolean): Promise<void>
211
+ /**
212
+ * Changes the autoload Photos
213
+ * @param flag true/false on or off
214
+ */
215
+ setAutoDownloadPhotos(flag: boolean): Promise<void>
216
+ /**
217
+ * Changes the autoload Videos
218
+ * @param flag true/false on or off
219
+ */
220
+ setAutoDownloadVideos(flag: boolean): Promise<void>
221
+
222
+ /**
223
+ * Changing the background synchronization setting.
224
+ * NOTE: this action will take effect after you restart the client.
225
+ * @param flag true/false on or off
226
+ */
227
+ setBackgroundSync(flag: boolean): Promise<void>
228
+
229
+ /**
230
+ * Get user device count by ID
231
+ * Each WaWeb Connection counts as one device, and the phone (if exists) counts as one
232
+ * So for a non-enterprise user with one WaWeb connection it should return "2"
233
+ * @param {string} contactId
234
+ */
235
+ getContactDeviceCount(userId: string): Promise<number>
236
+
237
+ /** Sync history conversation of the Chat */
238
+ syncHistory(chatId: string): Promise<boolean>
239
+
240
+ /** Save new contact to user's addressbook or edit the existing one */
241
+ saveOrEditAddressbookContact(phoneNumber: string, firstName: string, lastName: string, syncToAddressbook?: boolean): Promise<ChatId>
242
+
243
+ /** Deletes the contact from user's addressbook */
244
+ deleteAddressbookContact(honeNumber: string): Promise<void>
245
+
246
+ /** Changes and returns the archive state of the Chat */
247
+ unarchiveChat(chatId: string): Promise<boolean>
248
+
249
+ /** Unmutes the Chat */
250
+ unmuteChat(chatId: string): Promise<{ isMuted: boolean, muteExpiration: number }>
251
+
252
+ /** Sets the current user's profile picture */
253
+ setProfilePicture(media: MessageMedia): Promise<boolean>
254
+
255
+ /** Deletes the current user's profile picture */
256
+ deleteProfilePicture(): Promise<boolean>
257
+
258
+ /** Gets an array of membership requests */
259
+ getGroupMembershipRequests(groupId: string): Promise<Array<GroupMembershipRequest>>
260
+
261
+ /** Approves membership requests if any */
262
+ approveGroupMembershipRequests(groupId: string, options: MembershipRequestActionOptions): Promise<Array<MembershipRequestActionResult>>;
263
+
264
+ /** Rejects membership requests if any */
265
+ rejectGroupMembershipRequests(groupId: string, options: MembershipRequestActionOptions): Promise<Array<MembershipRequestActionResult>>;
266
+
267
+ /**
268
+ * Transfers a channel ownership to another user.
269
+ * Note: the user you are transferring the channel ownership to must be a channel admin.
270
+ */
271
+ transferChannelOwnership(channelId: string, newOwnerId: string, options?: TransferChannelOwnershipOptions): Promise<boolean>;
272
+
273
+ /** Generic event */
274
+ on(event: string, listener: (...args: any) => void): this
275
+
276
+ /** Emitted when there has been an error while trying to restore an existing session */
277
+ on(event: 'auth_failure', listener: (message: string) => void): this
278
+
279
+ /** Emitted when authentication is successful */
280
+ on(event: 'authenticated', listener: (
281
+ /**
282
+ * Object containing session information, when using LegacySessionAuth. Can be used to restore the session
283
+ */
284
+ session?: ClientSession
285
+ ) => void): this
286
+
287
+ /**
288
+ * Emitted when the battery percentage for the attached device changes
289
+ * @deprecated
290
+ */
291
+ on(event: 'change_battery', listener: (batteryInfo: BatteryInfo) => void): this
292
+
293
+ /** Emitted when the connection state changes */
294
+ on(event: 'change_state', listener: (
295
+ /** the new connection state */
296
+ state: WAState
297
+ ) => void): this
298
+
299
+ /** Emitted when the client has been disconnected */
300
+ on(event: 'disconnected', listener: (
301
+ /** reason that caused the disconnect */
302
+ reason: WAState | "LOGOUT"
303
+ ) => void): this
304
+
305
+ /** Emitted when a user joins the chat via invite link or is added by an admin */
306
+ on(event: 'group_join', listener: (
307
+ /** GroupNotification with more information about the action */
308
+ notification: GroupNotification
309
+ ) => void): this
310
+
311
+ /** Emitted when a user leaves the chat or is removed by an admin */
312
+ on(event: 'group_leave', listener: (
313
+ /** GroupNotification with more information about the action */
314
+ notification: GroupNotification
315
+ ) => void): this
316
+
317
+ /** Emitted when a current user is promoted to an admin or demoted to a regular user */
318
+ on(event: 'group_admin_changed', listener: (
319
+ /** GroupNotification with more information about the action */
320
+ notification: GroupNotification
321
+ ) => void): this
322
+
323
+ /**
324
+ * Emitted when some user requested to join the group
325
+ * that has the membership approval mode turned on
326
+ */
327
+ on(event: 'group_membership_request', listener: (
328
+ /** GroupNotification with more information about the action */
329
+ notification: GroupNotification
330
+ ) => void): this
331
+
332
+ /** Emitted when group settings are updated, such as subject, description or picture */
333
+ on(event: 'group_update', listener: (
334
+ /** GroupNotification with more information about the action */
335
+ notification: GroupNotification
336
+ ) => void): this
337
+
338
+ /** Emitted when a contact or a group participant changed their phone number. */
339
+ on(event: 'contact_changed', listener: (
340
+ /** Message with more information about the event. */
341
+ message: Message,
342
+ /** Old user's id. */
343
+ oldId : String,
344
+ /** New user's id. */
345
+ newId : String,
346
+ /** Indicates if a contact or a group participant changed their phone number. */
347
+ isContact : Boolean
348
+ ) => void): this
349
+
350
+ /** Emitted when media has been uploaded for a message sent by the client */
351
+ on(event: 'media_uploaded', listener: (
352
+ /** The message with media that was uploaded */
353
+ message: Message
354
+ ) => void): this
355
+
356
+ /** Emitted when a new message is received */
357
+ on(event: 'message', listener: (
358
+ /** The message that was received */
359
+ message: Message
360
+ ) => void): this
361
+
362
+ /** Emitted when an ack event occurrs on message type */
363
+ on(event: 'message_ack', listener: (
364
+ /** The message that was affected */
365
+ message: Message,
366
+ /** The new ACK value */
367
+ ack: MessageAck
368
+ ) => void): this
369
+
370
+ /** Emitted when an ack event occurrs on message type */
371
+ on(event: 'message_edit', listener: (
372
+ /** The message that was affected */
373
+ message: Message,
374
+ /** New text message */
375
+ newBody: String,
376
+ /** Prev text message */
377
+ prevBody: String
378
+ ) => void): this
379
+
380
+ /** Emitted when a chat unread count changes */
381
+ on(event: 'unread_count', listener: (
382
+ /** The chat that was affected */
383
+ chat: Chat
384
+ ) => void): this
385
+
386
+ /** Emitted when a new message is created, which may include the current user's own messages */
387
+ on(event: 'message_create', listener: (
388
+ /** The message that was created */
389
+ message: Message
390
+ ) => void): this
391
+
392
+ /** Emitted when a new message ciphertext is received */
393
+ on(event: 'message_ciphertext', listener: (
394
+ /** The message that was ciphertext */
395
+ message: Message
396
+ ) => void): this
397
+
398
+ /** Emitted when a message is deleted for everyone in the chat */
399
+ on(event: 'message_revoke_everyone', listener: (
400
+ /** The message that was revoked, in its current state. It will not contain the original message's data */
401
+ message: Message,
402
+ /**The message that was revoked, before it was revoked.
403
+ * It will contain the message's original data.
404
+ * Note that due to the way this data is captured,
405
+ * it may be possible that this param will be undefined. */
406
+ revoked_msg?: Message | null
407
+ ) => void): this
408
+
409
+ /** Emitted when a message is deleted by the current user */
410
+ on(event: 'message_revoke_me', listener: (
411
+ /** The message that was revoked */
412
+ message: Message
413
+ ) => void): this
414
+
415
+ /** Emitted when a reaction is sent, received, updated or removed */
416
+ on(event: 'message_reaction', listener: (
417
+ /** The reaction object */
418
+ reaction: Reaction
419
+ ) => void): this
420
+
421
+ /** Emitted when a chat is removed */
422
+ on(event: 'chat_removed', listener: (
423
+ /** The chat that was removed */
424
+ chat: Chat
425
+ ) => void): this
426
+
427
+ /** Emitted when a chat is archived/unarchived */
428
+ on(event: 'chat_archived', listener: (
429
+ /** The chat that was archived/unarchived */
430
+ chat: Chat,
431
+ /** State the chat is currently in */
432
+ currState: boolean,
433
+ /** State the chat was previously in */
434
+ prevState: boolean
435
+ ) => void): this
436
+
437
+ /** Emitted when loading screen is appearing */
438
+ on(event: 'loading_screen', listener: (percent: string, message: string) => void): this
439
+
440
+ /** Emitted when the QR code is received */
441
+ on(event: 'qr', listener: (
442
+ /** qr code string
443
+ * @example ```1@9Q8tWf6bnezr8uVGwVCluyRuBOJ3tIglimzI5dHB0vQW2m4DQ0GMlCGf,f1/vGcW4Z3vBa1eDNl3tOjWqLL5DpYTI84DMVkYnQE8=,ZL7YnK2qdPN8vKo2ESxhOQ==``` */
444
+ qr: string
445
+ ) => void): this
446
+
447
+ /** Emitted when a call is received */
448
+ on(event: 'call', listener: (
449
+ /** The call that started */
450
+ call: Call
451
+ ) => void): this
452
+
453
+ /** Emitted when the client has initialized and is ready to receive messages */
454
+ on(event: 'ready', listener: () => void): this
455
+
456
+ /** Emitted when the RemoteAuth session is saved successfully on the external Database */
457
+ on(event: 'remote_session_saved', listener: () => void): this
458
+
459
+ /**
460
+ * Emitted when some poll option is selected or deselected,
461
+ * shows a user's current selected option(s) on the poll
462
+ */
463
+ on(event: 'vote_update', listener: (
464
+ vote: PollVote
465
+ ) => void): this
466
+ }
467
+
468
+ /** Current connection information */
469
+ export interface ClientInfo {
470
+ /**
471
+ * Current user ID
472
+ * @deprecated Use .wid instead
473
+ */
474
+ me: ContactId
475
+ /** Current user ID */
476
+ wid: ContactId
477
+ /**
478
+ * Information about the phone this client is connected to. Not available in multi-device.
479
+ * @deprecated
480
+ */
481
+ phone: ClientInfoPhone
482
+ /** Platform the phone is running on */
483
+ platform: string
484
+ /** Name configured to be shown in push notifications */
485
+ pushname: string
486
+
487
+ /** Get current battery percentage and charging status for the attached device */
488
+ getBatteryStatus: () => Promise<BatteryInfo>
489
+ }
490
+
491
+ /**
492
+ * Information about the phone this client is connected to
493
+ * @deprecated
494
+ */
495
+ export interface ClientInfoPhone {
496
+ /** WhatsApp Version running on the phone */
497
+ wa_version: string
498
+ /** OS Version running on the phone (iOS or Android version) */
499
+ os_version: string
500
+ /** Device manufacturer */
501
+ device_manufacturer: string
502
+ /** Device model */
503
+ device_model: string
504
+ /** OS build number */
505
+ os_build_number: string
506
+ }
507
+
508
+ /** Options for initializing the whatsapp client */
509
+ export interface ClientOptions {
510
+ /** Timeout for authentication selector in puppeteer
511
+ * @default 0 */
512
+ authTimeoutMs?: number,
513
+ /** Puppeteer launch options. View docs here: https://github.com/puppeteer/puppeteer/ */
514
+ puppeteer?: puppeteer.PuppeteerNodeLaunchOptions & puppeteer.ConnectOptions
515
+ /** Determines how to save and restore sessions. Will use LegacySessionAuth if options.session is set. Otherwise, NoAuth will be used. */
516
+ authStrategy?: AuthStrategy,
517
+ /** The version of WhatsApp Web to use. Use options.webVersionCache to configure how the version is retrieved. */
518
+ webVersion?: string,
519
+ /** Determines how to retrieve the WhatsApp Web version specified in options.webVersion. */
520
+ webVersionCache?: WebCacheOptions,
521
+ /** How many times should the qrcode be refreshed before giving up
522
+ * @default 0 (disabled) */
523
+ qrMaxRetries?: number,
524
+ /**
525
+ * @deprecated This option should be set directly on the LegacySessionAuth
526
+ */
527
+ restartOnAuthFail?: boolean
528
+ /**
529
+ * @deprecated Only here for backwards-compatibility. You should move to using LocalAuth, or set the authStrategy to LegacySessionAuth explicitly.
530
+ */
531
+ session?: ClientSession
532
+ /** If another whatsapp web session is detected (another browser), take over the session in the current browser
533
+ * @default false */
534
+ takeoverOnConflict?: boolean,
535
+ /** How much time to wait before taking over the session
536
+ * @default 0 */
537
+ takeoverTimeoutMs?: number,
538
+ /** User agent to use in puppeteer.
539
+ * @default 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36' */
540
+ userAgent?: string
541
+ /** Ffmpeg path to use when formatting videos to webp while sending stickers
542
+ * @default 'ffmpeg' */
543
+ ffmpegPath?: string,
544
+ /** Object with proxy autentication requirements @default: undefined */
545
+ proxyAuthentication?: {username: string, password: string} | undefined
546
+ }
547
+
548
+ export interface LocalWebCacheOptions {
549
+ type: 'local',
550
+ path?: string,
551
+ strict?: boolean
552
+ }
553
+
554
+ export interface RemoteWebCacheOptions {
555
+ type: 'remote',
556
+ remotePath: string,
557
+ strict?: boolean
558
+ }
559
+
560
+ export interface NoWebCacheOptions {
561
+ type: 'none'
562
+ }
563
+
564
+ export type WebCacheOptions = NoWebCacheOptions | LocalWebCacheOptions | RemoteWebCacheOptions;
565
+
566
+ /**
567
+ * Base class which all authentication strategies extend
568
+ */
569
+ export abstract class AuthStrategy {
570
+ setup: (client: Client) => void;
571
+ beforeBrowserInitialized: () => Promise<void>;
572
+ afterBrowserInitialized: () => Promise<void>;
573
+ onAuthenticationNeeded: () => Promise<{
574
+ failed?: boolean;
575
+ restart?: boolean;
576
+ failureEventPayload?: any
577
+ }>;
578
+ getAuthEventPayload: () => Promise<any>;
579
+ afterAuthReady: () => Promise<void>;
580
+ disconnect: () => Promise<void>;
581
+ destroy: () => Promise<void>;
582
+ logout: () => Promise<void>;
583
+ }
584
+
585
+ /**
586
+ * No session restoring functionality
587
+ * Will need to authenticate via QR code every time
588
+ */
589
+ export class NoAuth extends AuthStrategy {}
590
+
591
+ /**
592
+ * Local directory-based authentication
593
+ */
594
+ export class LocalAuth extends AuthStrategy {
595
+ public clientId?: string;
596
+ public dataPath?: string;
597
+ constructor(options?: {
598
+ clientId?: string,
599
+ dataPath?: string,
600
+ rmMaxRetries?: number
601
+ })
602
+ }
603
+
604
+ /**
605
+ * Remote-based authentication
606
+ */
607
+ export class RemoteAuth extends AuthStrategy {
608
+ public clientId?: string;
609
+ public dataPath?: string;
610
+ constructor(options?: {
611
+ store: Store,
612
+ clientId?: string,
613
+ dataPath?: string,
614
+ backupSyncIntervalMs: number,
615
+ rmMaxRetries?: number
616
+ })
617
+ }
618
+
619
+ /**
620
+ * Remote store interface
621
+ */
622
+ export interface Store {
623
+ sessionExists: (options: { session: string }) => Promise<boolean> | boolean,
624
+ delete: (options: { session: string }) => Promise<any> | any,
625
+ save: (options: { session: string }) => Promise<any> | any,
626
+ extract: (options: { session: string, path: string }) => Promise<any> | any,
627
+ }
628
+
629
+ /**
630
+ * Legacy session auth strategy
631
+ * Not compatible with multi-device accounts.
632
+ */
633
+ export class LegacySessionAuth extends AuthStrategy {
634
+ constructor(options?: {
635
+ session?: ClientSession,
636
+ restartOnAuthFail?: boolean,
637
+ })
638
+ }
639
+
640
+ /**
641
+ * Represents a WhatsApp client session
642
+ */
643
+ export interface ClientSession {
644
+ WABrowserId: string,
645
+ WASecretBundle: string,
646
+ WAToken1: string,
647
+ WAToken2: string,
648
+ }
649
+
650
+ /**
651
+ * @deprecated
652
+ */
653
+ export interface BatteryInfo {
654
+ /** The current battery percentage */
655
+ battery: number,
656
+ /** Indicates if the phone is plugged in (true) or not (false) */
657
+ plugged: boolean,
658
+ }
659
+
660
+ /** An object that handles options for group creation */
661
+ export interface CreateGroupOptions {
662
+ /**
663
+ * The number of seconds for the messages to disappear in the group,
664
+ * won't take an effect if the group is been creating with myself only
665
+ * @default 0
666
+ */
667
+ messageTimer?: number
668
+ /**
669
+ * The ID of a parent community group to link the newly created group with,
670
+ * won't take an effect if the group is been creating with myself only
671
+ */
672
+ parentGroupId?: string
673
+ /** If true, the inviteV4 will be sent to those participants
674
+ * who have restricted others from being automatically added to groups,
675
+ * otherwise the inviteV4 won't be sent
676
+ * @default true
677
+ */
678
+ autoSendInviteV4?: boolean,
679
+ /**
680
+ * The comment to be added to an inviteV4 (empty string by default)
681
+ * @default ''
682
+ */
683
+ comment?: string
684
+ }
685
+
686
+ /** An object that handles the result for createGroup method */
687
+ export interface CreateGroupResult {
688
+ /** A group title */
689
+ title: string;
690
+ /** An object that handles the newly created group ID */
691
+ gid: ChatId;
692
+ /** An object that handles the result value for each added to the group participant */
693
+ participants: {
694
+ [participantId: string]: {
695
+ statusCode: number,
696
+ message: string,
697
+ isGroupCreator: boolean,
698
+ isInviteV4Sent: boolean
699
+ };
700
+ };
701
+ }
702
+
703
+ /** An object that handles options for channel creation */
704
+ export interface CreateChannelOptions {
705
+ /** The channel description */
706
+ description?: string,
707
+ /** The channel profile picture */
708
+ picture?: MessageMedia
709
+ }
710
+
711
+ /** An object that handles the result for createGroup method */
712
+ export interface CreateChannelResult {
713
+ /** A channel title */
714
+ title: string,
715
+ /** An object that handles the newly created channel ID */
716
+ nid: ChatId,
717
+ /** The channel invite link, starts with 'https://whatsapp.com/channel/' */
718
+ inviteLink: string,
719
+ /** The timestamp the channel was created at */
720
+ createdAtTs: number
721
+ }
722
+
723
+ /** Options for unsubscribe from a channel */
724
+ export interface UnsubscribeOptions {
725
+ /**
726
+ * If true, after an unsubscription, it will completely remove a channel from the channel collection
727
+ * making it seem like the current user have never interacted with it.
728
+ * Otherwise it will only remove a channel from the list of channels the current user is subscribed to
729
+ * and will set the membership type for that channel to GUEST
730
+ */
731
+ deleteLocalModels?: boolean
732
+ }
733
+
734
+ /** Options for searching for channels */
735
+ export interface SearchChannelsOptions {
736
+ searchText?: string;
737
+ countryCodes?: string[];
738
+ skipSubscribedNewsletters?: boolean;
739
+ view?: number;
740
+ limit?: number;
741
+ }
742
+
743
+ export interface GroupNotification {
744
+ /** ContactId for the user that produced the GroupNotification */
745
+ author: string,
746
+ /** Extra content */
747
+ body: string,
748
+ /** ID for the Chat that this groupNotification was sent for */
749
+ chatId: string,
750
+ /** ID that represents the groupNotification
751
+ * @todo create a more specific type for the id object */
752
+ id: object,
753
+ /** Contact IDs for the users that were affected by this GroupNotification */
754
+ recipientIds: string[],
755
+ /** Unix timestamp for when the groupNotification was created */
756
+ timestamp: number,
757
+ /** GroupNotification type */
758
+ type: GroupNotificationTypes,
759
+
760
+ /** Returns the Chat this GroupNotification was sent in */
761
+ getChat: () => Promise<Chat>,
762
+ /** Returns the Contact this GroupNotification was produced by */
763
+ getContact: () => Promise<Contact>,
764
+ /** Returns the Contacts affected by this GroupNotification */
765
+ getRecipients: () => Promise<Contact[]>,
766
+ /** Sends a message to the same chat this GroupNotification was produced in */
767
+ reply: (content: MessageContent, options?: MessageSendOptions) => Promise<Message>,
768
+
769
+ }
770
+
771
+ /** whatsapp web url */
772
+ export const WhatsWebURL: string
773
+
774
+ /** default client options */
775
+ export const DefaultOptions: ClientOptions
776
+
777
+ /** Chat types */
778
+ export enum ChatTypes {
779
+ SOLO = 'solo',
780
+ GROUP = 'group',
781
+ UNKNOWN = 'unknown',
782
+ }
783
+
784
+ /** Events that can be emitted by the client */
785
+ export enum Events {
786
+ AUTHENTICATED = 'authenticated',
787
+ AUTHENTICATION_FAILURE = 'auth_failure',
788
+ READY = 'ready',
789
+ MESSAGE_RECEIVED = 'message',
790
+ MESSAGE_CIPHERTEXT = 'message_ciphertext',
791
+ MESSAGE_CREATE = 'message_create',
792
+ MESSAGE_REVOKED_EVERYONE = 'message_revoke_everyone',
793
+ MESSAGE_REVOKED_ME = 'message_revoke_me',
794
+ MESSAGE_ACK = 'message_ack',
795
+ MESSAGE_EDIT = 'message_edit',
796
+ MEDIA_UPLOADED = 'media_uploaded',
797
+ CONTACT_CHANGED = 'contact_changed',
798
+ GROUP_JOIN = 'group_join',
799
+ GROUP_LEAVE = 'group_leave',
800
+ GROUP_ADMIN_CHANGED = 'group_admin_changed',
801
+ GROUP_MEMBERSHIP_REQUEST = 'group_membership_request',
802
+ GROUP_UPDATE = 'group_update',
803
+ QR_RECEIVED = 'qr',
804
+ LOADING_SCREEN = 'loading_screen',
805
+ DISCONNECTED = 'disconnected',
806
+ STATE_CHANGED = 'change_state',
807
+ BATTERY_CHANGED = 'change_battery',
808
+ REMOTE_SESSION_SAVED = 'remote_session_saved',
809
+ CALL = 'call'
810
+ }
811
+
812
+ /** Group notification types */
813
+ export enum GroupNotificationTypes {
814
+ ADD = 'add',
815
+ INVITE = 'invite',
816
+ REMOVE = 'remove',
817
+ LEAVE = 'leave',
818
+ SUBJECT = 'subject',
819
+ DESCRIPTION = 'description',
820
+ PICTURE = 'picture',
821
+ ANNOUNCE = 'announce',
822
+ RESTRICT = 'restrict',
823
+ }
824
+
825
+ /** Message ACK */
826
+ export enum MessageAck {
827
+ ACK_ERROR = -1,
828
+ ACK_PENDING = 0,
829
+ ACK_SERVER = 1,
830
+ ACK_DEVICE = 2,
831
+ ACK_READ = 3,
832
+ ACK_PLAYED = 4,
833
+ }
834
+
835
+ /** Message types */
836
+ export enum MessageTypes {
837
+ TEXT = 'chat',
838
+ AUDIO = 'audio',
839
+ VOICE = 'ptt',
840
+ IMAGE = 'image',
841
+ VIDEO = 'video',
842
+ DOCUMENT = 'document',
843
+ STICKER = 'sticker',
844
+ LOCATION = 'location',
845
+ CONTACT_CARD = 'vcard',
846
+ CONTACT_CARD_MULTI = 'multi_vcard',
847
+ REVOKED = 'revoked',
848
+ ORDER = 'order',
849
+ PRODUCT = 'product',
850
+ PAYMENT = 'payment',
851
+ UNKNOWN = 'unknown',
852
+ GROUP_INVITE = 'groups_v4_invite',
853
+ LIST = 'list',
854
+ LIST_RESPONSE = 'list_response',
855
+ BUTTONS_RESPONSE = 'buttons_response',
856
+ BROADCAST_NOTIFICATION = 'broadcast_notification',
857
+ CALL_LOG = 'call_log',
858
+ CIPHERTEXT = 'ciphertext',
859
+ DEBUG = 'debug',
860
+ E2E_NOTIFICATION = 'e2e_notification',
861
+ GP2 = 'gp2',
862
+ GROUP_NOTIFICATION = 'group_notification',
863
+ HSM = 'hsm',
864
+ INTERACTIVE = 'interactive',
865
+ NATIVE_FLOW = 'native_flow',
866
+ NOTIFICATION = 'notification',
867
+ NOTIFICATION_TEMPLATE = 'notification_template',
868
+ OVERSIZED = 'oversized',
869
+ PROTOCOL = 'protocol',
870
+ REACTION = 'reaction',
871
+ TEMPLATE_BUTTON_REPLY = 'template_button_reply',
872
+ POLL_CREATION = 'poll_creation',
873
+ }
874
+
875
+ /** Client status */
876
+ export enum Status {
877
+ INITIALIZING = 0,
878
+ AUTHENTICATING = 1,
879
+ READY = 3,
880
+ }
881
+
882
+ /** WhatsApp state */
883
+ export enum WAState {
884
+ CONFLICT = 'CONFLICT',
885
+ CONNECTED = 'CONNECTED',
886
+ DEPRECATED_VERSION = 'DEPRECATED_VERSION',
887
+ OPENING = 'OPENING',
888
+ PAIRING = 'PAIRING',
889
+ PROXYBLOCK = 'PROXYBLOCK',
890
+ SMB_TOS_BLOCK = 'SMB_TOS_BLOCK',
891
+ TIMEOUT = 'TIMEOUT',
892
+ TOS_BLOCK = 'TOS_BLOCK',
893
+ UNLAUNCHED = 'UNLAUNCHED',
894
+ UNPAIRED = 'UNPAIRED',
895
+ UNPAIRED_IDLE = 'UNPAIRED_IDLE',
896
+ }
897
+
898
+ export type MessageInfo = {
899
+ delivery: Array<{id: ContactId, t: number}>,
900
+ deliveryRemaining: number,
901
+ played: Array<{id: ContactId, t: number}>,
902
+ playedRemaining: number,
903
+ read: Array<{id: ContactId, t: number}>,
904
+ readRemaining: number
905
+ }
906
+
907
+ export type InviteV4Data = {
908
+ inviteCode: string,
909
+ inviteCodeExp: number,
910
+ groupId: string,
911
+ groupName?: string,
912
+ fromId: string,
913
+ toId: string
914
+ }
915
+
916
+ /**
917
+ * Represents a Message on WhatsApp
918
+ *
919
+ * @example
920
+ * {
921
+ * mediaKey: undefined,
922
+ * id: {
923
+ * fromMe: false,
924
+ * remote: `554199999999@c.us`,
925
+ * id: '1234567890ABCDEFGHIJ',
926
+ * _serialized: `false_554199999999@c.us_1234567890ABCDEFGHIJ`
927
+ * },
928
+ * ack: -1,
929
+ * hasMedia: false,
930
+ * body: 'Hello!',
931
+ * type: 'chat',
932
+ * timestamp: 1591482682,
933
+ * from: `554199999999@c.us`,
934
+ * to: `554188888888@c.us`,
935
+ * author: undefined,
936
+ * isForwarded: false,
937
+ * broadcast: false,
938
+ * fromMe: false,
939
+ * hasQuotedMsg: false,
940
+ * hasReaction: false,
941
+ * location: undefined,
942
+ * mentionedIds: []
943
+ * }
944
+ */
945
+ export interface Message {
946
+ /** ACK status for the message */
947
+ ack: MessageAck,
948
+ /** If the message was sent to a group, this field will contain the user that sent the message. */
949
+ author?: string,
950
+ /** String that represents from which device type the message was sent */
951
+ deviceType: string,
952
+ /** Message content */
953
+ body: string,
954
+ /** Indicates if the message was a broadcast */
955
+ broadcast: boolean,
956
+ /** Indicates if the message was a status update */
957
+ isStatus: boolean,
958
+ /** Indicates if the message is a Gif */
959
+ isGif: boolean,
960
+ /** Indicates if the message will disappear after it expires */
961
+ isEphemeral: boolean,
962
+ /** ID for the Chat that this message was sent to, except if the message was sent by the current user */
963
+ from: string,
964
+ /** Indicates if the message was sent by the current user */
965
+ fromMe: boolean,
966
+ /** Indicates if the message has media available for download */
967
+ hasMedia: boolean,
968
+ /** Indicates if the message was sent as a reply to another message */
969
+ hasQuotedMsg: boolean,
970
+ /** Indicates whether there are reactions to the message */
971
+ hasReaction: boolean,
972
+ /** Indicates the duration of the message in seconds */
973
+ duration: string,
974
+ /** ID that represents the message */
975
+ id: MessageId,
976
+ /** Indicates if the message was forwarded */
977
+ isForwarded: boolean,
978
+ /**
979
+ * Indicates how many times the message was forwarded.
980
+ * The maximum value is 127.
981
+ */
982
+ forwardingScore: number,
983
+ /** Indicates if the message was starred */
984
+ isStarred: boolean,
985
+ /** Location information contained in the message, if the message is type "location" */
986
+ location: Location,
987
+ /** List of vCards contained in the message */
988
+ vCards: string[],
989
+ /** Invite v4 info */
990
+ inviteV4?: InviteV4Data,
991
+ /** MediaKey that represents the sticker 'ID' */
992
+ mediaKey?: string,
993
+ /** Indicates the mentions in the message body. */
994
+ mentionedIds: string[],
995
+ /** Indicates whether there are group mentions in the message body */
996
+ groupMentions: {
997
+ groupSubject: string;
998
+ groupJid: string;
999
+ }[],
1000
+ /** Unix timestamp for when the message was created */
1001
+ timestamp: number,
1002
+ /**
1003
+ * ID for who this message is for.
1004
+ * If the message is sent by the current user, it will be the Chat to which the message is being sent.
1005
+ * If the message is sent by another user, it will be the ID for the current user.
1006
+ */
1007
+ to: string,
1008
+ /** Message type */
1009
+ type: MessageTypes,
1010
+ /** Links included in the message. */
1011
+ links: Array<{
1012
+ link: string,
1013
+ isSuspicious: boolean
1014
+ }>,
1015
+ /** Order ID */
1016
+ orderId: string,
1017
+ /** title */
1018
+ title?: string,
1019
+ /** description*/
1020
+ description?: string,
1021
+ /** Business Owner JID */
1022
+ businessOwnerJid?: string,
1023
+ /** Product JID */
1024
+ productId?: string,
1025
+ /** Last edit time */
1026
+ latestEditSenderTimestampMs?: number,
1027
+ /** Last edit message author */
1028
+ latestEditMsgKey?: MessageId,
1029
+ /** Message buttons */
1030
+ dynamicReplyButtons?: object,
1031
+ /** Selected button ID */
1032
+ selectedButtonId?: string,
1033
+ /** Selected list row ID */
1034
+ selectedRowId?: string,
1035
+ /** Returns message in a raw format */
1036
+ rawData: object,
1037
+ pollName: string,
1038
+ /** Avaiaible poll voting options */
1039
+ pollOptions: string[],
1040
+ /** False for a single choice poll, true for a multiple choice poll */
1041
+ allowMultipleAnswers: boolean,
1042
+ /*
1043
+ * Reloads this Message object's data in-place with the latest values from WhatsApp Web.
1044
+ * Note that the Message must still be in the web app cache for this to work, otherwise will return null.
1045
+ */
1046
+ reload: () => Promise<Message>,
1047
+ /** Accept the Group V4 Invite in message */
1048
+ acceptGroupV4Invite: () => Promise<{status: number}>,
1049
+ /** Deletes the message from the chat */
1050
+ delete: (everyone?: boolean, clearMedia?: boolean) => Promise<void>,
1051
+ /** Downloads and returns the attached message media */
1052
+ downloadMedia: () => Promise<MessageMedia>,
1053
+ /** Returns the Chat this message was sent in */
1054
+ getChat: () => Promise<Chat>,
1055
+ /** Returns the Contact this message was sent from */
1056
+ getContact: () => Promise<Contact>,
1057
+ /** Returns the Contacts mentioned in this message */
1058
+ getMentions: () => Promise<Contact[]>,
1059
+ /** Returns groups mentioned in this message */
1060
+ getGroupMentions: () => Promise<GroupChat[]|[]>,
1061
+ /** Returns the quoted message, if any */
1062
+ getQuotedMessage: () => Promise<Message>,
1063
+ /**
1064
+ * Sends a message as a reply to this message.
1065
+ * If chatId is specified, it will be sent through the specified Chat.
1066
+ * If not, it will send the message in the same Chat as the original message was sent.
1067
+ */
1068
+ reply: (content: MessageContent, chatId?: string, options?: MessageSendOptions) => Promise<Message>,
1069
+ /** React to this message with an emoji*/
1070
+ react: (reaction: string) => Promise<void>,
1071
+ /**
1072
+ * Forwards this message to another chat (that you chatted before, otherwise it will fail)
1073
+ */
1074
+ forward: (chat: Chat | string) => Promise<void>,
1075
+ /** Star this message */
1076
+ star: () => Promise<void>,
1077
+ /** Unstar this message */
1078
+ unstar: () => Promise<void>,
1079
+ /** Pins the message (group admins can pin messages of all group members) */
1080
+ pin: (duration: number) => Promise<boolean>,
1081
+ /** Unpins the message (group admins can unpin messages of all group members) */
1082
+ unpin: () => Promise<boolean>,
1083
+ /** Get information about message delivery status */
1084
+ getInfo: () => Promise<MessageInfo | null>,
1085
+ /**
1086
+ * Gets the order associated with a given message
1087
+ */
1088
+ getOrder: () => Promise<Order>,
1089
+ /**
1090
+ * Gets the payment details associated with a given message
1091
+ */
1092
+ getPayment: () => Promise<Payment>,
1093
+ /**
1094
+ * Gets the reactions associated with the given message
1095
+ */
1096
+ getReactions: () => Promise<ReactionList[]>,
1097
+ /** Edits the current message */
1098
+ edit: (content: MessageContent, options?: MessageEditOptions) => Promise<Message | null>,
1099
+ }
1100
+
1101
+ /** ID that represents a message */
1102
+ export interface MessageId {
1103
+ fromMe: boolean,
1104
+ remote: string,
1105
+ id: string,
1106
+ _serialized: string,
1107
+ }
1108
+
1109
+ /** Options for sending a location */
1110
+ export interface LocationSendOptions {
1111
+ /** Location name */
1112
+ name?: string;
1113
+ /** Location address */
1114
+ address?: string;
1115
+ /** URL address to be shown within a location message */
1116
+ url?: string;
1117
+ }
1118
+
1119
+ /** Location information */
1120
+ export class Location {
1121
+ latitude: string;
1122
+ longitude: string;
1123
+ name?: string;
1124
+ address?: string;
1125
+ url?: string;
1126
+ description?: string;
1127
+
1128
+ constructor(latitude: number, longitude: number, options?: LocationSendOptions)
1129
+ }
1130
+
1131
+ /** Poll send options */
1132
+ export interface PollSendOptions {
1133
+ /** False for a single choice poll, true for a multiple choice poll (false by default) */
1134
+ allowMultipleAnswers?: boolean,
1135
+ /**
1136
+ * The custom message secret, can be used as a poll ID
1137
+ * @note It has to be a unique vector with a length of 32
1138
+ */
1139
+ messageSecret: Array<number>|undefined
1140
+ }
1141
+
1142
+ /** Represents a Poll on WhatsApp */
1143
+ export class Poll {
1144
+ pollName: string
1145
+ pollOptions: Array<{
1146
+ name: string,
1147
+ localId: number
1148
+ }>
1149
+ options: PollSendOptions
1150
+
1151
+ constructor(pollName: string, pollOptions: Array<string>, options?: PollSendOptions)
1152
+ }
1153
+
1154
+ /** Represents a Poll Vote on WhatsApp */
1155
+ export interface PollVote {
1156
+ /** The person who voted */
1157
+ voter: string;
1158
+
1159
+ /**
1160
+ * The selected poll option(s)
1161
+ * If it's an empty array, the user hasn't selected any options on the poll,
1162
+ * may occur when they deselected all poll options
1163
+ */
1164
+ selectedOptions: SelectedPollOption[];
1165
+
1166
+ /** Timestamp the option was selected or deselected at */
1167
+ interractedAtTs: number;
1168
+
1169
+ /** The poll creation message associated with the poll vote */
1170
+ parentMessage: Message;
1171
+ }
1172
+
1173
+ /** Selected poll option structure */
1174
+ export interface SelectedPollOption {
1175
+ /** The local selected option ID */
1176
+ id: number;
1177
+
1178
+ /** The option name */
1179
+ name: string;
1180
+ }
1181
+
1182
+ export interface Label {
1183
+ /** Label name */
1184
+ name: string,
1185
+ /** Label ID */
1186
+ id: string,
1187
+ /** Color assigned to the label */
1188
+ hexColor: string,
1189
+
1190
+ /** Get all chats that have been assigned this Label */
1191
+ getChats: () => Promise<Chat[]>
1192
+ }
1193
+
1194
+ export interface Broadcast {
1195
+ /** Chat Object ID */
1196
+ id: {
1197
+ server: string,
1198
+ user: string,
1199
+ _serialized: string
1200
+ },
1201
+ /** Unix timestamp of last story */
1202
+ timestamp: number,
1203
+ /** Number of available statuses */
1204
+ totalCount: number,
1205
+ /** Number of not viewed */
1206
+ unreadCount: number,
1207
+ /** Unix timestamp of last story */
1208
+ msgs: Message[],
1209
+
1210
+ /** Returns the Chat of the owner of the story */
1211
+ getChat: () => Promise<Chat>,
1212
+ /** Returns the Contact of the owner of the story */
1213
+ getContact: () => Promise<Contact>,
1214
+ }
1215
+
1216
+ /** Options for sending a message */
1217
+ export interface MessageSendOptions {
1218
+ /** Show links preview. Has no effect on multi-device accounts. */
1219
+ linkPreview?: boolean
1220
+ /** Send audio as voice message with a generated waveform */
1221
+ sendAudioAsVoice?: boolean
1222
+ /** Send video as gif */
1223
+ sendVideoAsGif?: boolean
1224
+ /** Send media as sticker */
1225
+ sendMediaAsSticker?: boolean
1226
+ /** Send media as document */
1227
+ sendMediaAsDocument?: boolean
1228
+ /** Send media as quality HD */
1229
+ sendMediaAsHd?: boolean
1230
+ /** Send photo/video as a view once message */
1231
+ isViewOnce?: boolean
1232
+ /** Automatically parse vCards and send them as contacts */
1233
+ parseVCards?: boolean
1234
+ /** Image or videos caption */
1235
+ caption?: string
1236
+ /** Id of the message that is being quoted (or replied to) */
1237
+ quotedMessageId?: string
1238
+ /** User IDs to mention in the message */
1239
+ mentions?: string[]
1240
+ /** An array of object that handle group mentions */
1241
+ groupMentions?: {
1242
+ /** The name of a group to mention (can be custom) */
1243
+ subject: string,
1244
+ /** The group ID, e.g.: 'XXXXXXXXXX@g.us' */
1245
+ id: string
1246
+ }[]
1247
+ /** Send 'seen' status */
1248
+ sendSeen?: boolean
1249
+ /** Bot Wid when doing a bot mention like @Meta AI */
1250
+ invokedBotWid?: string
1251
+ /** Media to be sent */
1252
+ media?: MessageMedia
1253
+ /** Extra options */
1254
+ extra?: any
1255
+ /** Sticker name, if sendMediaAsSticker is true */
1256
+ stickerName?: string
1257
+ /** Sticker author, if sendMediaAsSticker is true */
1258
+ stickerAuthor?: string
1259
+ /** Sticker categories, if sendMediaAsSticker is true */
1260
+ stickerCategories?: string[],
1261
+ /** Should the bot send a quoted message without the quoted message if it fails to get the quote?
1262
+ * @default true (enabled) */
1263
+ ignoreQuoteErrors?: boolean
1264
+ }
1265
+
1266
+ /** Options for editing a message */
1267
+ export interface MessageEditOptions {
1268
+ /** Show links preview. Has no effect on multi-device accounts. */
1269
+ linkPreview?: boolean
1270
+ /** Contacts that are being mentioned in the message */
1271
+ mentions?: Contact[]
1272
+ /** Extra options */
1273
+ extra?: any
1274
+ }
1275
+
1276
+ export interface MediaFromURLOptions {
1277
+ client?: Client
1278
+ filename?: string
1279
+ unsafeMime?: boolean
1280
+ reqOptions?: RequestInit
1281
+ }
1282
+
1283
+ /** Media attached to a message */
1284
+ export class MessageMedia {
1285
+ /** MIME type of the attachment */
1286
+ mimetype: string
1287
+ /** Base64-encoded data of the file */
1288
+ data: string
1289
+ /** Document file name. Value can be null */
1290
+ filename?: string | null
1291
+ /** Document file size in bytes. Value can be null. */
1292
+ filesize?: number | null
1293
+
1294
+ /**
1295
+ * @param {string} mimetype MIME type of the attachment
1296
+ * @param {string} data Base64-encoded data of the file
1297
+ * @param {?string} filename Document file name. Value can be null
1298
+ * @param {?number} filesize Document file size in bytes. Value can be null.
1299
+ */
1300
+ constructor(mimetype: string, data: string, filename?: string | null, filesize?: number | null)
1301
+
1302
+ /** Creates a MessageMedia instance from a local file path */
1303
+ static fromFilePath: (filePath: string) => MessageMedia
1304
+
1305
+ /** Creates a MessageMedia instance from a URL */
1306
+ static fromUrl: (url: string, options?: MediaFromURLOptions) => Promise<MessageMedia>
1307
+ }
1308
+
1309
+ export type MessageContent = string | MessageMedia | Location | Poll | Contact | Contact[] | List | Buttons
1310
+
1311
+ /**
1312
+ * Represents a Contact on WhatsApp
1313
+ *
1314
+ * @example
1315
+ * {
1316
+ * id: {
1317
+ * server: 'c.us',
1318
+ * user: '554199999999',
1319
+ * _serialized: `554199999999@c.us`
1320
+ * },
1321
+ * number: '554199999999',
1322
+ * isBusiness: false,
1323
+ * isEnterprise: false,
1324
+ * labels: [],
1325
+ * name: undefined,
1326
+ * pushname: 'John',
1327
+ * sectionHeader: undefined,
1328
+ * shortName: undefined,
1329
+ * statusMute: false,
1330
+ * type: 'in',
1331
+ * verifiedLevel: undefined,
1332
+ * verifiedName: undefined,
1333
+ * isMe: false,
1334
+ * isUser: true,
1335
+ * isGroup: false,
1336
+ * isWAContact: true,
1337
+ * isMyContact: false
1338
+ * }
1339
+ */
1340
+ export interface Contact {
1341
+ /** Contact's phone number */
1342
+ number: string,
1343
+ /** Indicates if the contact is a business contact */
1344
+ isBusiness: boolean,
1345
+ /** ID that represents the contact */
1346
+ id: ContactId,
1347
+ /** Indicates if the contact is an enterprise contact */
1348
+ isEnterprise: boolean,
1349
+ /** Indicates if the contact is a group contact */
1350
+ isGroup: boolean,
1351
+ /** Indicates if the contact is the current user's contact */
1352
+ isMe: boolean,
1353
+ /** Indicates if the number is saved in the current phone's contacts */
1354
+ isMyContact: boolean
1355
+ /** Indicates if the contact is a user contact */
1356
+ isUser: boolean,
1357
+ /** Indicates if the number is registered on WhatsApp */
1358
+ isWAContact: boolean,
1359
+ /** Indicates if you have blocked this contact */
1360
+ isBlocked: boolean,
1361
+ /** @todo verify labels type. didn't have any documentation */
1362
+ labels?: string[],
1363
+ /** The contact's name, as saved by the current user */
1364
+ name?: string,
1365
+ /** The name that the contact has configured to be shown publically */
1366
+ pushname: string,
1367
+ /** @todo missing documentation */
1368
+ sectionHeader: string,
1369
+ /** A shortened version of name */
1370
+ shortName?: string,
1371
+ /** Indicates if the status from the contact is muted */
1372
+ statusMute: boolean,
1373
+ /** @todo missing documentation */
1374
+ type: string,
1375
+ /** @todo missing documentation */
1376
+ verifiedLevel?: undefined,
1377
+ /** @todo missing documentation */
1378
+ verifiedName?: undefined,
1379
+
1380
+ /** Returns the contact's profile picture URL, if privacy settings allow it */
1381
+ getProfilePicUrl: () => Promise<string>,
1382
+
1383
+ /** Returns the Chat that corresponds to this Contact.
1384
+ * Will return null when getting chat for currently logged in user.
1385
+ */
1386
+ getChat: () => Promise<Chat>,
1387
+
1388
+ /** Returns the contact's countrycode, (1541859685@c.us) => (1) */
1389
+ getCountryCode(): Promise<string>,
1390
+
1391
+ /** Returns the contact's formatted phone number, (12345678901@c.us) => (+1 (234) 5678-901) */
1392
+ getFormattedNumber(): Promise<string>,
1393
+
1394
+ /** Blocks this contact from WhatsApp */
1395
+ block: () => Promise<boolean>,
1396
+
1397
+ /** Unlocks this contact from WhatsApp */
1398
+ unblock: () => Promise<boolean>,
1399
+
1400
+ /** Gets the Contact's current "about" info. Returns null if you don't have permission to read their status. */
1401
+ getAbout: () => Promise<string | null>,
1402
+
1403
+ /** Gets the Contact's common groups with you. Returns empty array if you don't have any common group. */
1404
+ getCommonGroups: () => Promise<ChatId[]>
1405
+
1406
+ }
1407
+
1408
+ export interface ContactId {
1409
+ server: string,
1410
+ user: string,
1411
+ _serialized: string,
1412
+ }
1413
+
1414
+ export interface BusinessCategory {
1415
+ id: string,
1416
+ localized_display_name: string,
1417
+ }
1418
+
1419
+ export interface BusinessHoursOfDay {
1420
+ mode: string,
1421
+ hours: number[]
1422
+ }
1423
+
1424
+ export interface BusinessHours {
1425
+ config: {
1426
+ sun: BusinessHoursOfDay,
1427
+ mon: BusinessHoursOfDay,
1428
+ tue: BusinessHoursOfDay,
1429
+ wed: BusinessHoursOfDay,
1430
+ thu: BusinessHoursOfDay,
1431
+ fri: BusinessHoursOfDay,
1432
+ }
1433
+ timezone: string,
1434
+ }
1435
+
1436
+
1437
+
1438
+ export interface BusinessContact extends Contact {
1439
+ /**
1440
+ * The contact's business profile
1441
+ */
1442
+ businessProfile: {
1443
+ /** The contact's business profile id */
1444
+ id: ContactId,
1445
+
1446
+ /** The contact's business profile tag */
1447
+ tag: string,
1448
+
1449
+ /** The contact's business profile description */
1450
+ description: string,
1451
+
1452
+ /** The contact's business profile categories */
1453
+ categories: BusinessCategory[],
1454
+
1455
+ /** The contact's business profile options */
1456
+ profileOptions: {
1457
+ /** The contact's business profile commerce experience*/
1458
+ commerceExperience: string,
1459
+
1460
+ /** The contact's business profile cart options */
1461
+ cartEnabled: boolean,
1462
+ }
1463
+
1464
+ /** The contact's business profile email */
1465
+ email: string,
1466
+
1467
+ /** The contact's business profile websites */
1468
+ website: string[],
1469
+
1470
+ /** The contact's business profile latitude */
1471
+ latitude: number,
1472
+
1473
+ /** The contact's business profile longitude */
1474
+ longitude: number,
1475
+
1476
+ /** The contact's business profile work hours*/
1477
+ businessHours: BusinessHours
1478
+
1479
+ /** The contact's business profile address */
1480
+ address: string,
1481
+
1482
+ /** The contact's business profile facebook page */
1483
+ fbPage: object,
1484
+
1485
+ /** Indicate if the contact's business profile linked */
1486
+ ifProfileLinked: boolean
1487
+
1488
+ /** The contact's business profile coverPhoto */
1489
+ coverPhoto: null | any,
1490
+ }
1491
+ }
1492
+
1493
+ export interface PrivateContact extends Contact {
1494
+
1495
+ }
1496
+
1497
+ /**
1498
+ * Represents a Chat on WhatsApp
1499
+ *
1500
+ * @example
1501
+ * {
1502
+ * id: {
1503
+ * server: 'c.us',
1504
+ * user: '554199999999',
1505
+ * _serialized: `554199999999@c.us`
1506
+ * },
1507
+ * name: '+55 41 9999-9999',
1508
+ * isGroup: false,
1509
+ * isReadOnly: false,
1510
+ * unreadCount: 6,
1511
+ * timestamp: 1591484087,
1512
+ * archived: false
1513
+ * }
1514
+ */
1515
+ export interface Chat {
1516
+ /** Indicates if the Chat is archived */
1517
+ archived: boolean,
1518
+ /** ID that represents the chat */
1519
+ id: ChatId,
1520
+ /** Indicates if the Chat is a Group Chat */
1521
+ isGroup: boolean,
1522
+ /** Indicates if the Chat is readonly */
1523
+ isReadOnly: boolean,
1524
+ /** Indicates if the Chat is muted */
1525
+ isMuted: boolean,
1526
+ /** Unix timestamp for when the mute expires */
1527
+ muteExpiration: number,
1528
+ /** Title of the chat */
1529
+ name: string,
1530
+ /** Unix timestamp for when the last activity occurred */
1531
+ timestamp: number,
1532
+ /** Amount of messages unread */
1533
+ unreadCount: number,
1534
+ /** Last message of chat */
1535
+ lastMessage: Message,
1536
+ /** Indicates if the Chat is pinned */
1537
+ pinned: boolean,
1538
+
1539
+ /** Archives this chat */
1540
+ archive: () => Promise<void>,
1541
+ /** Pins this chat and returns its new Pin state */
1542
+ pin: () => Promise<boolean>,
1543
+ /** Unpins this chat and returns its new Pin state */
1544
+ unpin: () => Promise<boolean>,
1545
+ /** Clears all messages from the chat */
1546
+ clearMessages: () => Promise<boolean>,
1547
+ /** Stops typing or recording in chat immediately. */
1548
+ clearState: () => Promise<boolean>,
1549
+ /** Deletes the chat */
1550
+ delete: () => Promise<boolean>,
1551
+ /** Loads chat messages, sorted from earliest to latest. */
1552
+ fetchMessages: (searchOptions: MessageSearchOptions) => Promise<Message[]>,
1553
+ /** Mutes this chat forever, unless a date is specified */
1554
+ mute: (unmuteDate?: Date) => Promise<{ isMuted: boolean, muteExpiration: number }>,
1555
+ /** Send a message to this chat */
1556
+ sendMessage: (content: MessageContent, options?: MessageSendOptions) => Promise<Message>,
1557
+ /** Sets the chat as seen */
1558
+ sendSeen: () => Promise<boolean>,
1559
+ /** Simulate recording audio in chat. This will last for 25 seconds */
1560
+ sendStateRecording: () => Promise<void>,
1561
+ /** Simulate typing in chat. This will last for 25 seconds. */
1562
+ sendStateTyping: () => Promise<void>,
1563
+ /** un-archives this chat */
1564
+ unarchive: () => Promise<void>,
1565
+ /** Unmutes this chat */
1566
+ unmute: () => Promise<{ isMuted: boolean, muteExpiration: number }>,
1567
+ /** Returns the Contact that corresponds to this Chat. */
1568
+ getContact: () => Promise<Contact>,
1569
+ /** Marks this Chat as unread */
1570
+ markUnread: () => Promise<void>,
1571
+ /** Returns array of all Labels assigned to this Chat */
1572
+ getLabels: () => Promise<Label[]>,
1573
+ /** Add or remove labels to this Chat */
1574
+ changeLabels: (labelIds: Array<string | number>) => Promise<void>
1575
+ /** Sync history conversation of the Chat */
1576
+ syncHistory: () => Promise<boolean>
1577
+ }
1578
+
1579
+ export interface Channel {
1580
+ /** ID that represents the channel */
1581
+ id: {
1582
+ server: string;
1583
+ user: string;
1584
+ _serialized: string;
1585
+ };
1586
+ /** Title of the channel */
1587
+ name: string;
1588
+ /** The channel description */
1589
+ description: string;
1590
+ /** Indicates if it is a Channel */
1591
+ isChannel: boolean;
1592
+ /** Indicates if it is a Group */
1593
+ isGroup: boolean;
1594
+ /** Indicates if the channel is readonly */
1595
+ isReadOnly: boolean;
1596
+ /** Amount of messages unread */
1597
+ unreadCount: number;
1598
+ /** Unix timestamp for when the last activity occurred */
1599
+ timestamp: number;
1600
+ /** Indicates if the channel is muted or not */
1601
+ isMuted: boolean;
1602
+ /** Unix timestamp for when the mute expires */
1603
+ muteExpiration: number;
1604
+ /** Last message in the channel */
1605
+ lastMessage: Message | undefined;
1606
+
1607
+ /** Gets the subscribers of the channel (only those who are in your contact list) */
1608
+ getSubscribers(limit?: number): Promise<{contact: Contact, role: string}[]>;
1609
+ /** Updates the channel subject */
1610
+ setSubject(newSubject: string): Promise<boolean>;
1611
+ /** Updates the channel description */
1612
+ setDescription(newDescription: string): Promise<boolean>;
1613
+ /** Updates the channel profile picture */
1614
+ setProfilePicture(newProfilePicture: MessageMedia): Promise<boolean>;
1615
+ /**
1616
+ * Updates available reactions to use in the channel
1617
+ *
1618
+ * Valid values for passing to the method are:
1619
+ * 0 for NONE reactions to be avaliable
1620
+ * 1 for BASIC reactions to be available: 👍, ❤️, 😂, 😮, 😢, 🙏
1621
+ * 2 for ALL reactions to be available
1622
+ */
1623
+ setReactionSetting(reactionCode: number): Promise<boolean>;
1624
+ /** Mutes the channel */
1625
+ mute(): Promise<boolean>;
1626
+ /** Unmutes the channel */
1627
+ unmute(): Promise<boolean>;
1628
+ /** Sends a message to this channel */
1629
+ sendMessage(content: string|MessageMedia, options?: MessageSendChannelOptions): Promise<Message>;
1630
+ /** Sets the channel as seen */
1631
+ sendSeen(): Promise<boolean>;
1632
+ /** Sends a channel admin invitation to a user, allowing them to become an admin of the channel */
1633
+ sendChannelAdminInvite(chatId: string, options?: { comment?: string }): Promise<boolean>;
1634
+ /** Accepts a channel admin invitation and promotes the current user to a channel admin */
1635
+ acceptChannelAdminInvite(): Promise<boolean>;
1636
+ /** Revokes a channel admin invitation sent to a user by a channel owner */
1637
+ revokeChannelAdminInvite(userId: string): Promise<boolean>;
1638
+ /** Demotes a channel admin to a regular subscriber (can be used also for self-demotion) */
1639
+ demoteChannelAdmin(userId: string): Promise<boolean>;
1640
+ /** Loads channel messages, sorted from earliest to latest */
1641
+ fetchMessages: (searchOptions: MessageSearchOptions) => Promise<Message[]>;
1642
+ /**
1643
+ * Transfers a channel ownership to another user.
1644
+ * Note: the user you are transferring the channel ownership to must be a channel admin.
1645
+ */
1646
+ transferChannelOwnership(newOwnerId: string, options?: TransferChannelOwnershipOptions): Promise<boolean>;
1647
+ /** Deletes the channel you created */
1648
+ deleteChannel(): Promise<boolean>;
1649
+ }
1650
+
1651
+ /** Options for transferring a channel ownership to another user */
1652
+ export interface TransferChannelOwnershipOptions {
1653
+ /**
1654
+ * If true, after the channel ownership is being transferred to another user,
1655
+ * the current user will be dismissed as a channel admin and will become to a channel subscriber.
1656
+ */
1657
+ shouldDismissSelfAsAdmin?: boolean
1658
+ }
1659
+
1660
+ /** Options for sending a message */
1661
+ export interface MessageSendChannelOptions {
1662
+ /** Image or videos caption */
1663
+ caption?: string
1664
+ /** User IDs of user that will be mentioned in the message */
1665
+ mentions?: string[]
1666
+ /** Image or video to be sent */
1667
+ media?: MessageMedia
1668
+ /** Extra options */
1669
+ extra?: any
1670
+ }
1671
+
1672
+ export interface MessageSearchOptions {
1673
+ /**
1674
+ * The amount of messages to return. If no limit is specified, the available messages will be returned.
1675
+ * Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation.
1676
+ * Set this to Infinity to load all messages.
1677
+ */
1678
+ limit?: number
1679
+ /**
1680
+ * Return only messages from the bot number or vise versa. To get all messages, leave the option undefined.
1681
+ */
1682
+ fromMe?: boolean
1683
+ }
1684
+
1685
+ /**
1686
+ * Id that represents the chat
1687
+ *
1688
+ * @example
1689
+ * id: {
1690
+ * server: 'c.us',
1691
+ * user: '554199999999',
1692
+ * _serialized: `554199999999@c.us`
1693
+ * },
1694
+ */
1695
+ export interface ChatId {
1696
+ /**
1697
+ * Whatsapp server domain
1698
+ * @example `c.us`
1699
+ */
1700
+ server: string,
1701
+ /**
1702
+ * User whatsapp number
1703
+ * @example `554199999999`
1704
+ */
1705
+ user: string,
1706
+ /**
1707
+ * Serialized id
1708
+ * @example `554199999999@c.us`
1709
+ */
1710
+ _serialized: string,
1711
+ }
1712
+
1713
+ export interface PrivateChat extends Chat {
1714
+
1715
+ }
1716
+
1717
+ export type GroupParticipant = {
1718
+ id: ContactId,
1719
+ isAdmin: boolean
1720
+ isSuperAdmin: boolean
1721
+ }
1722
+
1723
+ /** Promotes or demotes participants by IDs to regular users or admins */
1724
+ export type ChangeParticipantsPermissions =
1725
+ (participantIds: Array<string>) => Promise<{ status: number }>
1726
+
1727
+ /** An object that handles the result for addParticipants method */
1728
+ export interface AddParticipantsResult {
1729
+ [participantId: string]: {
1730
+ code: number;
1731
+ message: string;
1732
+ isInviteV4Sent: boolean,
1733
+ }
1734
+ }
1735
+
1736
+ /** An object that handles options for adding participants */
1737
+ export interface AddParticipantsOptions {
1738
+ /**
1739
+ * The number of milliseconds to wait before adding the next participant.
1740
+ * If it is an array, a random sleep time between the sleep[0] and sleep[1] values will be added
1741
+ * (the difference must be >=100 ms, otherwise, a random sleep time between sleep[1] and sleep[1] + 100
1742
+ * will be added). If sleep is a number, a sleep time equal to its value will be added
1743
+ * @default [250,500]
1744
+ */
1745
+ sleep?: Array<number>|number,
1746
+ /**
1747
+ * If true, the inviteV4 will be sent to those participants
1748
+ * who have restricted others from being automatically added to groups,
1749
+ * otherwise the inviteV4 won't be sent
1750
+ * @default true
1751
+ */
1752
+ autoSendInviteV4?: boolean,
1753
+ /**
1754
+ * The comment to be added to an inviteV4 (empty string by default)
1755
+ * @default ''
1756
+ */
1757
+ comment?: string
1758
+ }
1759
+
1760
+ /** An object that handles the information about the group membership request */
1761
+ export interface GroupMembershipRequest {
1762
+ /** The wid of a user who requests to enter the group */
1763
+ id: Object;
1764
+ /** The wid of a user who created that request */
1765
+ addedBy: Object;
1766
+ /** The wid of a community parent group to which the current group is linked */
1767
+ parentGroupId: Object | null;
1768
+ /** The method used to create the request: NonAdminAdd/InviteLink/LinkedGroupJoin */
1769
+ requestMethod: string,
1770
+ /** The timestamp the request was created at */
1771
+ t: number
1772
+ }
1773
+
1774
+ /** An object that handles the result for membership request action */
1775
+ export interface MembershipRequestActionResult {
1776
+ /** User ID whos membership request was approved/rejected */
1777
+ requesterId: Array<string> | string | null;
1778
+ /** An error code that occurred during the operation for the participant */
1779
+ error?: number;
1780
+ /** A message with a result of membership request action */
1781
+ message: string;
1782
+ }
1783
+
1784
+ /** Options for performing a membership request action */
1785
+ export interface MembershipRequestActionOptions {
1786
+ /** User ID/s who requested to join the group, if no value is provided, the method will search for all membership requests for that group */
1787
+ requesterIds: Array<string> | string | null;
1788
+ /** The number of milliseconds to wait before performing an operation for the next requester. If it is an array, a random sleep time between the sleep[0] and sleep[1] values will be added (the difference must be >=100 ms, otherwise, a random sleep time between sleep[1] and sleep[1] + 100 will be added). If sleep is a number, a sleep time equal to its value will be added. By default, sleep is an array with a value of [250, 500] */
1789
+ sleep: Array<number> | number | null;
1790
+ }
1791
+
1792
+ export interface GroupChat extends Chat {
1793
+ /** Group owner */
1794
+ owner: ContactId;
1795
+ /** Date at which the group was created */
1796
+ createdAt: Date;
1797
+ /** Group description */
1798
+ description: string;
1799
+ /** Group participants */
1800
+ participants: Array<GroupParticipant>;
1801
+ /** Adds a list of participants by ID to the group */
1802
+ addParticipants: (participantIds: string | string[], options?: AddParticipantsOptions) => Promise<{ [key: string]: AddParticipantsResult } | string>;
1803
+ /** Removes a list of participants by ID to the group */
1804
+ removeParticipants: (participantIds: string[]) => Promise<{ status: number }>;
1805
+ /** Promotes participants by IDs to admins */
1806
+ promoteParticipants: ChangeParticipantsPermissions;
1807
+ /** Demotes participants by IDs to regular users */
1808
+ demoteParticipants: ChangeParticipantsPermissions;
1809
+ /** Updates the group subject */
1810
+ setSubject: (subject: string) => Promise<boolean>;
1811
+ /** Updates the group description */
1812
+ setDescription: (description: string) => Promise<boolean>;
1813
+ /**
1814
+ * Updates the group setting to allow only admins to add members to the group.
1815
+ * @param {boolean} [adminsOnly=true] Enable or disable this option
1816
+ * @returns {Promise<boolean>} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.
1817
+ */
1818
+ setAddMembersAdminsOnly: (adminsOnly?: boolean) => Promise<boolean>;
1819
+ /** Updates the group settings to only allow admins to send messages
1820
+ * @param {boolean} [adminsOnly=true] Enable or disable this option
1821
+ * @returns {Promise<boolean>} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.
1822
+ */
1823
+ setMessagesAdminsOnly: (adminsOnly?: boolean) => Promise<boolean>;
1824
+ /**
1825
+ * Updates the group settings to only allow admins to edit group info (title, description, photo).
1826
+ * @param {boolean} [adminsOnly=true] Enable or disable this option
1827
+ * @returns {Promise<boolean>} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.
1828
+ */
1829
+ setInfoAdminsOnly: (adminsOnly?: boolean) => Promise<boolean>;
1830
+ /**
1831
+ * Gets an array of membership requests
1832
+ * @returns {Promise<Array<GroupMembershipRequest>>} An array of membership requests
1833
+ */
1834
+ getGroupMembershipRequests: () => Promise<Array<GroupMembershipRequest>>;
1835
+ /**
1836
+ * Approves membership requests if any
1837
+ * @param {MembershipRequestActionOptions} options Options for performing a membership request action
1838
+ * @returns {Promise<Array<MembershipRequestActionResult>>} Returns an array of requester IDs whose membership requests were approved and an error for each requester, if any occurred during the operation. If there are no requests, an empty array will be returned
1839
+ */
1840
+ approveGroupMembershipRequests: (options: MembershipRequestActionOptions) => Promise<Array<MembershipRequestActionResult>>;
1841
+ /**
1842
+ * Rejects membership requests if any
1843
+ * @param {MembershipRequestActionOptions} options Options for performing a membership request action
1844
+ * @returns {Promise<Array<MembershipRequestActionResult>>} Returns an array of requester IDs whose membership requests were rejected and an error for each requester, if any occurred during the operation. If there are no requests, an empty array will be returned
1845
+ */
1846
+ rejectGroupMembershipRequests: (options: MembershipRequestActionOptions) => Promise<Array<MembershipRequestActionResult>>;
1847
+ /** Gets the invite code for a specific group */
1848
+ getInviteCode: () => Promise<string>;
1849
+ /** Invalidates the current group invite code and generates a new one */
1850
+ revokeInvite: () => Promise<void>;
1851
+ /** Makes the bot leave the group */
1852
+ leave: () => Promise<void>;
1853
+ /** Sets the group's picture.*/
1854
+ setPicture: (media: MessageMedia) => Promise<boolean>;
1855
+ /** Deletes the group's picture */
1856
+ deletePicture: () => Promise<boolean>;
1857
+ }
1858
+
1859
+ /**
1860
+ * Represents the metadata associated with a given product
1861
+ *
1862
+ */
1863
+ export interface ProductMetadata {
1864
+ /** Product Id */
1865
+ id: string,
1866
+ /** Product Name */
1867
+ name: string,
1868
+ /** Product Description */
1869
+ description: string,
1870
+ /** Retailer ID */
1871
+ retailer_id?: string
1872
+ }
1873
+
1874
+ /**
1875
+ * Represents a Product on Whatsapp
1876
+ * @example
1877
+ * {
1878
+ * "id": "123456789",
1879
+ * "price": "150000",
1880
+ * "thumbnailId": "123456789",
1881
+ * "thumbnailUrl": "https://mmg.whatsapp.net",
1882
+ * "currency": "GTQ",
1883
+ * "name": "Store Name",
1884
+ * "quantity": 1
1885
+ * }
1886
+ */
1887
+ export interface Product {
1888
+ /** Product Id */
1889
+ id: string,
1890
+ /** Price */
1891
+ price?: string,
1892
+ /** Product Thumbnail*/
1893
+ thumbnailUrl: string,
1894
+ /** Currency */
1895
+ currency: string,
1896
+ /** Product Name */
1897
+ name: string,
1898
+ /** Product Quantity*/
1899
+ quantity: number,
1900
+ /** Gets the Product metadata */
1901
+ getData: () => Promise<ProductMetadata>
1902
+ }
1903
+
1904
+ /**
1905
+ * Represents a Order on WhatsApp
1906
+ *
1907
+ * @example
1908
+ * {
1909
+ * "products": [
1910
+ * {
1911
+ * "id": "123456789",
1912
+ * "price": "150000",
1913
+ * "thumbnailId": "123456789",
1914
+ * "thumbnailUrl": "https://mmg.whatsapp.net",
1915
+ * "currency": "GTQ",
1916
+ * "name": "Store Name",
1917
+ * "quantity": 1
1918
+ * }
1919
+ * ],
1920
+ * "subtotal": "150000",
1921
+ * "total": "150000",
1922
+ * "currency": "GTQ",
1923
+ * "createdAt": 1610136796,
1924
+ * "sellerJid": "55555555@s.whatsapp.net"
1925
+ * }
1926
+ */
1927
+ export interface Order {
1928
+ /** List of products*/
1929
+ products: Array<Product>,
1930
+ /** Order Subtotal */
1931
+ subtotal: string,
1932
+ /** Order Total */
1933
+ total: string,
1934
+ /** Order Currency */
1935
+ currency: string,
1936
+ /** Order Created At*/
1937
+ createdAt: number;
1938
+ }
1939
+
1940
+ /**
1941
+ * Represents a Payment on WhatsApp
1942
+ *
1943
+ * @example
1944
+ * {
1945
+ * id: {
1946
+ * fromMe: true,
1947
+ * remote: {
1948
+ * server: 'c.us',
1949
+ * user: '5511999999999',
1950
+ * _serialized: '5511999999999@c.us'
1951
+ * },
1952
+ * id: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
1953
+ * _serialized: 'true_5511999999999@c.us_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
1954
+ * },
1955
+ * paymentCurrency: 'BRL',
1956
+ * paymentAmount1000: 1000,
1957
+ * paymentMessageReceiverJid: {
1958
+ * server: 'c.us',
1959
+ * user: '5511999999999',
1960
+ * _serialized: '5511999999999@c.us'
1961
+ * },
1962
+ * paymentTransactionTimestamp: 1623463058,
1963
+ * paymentStatus: 4,
1964
+ * paymentTxnStatus: 4,
1965
+ * paymentNote: 'note'
1966
+ * }
1967
+ */
1968
+ export interface Payment {
1969
+ /** Payment Id*/
1970
+ id: object,
1971
+ /** Payment currency */
1972
+ paymentCurrency: string,
1973
+ /** Payment ammount */
1974
+ paymentAmount1000 : number,
1975
+ /** Payment receiver */
1976
+ paymentMessageReceiverJid : object,
1977
+ /** Payment transaction timestamp */
1978
+ paymentTransactionTimestamp : number,
1979
+ /** Payment paymentStatus */
1980
+ paymentStatus : number,
1981
+ /** Integer that represents the payment Text */
1982
+ paymentTxnStatus : number,
1983
+ /** The note sent with the payment */
1984
+ paymentNote : string;
1985
+ }
1986
+
1987
+ /**
1988
+ * Represents a Call on WhatsApp
1989
+ *
1990
+ * @example
1991
+ * Call {
1992
+ * id: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
1993
+ * from: '5511999999@c.us',
1994
+ * timestamp: 1625003709,
1995
+ * isVideo: false,
1996
+ * isGroup: false,
1997
+ * fromMe: false,
1998
+ * canHandleLocally: false,
1999
+ * webClientShouldHandle: false,
2000
+ * participants: []
2001
+ * }
2002
+ */
2003
+ export interface Call {
2004
+ /** Call Id */
2005
+ id: string,
2006
+ /** from */
2007
+ from?: string,
2008
+ /** Unix timestamp for when the call was created*/
2009
+ timestamp: number,
2010
+ /** Is video */
2011
+ isVideo: boolean,
2012
+ /** Is Group */
2013
+ isGroup: boolean,
2014
+ /** Indicates if the call was sent by the current user */
2015
+ fromMe: boolean,
2016
+ /** indicates if the call can be handled in waweb */
2017
+ canHandleLocally: boolean,
2018
+ /** indicates if the call should be handled in waweb */
2019
+ webClientShouldHandle: boolean,
2020
+ /** Object with participants */
2021
+ participants: object
2022
+
2023
+ /** Reject the call */
2024
+ reject: () => Promise<void>
2025
+ }
2026
+
2027
+ /** Message type List */
2028
+ export class List {
2029
+ body: string
2030
+ buttonText: string
2031
+ sections: Array<any>
2032
+ title?: string | null
2033
+ footer?: string | null
2034
+
2035
+ constructor(body: string, buttonText: string, sections: Array<any>, title?: string | null, footer?: string | null)
2036
+ }
2037
+
2038
+ /** Message type Buttons */
2039
+ export class Buttons {
2040
+ body: string | MessageMedia
2041
+ buttons: Array<{ buttonId: string; buttonText: {displayText: string}; type: number }>
2042
+ title?: string | null
2043
+ footer?: string | null
2044
+
2045
+ constructor(body: string, buttons: Array<{ id?: string; body: string }>, title?: string | null, footer?: string | null)
2046
+ }
2047
+
2048
+ /** Message type Reaction */
2049
+ export class Reaction {
2050
+ id: MessageId
2051
+ orphan: number
2052
+ orphanReason?: string
2053
+ timestamp: number
2054
+ reaction: string
2055
+ read: boolean
2056
+ msgId: MessageId
2057
+ senderId: string
2058
+ ack?: number
2059
+ }
2060
+
2061
+ export type ReactionList = {
2062
+ id: string,
2063
+ aggregateEmoji: string,
2064
+ hasReactionByMe: boolean,
2065
+ senders: Array<Reaction>
2066
+ }
2067
+ }
2068
+
2069
+ export = WAWebJS