@another-trial/whatsapp-web.js 1.34.1 → 1.35.0-alpha.2

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