-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
index.d.ts
1872 lines (1666 loc) · 66.3 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { EventEmitter } from 'events'
import { RequestInit } from 'node-fetch'
import * as puppeteer from 'puppeteer'
import InterfaceController from './src/util/InterfaceController'
declare namespace WAWebJS {
export class Client extends EventEmitter {
constructor(options: ClientOptions)
/** Current connection information */
public info: ClientInfo
/** Puppeteer page running WhatsApp Web */
pupPage?: puppeteer.Page
/** Puppeteer browser running WhatsApp Web */
pupBrowser?: puppeteer.Browser
/** Client interactivity interface */
interface?: InterfaceController
/**Accepts an invitation to join a group */
acceptInvite(inviteCode: string): Promise<string>
/** Accepts a private invitation to join a group (v4 invite) */
acceptGroupV4Invite: (inviteV4: InviteV4Data) => Promise<{status: number}>
/**Returns an object with information about the invite code's group */
getInviteInfo(inviteCode: string): Promise<object>
/** Enables and returns the archive state of the Chat */
archiveChat(chatId: string): Promise<boolean>
/** Pins the Chat and returns its new Pin state */
pinChat(chatId: string): Promise<boolean>
/** Unpins the Chat and returns its new Pin state */
unpinChat(chatId: string): Promise<boolean>
/** Creates a new group */
createGroup(title: string, participants?: string | Contact | Contact[] | string[], options?: CreateGroupOptions): Promise<CreateGroupResult|string>
/** Closes the client */
destroy(): Promise<void>
/** Logs out the client, closing the current session */
logout(): Promise<void>
/** Get all blocked contacts by host account */
getBlockedContacts(): Promise<Contact[]>
/** Get chat instance by ID */
getChatById(chatId: string): Promise<Chat>
/** Get all current chat instances */
getChats(): Promise<Chat[]>
/** Get contact instance by ID */
getContactById(contactId: string): Promise<Contact>
/** Get message by ID */
getMessageById(messageId: string): Promise<Message>
/** Get all current contact instances */
getContacts(): Promise<Contact[]>
/** Get the country code of a WhatsApp ID. ([email protected]) => (1) */
getCountryCode(number: string): Promise<string>
/** Get the formatted number of a WhatsApp ID. ([email protected]) => (+1 (234) 5678-901) */
getFormattedNumber(number: string): Promise<string>
/** Get all current Labels */
getLabels(): Promise<Label[]>
/** Get all current Broadcasts */
getBroadcasts(): Promise<Broadcast[]>
/** Change labels in chats */
addOrRemoveLabels(labelIds: Array<number|string>, chatIds: Array<string>): Promise<void>
/** Get Label instance by ID */
getLabelById(labelId: string): Promise<Label>
/** Get all Labels assigned to a Chat */
getChatLabels(chatId: string): Promise<Label[]>
/** Get all Chats for a specific Label */
getChatsByLabelId(labelId: string): Promise<Chat[]>
/** Returns the contact ID's profile picture URL, if privacy settings allow it */
getProfilePicUrl(contactId: string): Promise<string>
/** Gets the Contact's common groups with you. Returns empty array if you don't have any common group. */
getCommonGroups(contactId: string): Promise<ChatId[]>
/** Gets the current connection state for the client */
getState(): Promise<WAState>
/** Returns the version of WhatsApp Web currently being run */
getWWebVersion(): Promise<string>
/** Sets up events and requirements, kicks off authentication request */
initialize(): Promise<void>
/** Check if a given ID is registered in whatsapp */
isRegisteredUser(contactId: string): Promise<boolean>
/** Get the registered WhatsApp ID for a number. Returns null if the number is not registered on WhatsApp. */
getNumberId(number: string): Promise<ContactId | null>
/**
* Mutes this chat forever, unless a date is specified
* @param chatId ID of the chat that will be muted
* @param unmuteDate Date when the chat will be unmuted, leave as is to mute forever
*/
muteChat(chatId: string, unmuteDate?: Date): Promise<void>
/**
* Request authentication via pairing code instead of QR code
* @param phoneNumber - Phone number in international, symbol-free format (e.g. 12025550108 for US, 551155501234 for Brazil)
* @param showNotification - Show notification to pair on phone number
* @returns {Promise<string>} - Returns a pairing code in format "ABCDEFGH"
*/
requestPairingCode(phoneNumber: string, showNotification = true): Promise<string>
/** Force reset of connection state for the client */
resetState(): Promise<void>
/** Send a message to a specific chatId */
sendMessage(chatId: string, content: MessageContent, options?: MessageSendOptions): Promise<Message>
/** Searches for messages */
searchMessages(query: string, options?: { chatId?: string, page?: number, limit?: number }): Promise<Message[]>
/** Marks the client as online */
sendPresenceAvailable(): Promise<void>
/** Marks the client as offline */
sendPresenceUnavailable(): Promise<void>
/** Mark as seen for the Chat */
sendSeen(chatId: string): Promise<boolean>
/** Mark the Chat as unread */
markChatUnread(chatId: string): Promise<void>
/**
* Sets the current user's status message
* @param status New status message
*/
setStatus(status: string): Promise<void>
/**
* Sets the current user's display name
* @param displayName New display name
*/
setDisplayName(displayName: string): Promise<boolean>
/**
* Changes the autoload Audio
* @param flag true/false on or off
*/
setAutoDownloadAudio(flag: boolean): Promise<void>
/**
* Changes the autoload Documents
* @param flag true/false on or off
*/
setAutoDownloadDocuments(flag: boolean): Promise<void>
/**
* Changes the autoload Photos
* @param flag true/false on or off
*/
setAutoDownloadPhotos(flag: boolean): Promise<void>
/**
* Changes the autoload Videos
* @param flag true/false on or off
*/
setAutoDownloadVideos(flag: boolean): Promise<void>
/**
* Get user device count by ID
* Each WaWeb Connection counts as one device, and the phone (if exists) counts as one
* So for a non-enterprise user with one WaWeb connection it should return "2"
* @param {string} contactId
*/
getContactDeviceCount(userId: string): Promise<number>
/** Sync history conversation of the Chat */
syncHistory(chatId: string): Promise<boolean>
/** Changes and returns the archive state of the Chat */
unarchiveChat(chatId: string): Promise<boolean>
/** Unmutes the Chat */
unmuteChat(chatId: string): Promise<void>
/** Sets the current user's profile picture */
setProfilePicture(media: MessageMedia): Promise<boolean>
/** Deletes the current user's profile picture */
deleteProfilePicture(): Promise<boolean>
/** Gets an array of membership requests */
getGroupMembershipRequests: (groupId: string) => Promise<Array<GroupMembershipRequest>>
/** Approves membership requests if any */
approveGroupMembershipRequests: (groupId: string, options: MembershipRequestActionOptions) => Promise<Array<MembershipRequestActionResult>>;
/** Rejects membership requests if any */
rejectGroupMembershipRequests: (groupId: string, options: MembershipRequestActionOptions) => Promise<Array<MembershipRequestActionResult>>;
/** Generic event */
on(event: string, listener: (...args: any) => void): this
/** Emitted when there has been an error while trying to restore an existing session */
on(event: 'auth_failure', listener: (message: string) => void): this
/** Emitted when authentication is successful */
on(event: 'authenticated', listener: (
/**
* Object containing session information, when using LegacySessionAuth. Can be used to restore the session
*/
session?: ClientSession
) => void): this
/**
* Emitted when the battery percentage for the attached device changes
* @deprecated
*/
on(event: 'change_battery', listener: (batteryInfo: BatteryInfo) => void): this
/** Emitted when the connection state changes */
on(event: 'change_state', listener: (
/** the new connection state */
state: WAState
) => void): this
/** Emitted when the client has been disconnected */
on(event: 'disconnected', listener: (
/** reason that caused the disconnect */
reason: WAState | "LOGOUT"
) => void): this
/** Emitted when a user joins the chat via invite link or is added by an admin */
on(event: 'group_join', listener: (
/** GroupNotification with more information about the action */
notification: GroupNotification
) => void): this
/** Emitted when a user leaves the chat or is removed by an admin */
on(event: 'group_leave', listener: (
/** GroupNotification with more information about the action */
notification: GroupNotification
) => void): this
/** Emitted when a current user is promoted to an admin or demoted to a regular user */
on(event: 'group_admin_changed', listener: (
/** GroupNotification with more information about the action */
notification: GroupNotification
) => void): this
/**
* Emitted when some user requested to join the group
* that has the membership approval mode turned on
*/
on(event: 'group_membership_request', listener: (
/** GroupNotification with more information about the action */
notification: GroupNotification
) => void): this
/** Emitted when group settings are updated, such as subject, description or picture */
on(event: 'group_update', listener: (
/** GroupNotification with more information about the action */
notification: GroupNotification
) => void): this
/** Emitted when a contact or a group participant changed their phone number. */
on(event: 'contact_changed', listener: (
/** Message with more information about the event. */
message: Message,
/** Old user's id. */
oldId : String,
/** New user's id. */
newId : String,
/** Indicates if a contact or a group participant changed their phone number. */
isContact : Boolean
) => void): this
/** Emitted when media has been uploaded for a message sent by the client */
on(event: 'media_uploaded', listener: (
/** The message with media that was uploaded */
message: Message
) => void): this
/** Emitted when a new message is received */
on(event: 'message', listener: (
/** The message that was received */
message: Message
) => void): this
/** Emitted when an ack event occurrs on message type */
on(event: 'message_ack', listener: (
/** The message that was affected */
message: Message,
/** The new ACK value */
ack: MessageAck
) => void): this
/** Emitted when an ack event occurrs on message type */
on(event: 'message_edit', listener: (
/** The message that was affected */
message: Message,
/** New text message */
newBody: String,
/** Prev text message */
prevBody: String
) => void): this
/** Emitted when a chat unread count changes */
on(event: 'unread_count', listener: (
/** The chat that was affected */
chat: Chat
) => void): this
/** Emitted when a new message is created, which may include the current user's own messages */
on(event: 'message_create', listener: (
/** The message that was created */
message: Message
) => void): this
/** Emitted when a new message ciphertext is received */
on(event: 'message_ciphertext', listener: (
/** The message that was ciphertext */
message: Message
) => void): this
/** Emitted when a message is deleted for everyone in the chat */
on(event: 'message_revoke_everyone', listener: (
/** The message that was revoked, in its current state. It will not contain the original message's data */
message: Message,
/**The message that was revoked, before it was revoked.
* It will contain the message's original data.
* Note that due to the way this data is captured,
* it may be possible that this param will be undefined. */
revoked_msg?: Message | null
) => void): this
/** Emitted when a message is deleted by the current user */
on(event: 'message_revoke_me', listener: (
/** The message that was revoked */
message: Message
) => void): this
/** Emitted when a reaction is sent, received, updated or removed */
on(event: 'message_reaction', listener: (
/** The reaction object */
reaction: Reaction
) => void): this
/** Emitted when a chat is removed */
on(event: 'chat_removed', listener: (
/** The chat that was removed */
chat: Chat
) => void): this
/** Emitted when a chat is archived/unarchived */
on(event: 'chat_archived', listener: (
/** The chat that was archived/unarchived */
chat: Chat,
/** State the chat is currently in */
currState: boolean,
/** State the chat was previously in */
prevState: boolean
) => void): this
/** Emitted when loading screen is appearing */
on(event: 'loading_screen', listener: (percent: string, message: string) => void): this
/** Emitted when the QR code is received */
on(event: 'qr', listener: (
/** qr code string
* @example ```1@9Q8tWf6bnezr8uVGwVCluyRuBOJ3tIglimzI5dHB0vQW2m4DQ0GMlCGf,f1/vGcW4Z3vBa1eDNl3tOjWqLL5DpYTI84DMVkYnQE8=,ZL7YnK2qdPN8vKo2ESxhOQ==``` */
qr: string
) => void): this
/** Emitted when a call is received */
on(event: 'call', listener: (
/** The call that started */
call: Call
) => void): this
/** Emitted when the client has initialized and is ready to receive messages */
on(event: 'ready', listener: () => void): this
/** Emitted when the RemoteAuth session is saved successfully on the external Database */
on(event: 'remote_session_saved', listener: () => void): this
/**
* Emitted when some poll option is selected or deselected,
* shows a user's current selected option(s) on the poll
*/
on(event: 'vote_update', listener: (
vote: PollVote
) => void): this
}
/** Current connection information */
export interface ClientInfo {
/**
* Current user ID
* @deprecated Use .wid instead
*/
me: ContactId
/** Current user ID */
wid: ContactId
/**
* Information about the phone this client is connected to. Not available in multi-device.
* @deprecated
*/
phone: ClientInfoPhone
/** Platform the phone is running on */
platform: string
/** Name configured to be shown in push notifications */
pushname: string
/** Get current battery percentage and charging status for the attached device */
getBatteryStatus: () => Promise<BatteryInfo>
}
/**
* Information about the phone this client is connected to
* @deprecated
*/
export interface ClientInfoPhone {
/** WhatsApp Version running on the phone */
wa_version: string
/** OS Version running on the phone (iOS or Android version) */
os_version: string
/** Device manufacturer */
device_manufacturer: string
/** Device model */
device_model: string
/** OS build number */
os_build_number: string
}
/** Options for initializing the whatsapp client */
export interface ClientOptions {
/** Timeout for authentication selector in puppeteer
* @default 0 */
authTimeoutMs?: number,
/** Puppeteer launch options. View docs here: https://github.com/puppeteer/puppeteer/ */
puppeteer?: puppeteer.PuppeteerNodeLaunchOptions & puppeteer.ConnectOptions
/** Determines how to save and restore sessions. Will use LegacySessionAuth if options.session is set. Otherwise, NoAuth will be used. */
authStrategy?: AuthStrategy,
/** The version of WhatsApp Web to use. Use options.webVersionCache to configure how the version is retrieved. */
webVersion?: string,
/** Determines how to retrieve the WhatsApp Web version specified in options.webVersion. */
webVersionCache?: WebCacheOptions,
/** How many times should the qrcode be refreshed before giving up
* @default 0 (disabled) */
qrMaxRetries?: number,
/**
* @deprecated This option should be set directly on the LegacySessionAuth
*/
restartOnAuthFail?: boolean
/**
* @deprecated Only here for backwards-compatibility. You should move to using LocalAuth, or set the authStrategy to LegacySessionAuth explicitly.
*/
session?: ClientSession
/** If another whatsapp web session is detected (another browser), take over the session in the current browser
* @default false */
takeoverOnConflict?: boolean,
/** How much time to wait before taking over the session
* @default 0 */
takeoverTimeoutMs?: number,
/** User agent to use in puppeteer.
* @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' */
userAgent?: string
/** Ffmpeg path to use when formatting videos to webp while sending stickers
* @default 'ffmpeg' */
ffmpegPath?: string,
/** Object with proxy autentication requirements @default: undefined */
proxyAuthentication?: {username: string, password: string} | undefined
}
export interface LocalWebCacheOptions {
type: 'local',
path?: string,
strict?: boolean
}
export interface RemoteWebCacheOptions {
type: 'remote',
remotePath: string,
strict?: boolean
}
export interface NoWebCacheOptions {
type: 'none'
}
export type WebCacheOptions = NoWebCacheOptions | LocalWebCacheOptions | RemoteWebCacheOptions;
/**
* Base class which all authentication strategies extend
*/
export abstract class AuthStrategy {
setup: (client: Client) => void;
beforeBrowserInitialized: () => Promise<void>;
afterBrowserInitialized: () => Promise<void>;
onAuthenticationNeeded: () => Promise<{
failed?: boolean;
restart?: boolean;
failureEventPayload?: any
}>;
getAuthEventPayload: () => Promise<any>;
afterAuthReady: () => Promise<void>;
disconnect: () => Promise<void>;
destroy: () => Promise<void>;
logout: () => Promise<void>;
}
/**
* No session restoring functionality
* Will need to authenticate via QR code every time
*/
export class NoAuth extends AuthStrategy {}
/**
* Local directory-based authentication
*/
export class LocalAuth extends AuthStrategy {
public clientId?: string;
public dataPath?: string;
constructor(options?: {
clientId?: string,
dataPath?: string
})
}
/**
* Remote-based authentication
*/
export class RemoteAuth extends AuthStrategy {
public clientId?: string;
public dataPath?: string;
constructor(options?: {
store: Store,
clientId?: string,
dataPath?: string,
backupSyncIntervalMs: number
})
}
/**
* Remote store interface
*/
export interface Store {
sessionExists: (options: { session: string }) => Promise<boolean> | boolean,
delete: (options: { session: string }) => Promise<any> | any,
save: (options: { session: string }) => Promise<any> | any,
extract: (options: { session: string, path: string }) => Promise<any> | any,
}
/**
* Legacy session auth strategy
* Not compatible with multi-device accounts.
*/
export class LegacySessionAuth extends AuthStrategy {
constructor(options?: {
session?: ClientSession,
restartOnAuthFail?: boolean,
})
}
/**
* Represents a WhatsApp client session
*/
export interface ClientSession {
WABrowserId: string,
WASecretBundle: string,
WAToken1: string,
WAToken2: string,
}
/**
* @deprecated
*/
export interface BatteryInfo {
/** The current battery percentage */
battery: number,
/** Indicates if the phone is plugged in (true) or not (false) */
plugged: boolean,
}
/** An object that handles options for group creation */
export interface CreateGroupOptions {
/**
* The number of seconds for the messages to disappear in the group,
* won't take an effect if the group is been creating with myself only
* @default 0
*/
messageTimer?: number
/**
* The ID of a parent community group to link the newly created group with,
* won't take an effect if the group is been creating with myself only
*/
parentGroupId?: string
/** If true, the inviteV4 will be sent to those participants
* who have restricted others from being automatically added to groups,
* otherwise the inviteV4 won't be sent
* @default true
*/
autoSendInviteV4?: boolean,
/**
* The comment to be added to an inviteV4 (empty string by default)
* @default ''
*/
comment?: string
}
/** An object that handles the result for createGroup method */
export interface CreateGroupResult {
/** A group title */
title: string;
/** An object that handles the newly created group ID */
gid: ChatId;
/** An object that handles the result value for each added to the group participant */
participants: {
[participantId: string]: {
statusCode: number,
message: string,
isGroupCreator: boolean,
isInviteV4Sent: boolean
};
};
}
export interface GroupNotification {
/** ContactId for the user that produced the GroupNotification */
author: string,
/** Extra content */
body: string,
/** ID for the Chat that this groupNotification was sent for */
chatId: string,
/** ID that represents the groupNotification
* @todo create a more specific type for the id object */
id: object,
/** Contact IDs for the users that were affected by this GroupNotification */
recipientIds: string[],
/** Unix timestamp for when the groupNotification was created */
timestamp: number,
/** GroupNotification type */
type: GroupNotificationTypes,
/** Returns the Chat this GroupNotification was sent in */
getChat: () => Promise<Chat>,
/** Returns the Contact this GroupNotification was produced by */
getContact: () => Promise<Contact>,
/** Returns the Contacts affected by this GroupNotification */
getRecipients: () => Promise<Contact[]>,
/** Sends a message to the same chat this GroupNotification was produced in */
reply: (content: MessageContent, options?: MessageSendOptions) => Promise<Message>,
}
/** whatsapp web url */
export const WhatsWebURL: string
/** default client options */
export const DefaultOptions: ClientOptions
/** Chat types */
export enum ChatTypes {
SOLO = 'solo',
GROUP = 'group',
UNKNOWN = 'unknown',
}
/** Events that can be emitted by the client */
export enum Events {
AUTHENTICATED = 'authenticated',
AUTHENTICATION_FAILURE = 'auth_failure',
READY = 'ready',
MESSAGE_RECEIVED = 'message',
MESSAGE_CIPHERTEXT = 'message_ciphertext',
MESSAGE_CREATE = 'message_create',
MESSAGE_REVOKED_EVERYONE = 'message_revoke_everyone',
MESSAGE_REVOKED_ME = 'message_revoke_me',
MESSAGE_ACK = 'message_ack',
MESSAGE_EDIT = 'message_edit',
MEDIA_UPLOADED = 'media_uploaded',
CONTACT_CHANGED = 'contact_changed',
GROUP_JOIN = 'group_join',
GROUP_LEAVE = 'group_leave',
GROUP_ADMIN_CHANGED = 'group_admin_changed',
GROUP_MEMBERSHIP_REQUEST = 'group_membership_request',
GROUP_UPDATE = 'group_update',
QR_RECEIVED = 'qr',
LOADING_SCREEN = 'loading_screen',
DISCONNECTED = 'disconnected',
STATE_CHANGED = 'change_state',
BATTERY_CHANGED = 'change_battery',
REMOTE_SESSION_SAVED = 'remote_session_saved',
CALL = 'call'
}
/** Group notification types */
export enum GroupNotificationTypes {
ADD = 'add',
INVITE = 'invite',
REMOVE = 'remove',
LEAVE = 'leave',
SUBJECT = 'subject',
DESCRIPTION = 'description',
PICTURE = 'picture',
ANNOUNCE = 'announce',
RESTRICT = 'restrict',
}
/** Message ACK */
export enum MessageAck {
ACK_ERROR = -1,
ACK_PENDING = 0,
ACK_SERVER = 1,
ACK_DEVICE = 2,
ACK_READ = 3,
ACK_PLAYED = 4,
}
/** Message types */
export enum MessageTypes {
TEXT = 'chat',
AUDIO = 'audio',
VOICE = 'ptt',
IMAGE = 'image',
VIDEO = 'video',
DOCUMENT = 'document',
STICKER = 'sticker',
LOCATION = 'location',
CONTACT_CARD = 'vcard',
CONTACT_CARD_MULTI = 'multi_vcard',
REVOKED = 'revoked',
ORDER = 'order',
PRODUCT = 'product',
PAYMENT = 'payment',
UNKNOWN = 'unknown',
GROUP_INVITE = 'groups_v4_invite',
LIST = 'list',
LIST_RESPONSE = 'list_response',
BUTTONS_RESPONSE = 'buttons_response',
BROADCAST_NOTIFICATION = 'broadcast_notification',
CALL_LOG = 'call_log',
CIPHERTEXT = 'ciphertext',
DEBUG = 'debug',
E2E_NOTIFICATION = 'e2e_notification',
GP2 = 'gp2',
GROUP_NOTIFICATION = 'group_notification',
HSM = 'hsm',
INTERACTIVE = 'interactive',
NATIVE_FLOW = 'native_flow',
NOTIFICATION = 'notification',
NOTIFICATION_TEMPLATE = 'notification_template',
OVERSIZED = 'oversized',
PROTOCOL = 'protocol',
REACTION = 'reaction',
TEMPLATE_BUTTON_REPLY = 'template_button_reply',
POLL_CREATION = 'poll_creation',
}
/** Client status */
export enum Status {
INITIALIZING = 0,
AUTHENTICATING = 1,
READY = 3,
}
/** WhatsApp state */
export enum WAState {
CONFLICT = 'CONFLICT',
CONNECTED = 'CONNECTED',
DEPRECATED_VERSION = 'DEPRECATED_VERSION',
OPENING = 'OPENING',
PAIRING = 'PAIRING',
PROXYBLOCK = 'PROXYBLOCK',
SMB_TOS_BLOCK = 'SMB_TOS_BLOCK',
TIMEOUT = 'TIMEOUT',
TOS_BLOCK = 'TOS_BLOCK',
UNLAUNCHED = 'UNLAUNCHED',
UNPAIRED = 'UNPAIRED',
UNPAIRED_IDLE = 'UNPAIRED_IDLE',
}
export type MessageInfo = {
delivery: Array<{id: ContactId, t: number}>,
deliveryRemaining: number,
played: Array<{id: ContactId, t: number}>,
playedRemaining: number,
read: Array<{id: ContactId, t: number}>,
readRemaining: number
}
export type InviteV4Data = {
inviteCode: string,
inviteCodeExp: number,
groupId: string,
groupName?: string,
fromId: string,
toId: string
}
/**
* Represents a Message on WhatsApp
*
* @example
* {
* mediaKey: undefined,
* id: {
* fromMe: false,
* remote: `[email protected]`,
* id: '1234567890ABCDEFGHIJ',
* _serialized: `[email protected]_1234567890ABCDEFGHIJ`
* },
* ack: -1,
* hasMedia: false,
* body: 'Hello!',
* type: 'chat',
* timestamp: 1591482682,
* from: `[email protected]`,
* to: `[email protected]`,
* author: undefined,
* isForwarded: false,
* broadcast: false,
* fromMe: false,
* hasQuotedMsg: false,
* hasReaction: false,
* location: undefined,
* mentionedIds: []
* }
*/
export interface Message {
/** ACK status for the message */
ack: MessageAck,
/** If the message was sent to a group, this field will contain the user that sent the message. */
author?: string,
/** String that represents from which device type the message was sent */
deviceType: string,
/** Message content */
body: string,
/** Indicates if the message was a broadcast */
broadcast: boolean,
/** Indicates if the message was a status update */
isStatus: boolean,
/** Indicates if the message is a Gif */
isGif: boolean,
/** Indicates if the message will disappear after it expires */
isEphemeral: boolean,
/** ID for the Chat that this message was sent to, except if the message was sent by the current user */
from: string,
/** Indicates if the message was sent by the current user */
fromMe: boolean,
/** Indicates if the message has media available for download */
hasMedia: boolean,
/** Indicates if the message was sent as a reply to another message */
hasQuotedMsg: boolean,
/** Indicates whether there are reactions to the message */
hasReaction: boolean,
/** Indicates the duration of the message in seconds */
duration: string,
/** ID that represents the message */
id: MessageId,
/** Indicates if the message was forwarded */
isForwarded: boolean,
/**
* Indicates how many times the message was forwarded.
* The maximum value is 127.
*/
forwardingScore: number,
/** Indicates if the message was starred */
isStarred: boolean,
/** Location information contained in the message, if the message is type "location" */
location: Location,
/** List of vCards contained in the message */
vCards: string[],
/** Invite v4 info */
inviteV4?: InviteV4Data,
/** MediaKey that represents the sticker 'ID' */
mediaKey?: string,
/** Indicates the mentions in the message body. */
mentionedIds: ChatId[],
/** Indicates whether there are group mentions in the message body */
groupMentions: {
groupSubject: string;
groupJid: {
server: string;
user: string;
_serialized: string;
};
}[],
/** Unix timestamp for when the message was created */
timestamp: number,
/**
* ID for who this message is for.
* If the message is sent by the current user, it will be the Chat to which the message is being sent.
* If the message is sent by another user, it will be the ID for the current user.
*/
to: string,
/** Message type */
type: MessageTypes,
/** Links included in the message. */
links: Array<{
link: string,
isSuspicious: boolean
}>,
/** Order ID */
orderId: string,
/** title */
title?: string,
/** description*/
description?: string,
/** Business Owner JID */
businessOwnerJid?: string,
/** Product JID */
productId?: string,
/** Last edit time */
latestEditSenderTimestampMs?: number,
/** Last edit message author */
latestEditMsgKey?: MessageId,
/** Message buttons */
dynamicReplyButtons?: object,
/** Selected button ID */
selectedButtonId?: string,
/** Selected list row ID */
selectedRowId?: string,
/** Returns message in a raw format */
rawData: object,
pollName: string,
/** Avaiaible poll voting options */
pollOptions: string[],
/** False for a single choice poll, true for a multiple choice poll */
allowMultipleAnswers: boolean,
/*
* Reloads this Message object's data in-place with the latest values from WhatsApp Web.
* Note that the Message must still be in the web app cache for this to work, otherwise will return null.
*/
reload: () => Promise<Message>,
/** Accept the Group V4 Invite in message */
acceptGroupV4Invite: () => Promise<{status: number}>,
/** Deletes the message from the chat */
delete: (everyone?: boolean) => Promise<void>,
/** Downloads and returns the attached message media */
downloadMedia: () => Promise<MessageMedia>,
/** Returns the Chat this message was sent in */
getChat: () => Promise<Chat>,
/** Returns the Contact this message was sent from */
getContact: () => Promise<Contact>,
/** Returns the Contacts mentioned in this message */
getMentions: () => Promise<Contact[]>,
/** Returns groups mentioned in this message */
getGroupMentions: () => Promise<GroupChat[]|[]>,
/** Returns the quoted message, if any */
getQuotedMessage: () => Promise<Message>,
/**
* Sends a message as a reply to this message.
* If chatId is specified, it will be sent through the specified Chat.
* If not, it will send the message in the same Chat as the original message was sent.
*/
reply: (content: MessageContent, chatId?: string, options?: MessageSendOptions) => Promise<Message>,
/** React to this message with an emoji*/
react: (reaction: string) => Promise<void>,
/**
* Forwards this message to another chat (that you chatted before, otherwise it will fail)
*/
forward: (chat: Chat | string) => Promise<void>,
/** Star this message */
star: () => Promise<void>,
/** Unstar this message */
unstar: () => Promise<void>,
/** Pins the message (group admins can pin messages of all group members) */
pin: (duration: number) => Promise<boolean>,
/** Unpins the message (group admins can unpin messages of all group members) */
unpin: () => Promise<boolean>,
/** Get information about message delivery status */
getInfo: () => Promise<MessageInfo | null>,
/**
* Gets the order associated with a given message
*/
getOrder: () => Promise<Order>,
/**
* Gets the payment details associated with a given message
*/
getPayment: () => Promise<Payment>,
/**
* Gets the reactions associated with the given message
*/
getReactions: () => Promise<ReactionList[]>,