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