whatsapp-web.js 1.31.1-alpha.0 → 1.33.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/example.js CHANGED
@@ -3,10 +3,26 @@ const { Client, Location, Poll, List, Buttons, LocalAuth } = require('./index');
3
3
  const client = new Client({
4
4
  authStrategy: new LocalAuth(),
5
5
  // proxyAuthentication: { username: 'username', password: 'password' },
6
+ /**
7
+ * This option changes the browser name from defined in user agent to custom.
8
+ */
9
+ // deviceName: 'Your custom name',
10
+ /**
11
+ * This option changes browser type from defined in user agent to yours. It affects the browser icon
12
+ * that is displayed in 'linked devices' section.
13
+ * Valid value are: 'Chrome' | 'Firefox' | 'IE' | 'Opera' | 'Safari' | 'Edge'.
14
+ * If another value is provided, the browser icon in 'linked devices' section will be gray.
15
+ */
16
+ // browserName: 'Firefox',
6
17
  puppeteer: {
7
18
  // args: ['--proxy-server=proxy-server-that-requires-authentication.example.com'],
8
19
  headless: false,
9
- }
20
+ },
21
+ // pairWithPhoneNumber: {
22
+ // phoneNumber: '96170100100' // Pair with phone number (format: <COUNTRY_CODE><PHONE_NUMBER>)
23
+ // showNotification: true,
24
+ // intervalMs: 180000 // Time to renew pairing code in milliseconds, defaults to 3 minutes
25
+ // }
10
26
  });
11
27
 
12
28
  // client initialize does not finish at ready now.
@@ -16,19 +32,13 @@ client.on('loading_screen', (percent, message) => {
16
32
  console.log('LOADING SCREEN', percent, message);
17
33
  });
18
34
 
19
- // Pairing code only needs to be requested once
20
- let pairingCodeRequested = false;
21
35
  client.on('qr', async (qr) => {
22
36
  // NOTE: This event will not be fired if a session is specified.
23
37
  console.log('QR RECEIVED', qr);
38
+ });
24
39
 
25
- // paiuting code example
26
- const pairingCodeEnabled = false;
27
- if (pairingCodeEnabled && !pairingCodeRequested) {
28
- const pairingCode = await client.requestPairingCode('96170100100'); // enter the target phone number
29
- console.log('Pairing code enabled, code: '+ pairingCode);
30
- pairingCodeRequested = true;
31
- }
40
+ client.on('code', (code) => {
41
+ console.log('Pairing code:',code);
32
42
  });
33
43
 
34
44
  client.on('authenticated', () => {
package/index.d.ts CHANGED
@@ -99,6 +99,9 @@ declare namespace WAWebJS {
99
99
  /** Get message by ID */
100
100
  getMessageById(messageId: string): Promise<Message>
101
101
 
102
+ /** Gets instances of all pinned messages in a chat */
103
+ getPinnedMessages(chatId: string): Promise<[Message]|[]>
104
+
102
105
  /** Get all current contact instances */
103
106
  getContacts(): Promise<Contact[]>
104
107
 
@@ -157,10 +160,11 @@ declare namespace WAWebJS {
157
160
  /**
158
161
  * Request authentication via pairing code instead of QR code
159
162
  * @param phoneNumber - Phone number in international, symbol-free format (e.g. 12025550108 for US, 551155501234 for Brazil)
160
- * @param showNotification - Show notification to pair on phone number
163
+ * @param showNotification - Show notification to pair on phone number. Defaults to `true`
164
+ * @param intervalMs - The interval in milliseconds on how frequent to generate pairing code (WhatsApp default to 3 minutes). Defaults to `180000`
161
165
  * @returns {Promise<string>} - Returns a pairing code in format "ABCDEFGH"
162
166
  */
163
- requestPairingCode(phoneNumber: string, showNotification?: boolean): Promise<string>
167
+ requestPairingCode(phoneNumber: string, showNotification?: boolean, intervalMs?: number): Promise<string>
164
168
 
165
169
  /** Force reset of connection state for the client */
166
170
  resetState(): Promise<void>
@@ -242,6 +246,9 @@ declare namespace WAWebJS {
242
246
 
243
247
  /** Deletes the contact from user's addressbook */
244
248
  deleteAddressbookContact(honeNumber: string): Promise<void>
249
+
250
+ /** Get Contact lid and phone */
251
+ getContactLidAndPhone(userIds: string[]): Promise<{ lid: string; pn: string }[]>
245
252
 
246
253
  /** Changes and returns the archive state of the Chat */
247
254
  unarchiveChat(chatId: string): Promise<boolean>
@@ -255,6 +262,16 @@ declare namespace WAWebJS {
255
262
  /** Deletes the current user's profile picture */
256
263
  deleteProfilePicture(): Promise<boolean>
257
264
 
265
+ /** Generates a WhatsApp call link (video call or voice call) */
266
+ createCallLink(startTime: Date, callType: string): Promise<string>
267
+
268
+ /**
269
+ * Sends a response to the scheduled event message, indicating whether a user is going to attend the event or not
270
+ * @param response The response code to the event message. Valid values are: `0` for NONE response (removes a previous response) | `1` for GOING | `2` for NOT GOING | `3` for MAYBE going
271
+ * @param eventMessageId The event message ID
272
+ */
273
+ sendResponseToScheduledEvent(response: number, eventMessageId: string): Promise<boolean>
274
+
258
275
  /** Gets an array of membership requests */
259
276
  getGroupMembershipRequests(groupId: string): Promise<Array<GroupMembershipRequest>>
260
277
 
@@ -367,7 +384,7 @@ declare namespace WAWebJS {
367
384
  ack: MessageAck
368
385
  ) => void): this
369
386
 
370
- /** Emitted when an ack event occurrs on message type */
387
+ /** Emitted when an edit event occurrs on message type */
371
388
  on(event: 'message_edit', listener: (
372
389
  /** The message that was affected */
373
390
  message: Message,
@@ -444,6 +461,13 @@ declare namespace WAWebJS {
444
461
  qr: string
445
462
  ) => void): this
446
463
 
464
+ /** Emitted when the phone number pairing code is received */
465
+ on(event: 'code', listener: (
466
+ /** pairing code string
467
+ * @example `8W2WZ3TS` */
468
+ code: string
469
+ ) => void): this
470
+
447
471
  /** Emitted when a call is received */
448
472
  on(event: 'call', listener: (
449
473
  /** The call that started */
@@ -541,8 +565,27 @@ declare namespace WAWebJS {
541
565
  /** Ffmpeg path to use when formatting videos to webp while sending stickers
542
566
  * @default 'ffmpeg' */
543
567
  ffmpegPath?: string,
568
+ /** Sets bypassing of page's Content-Security-Policy
569
+ * @default false */
570
+ bypassCSP?: boolean,
571
+ /** Sets the device name of a current linked device., i.e.: 'TEST' */
572
+ deviceName?: string,
573
+ /**
574
+ * Sets the browser name of a current linked device, i.e.: 'Firefox'.
575
+ * Valid value are: 'Chrome' | 'Firefox' | 'IE' | 'Opera' | 'Safari' | 'Edge'
576
+ */
577
+ browserName?: string,
544
578
  /** Object with proxy autentication requirements @default: undefined */
545
579
  proxyAuthentication?: {username: string, password: string} | undefined
580
+ /** Phone number pairing configuration. Refer the requestPairingCode function of Client.
581
+ * @default
582
+ * {
583
+ * phoneNumber: "",
584
+ * showNotification: true,
585
+ * intervalMs: 180000,
586
+ * }
587
+ */
588
+ pairWithPhoneNumber?: {phoneNumber: string, showNotification?: boolean, intervalMs?: number}
546
589
  }
547
590
 
548
591
  export interface LocalWebCacheOptions {
@@ -681,6 +724,22 @@ declare namespace WAWebJS {
681
724
  * @default ''
682
725
  */
683
726
  comment?: string
727
+ /** If true, only admins can add members to the group (false by default)
728
+ * @default false
729
+ */
730
+ memberAddMode?: boolean,
731
+ /** If true, group admins will be required to approve anyone who wishes to join the group (false by default)
732
+ * @default false
733
+ */
734
+ membershipApprovalMode?: boolean,
735
+ /** If true, only admins can change group group info (true by default)
736
+ * @default true
737
+ */
738
+ isRestrict?: boolean,
739
+ /** If true, only admins can send messages (false by default)
740
+ * @default false
741
+ */
742
+ isAnnounce?: boolean,
684
743
  }
685
744
 
686
745
  /** An object that handles the result for createGroup method */
@@ -870,6 +929,7 @@ declare namespace WAWebJS {
870
929
  REACTION = 'reaction',
871
930
  TEMPLATE_BUTTON_REPLY = 'template_button_reply',
872
931
  POLL_CREATION = 'poll_creation',
932
+ SCHEDULED_EVENT_CREATION = 'scheduled_event_creation',
873
933
  }
874
934
 
875
935
  /** Client status */
@@ -1026,6 +1086,11 @@ declare namespace WAWebJS {
1026
1086
  latestEditSenderTimestampMs?: number,
1027
1087
  /** Last edit message author */
1028
1088
  latestEditMsgKey?: MessageId,
1089
+ /**
1090
+ * Protocol message key.
1091
+ * Can be used to retrieve the ID of an original message that was revoked.
1092
+ */
1093
+ protocolMessageKey?: MessageId,
1029
1094
  /** Message buttons */
1030
1095
  dynamicReplyButtons?: object,
1031
1096
  /** Selected button ID */
@@ -1039,6 +1104,24 @@ declare namespace WAWebJS {
1039
1104
  pollOptions: string[],
1040
1105
  /** False for a single choice poll, true for a multiple choice poll */
1041
1106
  allowMultipleAnswers: boolean,
1107
+ /** The start time of the event in timestamp (10 digits) */
1108
+ eventStartTime: number,
1109
+ /** The end time of the event in timestamp (10 digits) */
1110
+ eventEndTime?: number,
1111
+ /** The event description */
1112
+ eventDescription?: string,
1113
+ /** The location of the event */
1114
+ eventLocation?: {
1115
+ degreesLatitude: number;
1116
+ degreesLongitude: number;
1117
+ name: string;
1118
+ },
1119
+ /** WhatsApp call link (video call or voice call) */
1120
+ eventJoinLink?: string,
1121
+ /** Indicates if an event should be sent as an already canceled */
1122
+ isEventCaneled: boolean,
1123
+ /** The custom message secret, can be used as an event ID */
1124
+ messageSecret?: Array<number>,
1042
1125
  /*
1043
1126
  * Reloads this Message object's data in-place with the latest values from WhatsApp Web.
1044
1127
  * Note that the Message must still be in the web app cache for this to work, otherwise will return null.
@@ -1096,6 +1179,11 @@ declare namespace WAWebJS {
1096
1179
  getReactions: () => Promise<ReactionList[]>,
1097
1180
  /** Edits the current message */
1098
1181
  edit: (content: MessageContent, options?: MessageEditOptions) => Promise<Message | null>,
1182
+ /**
1183
+ * Edits the current ScheduledEvent message.
1184
+ * Once the event is canceled, it can not be edited.
1185
+ */
1186
+ editScheduledEvent: (editedEventObject: Event) => Promise<Message | null>,
1099
1187
  }
1100
1188
 
1101
1189
  /** ID that represents a message */
@@ -1151,6 +1239,44 @@ declare namespace WAWebJS {
1151
1239
  constructor(pollName: string, pollOptions: Array<string>, options?: PollSendOptions)
1152
1240
  }
1153
1241
 
1242
+ /** ScheduledEvent send options */
1243
+ export interface ScheduledEventSendOptions {
1244
+ /** The scheduled event description */
1245
+ description?: string,
1246
+ /** The end time of the event */
1247
+ endTime?: Date,
1248
+ /** The location of the event */
1249
+ location?: string,
1250
+ /** The type of a WhatsApp call link to generate, valid values are: `video` | `voice` */
1251
+ callType?: string,
1252
+ /**
1253
+ * Indicates if a scheduled event should be sent as an already canceled
1254
+ * @default false
1255
+ */
1256
+ isEventCanceled?: boolean
1257
+ /**
1258
+ * The custom message secret, can be used as an event ID
1259
+ * @note It has to be a unique vector with a length of 32
1260
+ */
1261
+ messageSecret: Array<number>|undefined
1262
+ }
1263
+
1264
+ /** Represents a ScheduledEvent on WhatsApp */
1265
+ export class ScheduledEvent {
1266
+ name: string
1267
+ startTimeTs: number
1268
+ eventSendOptions: {
1269
+ description?: string;
1270
+ endTimeTs?: number;
1271
+ location?: string;
1272
+ callType?: string;
1273
+ isEventCanceled?: boolean;
1274
+ messageSecret?: string;
1275
+ };
1276
+
1277
+ constructor(name: string, startTime: Date, options?: EventSendOptions)
1278
+ }
1279
+
1154
1280
  /** Represents a Poll Vote on WhatsApp */
1155
1281
  export interface PollVote {
1156
1282
  /** The person who voted */
@@ -1261,14 +1387,19 @@ declare namespace WAWebJS {
1261
1387
  /** Should the bot send a quoted message without the quoted message if it fails to get the quote?
1262
1388
  * @default true (enabled) */
1263
1389
  ignoreQuoteErrors?: boolean
1390
+ /**
1391
+ * Should the bot wait for the message send result?
1392
+ * @default false
1393
+ */
1394
+ waitUntilMsgSent?: boolean
1264
1395
  }
1265
1396
 
1266
1397
  /** Options for editing a message */
1267
1398
  export interface MessageEditOptions {
1268
1399
  /** Show links preview. Has no effect on multi-device accounts. */
1269
1400
  linkPreview?: boolean
1270
- /** Contacts that are being mentioned in the message */
1271
- mentions?: Contact[]
1401
+ /** User IDs of users that being mentioned in the message */
1402
+ mentions?: string[]
1272
1403
  /** Extra options */
1273
1404
  extra?: any
1274
1405
  }
@@ -1306,7 +1437,7 @@ declare namespace WAWebJS {
1306
1437
  static fromUrl: (url: string, options?: MediaFromURLOptions) => Promise<MessageMedia>
1307
1438
  }
1308
1439
 
1309
- export type MessageContent = string | MessageMedia | Location | Poll | Contact | Contact[] | List | Buttons
1440
+ export type MessageContent = string | MessageMedia | Location | Poll | Contact | Contact[] | List | Buttons | ScheduledEvent
1310
1441
 
1311
1442
  /**
1312
1443
  * Represents a Contact on WhatsApp
@@ -1572,6 +1703,8 @@ declare namespace WAWebJS {
1572
1703
  getLabels: () => Promise<Label[]>,
1573
1704
  /** Add or remove labels to this Chat */
1574
1705
  changeLabels: (labelIds: Array<string | number>) => Promise<void>
1706
+ /** Gets instances of all pinned messages in a chat */
1707
+ getPinnedMessages: () => Promise<[Message]|[]>
1575
1708
  /** Sync history conversation of the Chat */
1576
1709
  syncHistory: () => Promise<boolean>
1577
1710
  }
package/index.js CHANGED
@@ -20,6 +20,7 @@ module.exports = {
20
20
  ClientInfo: require('./src/structures/ClientInfo'),
21
21
  Location: require('./src/structures/Location'),
22
22
  Poll: require('./src/structures/Poll'),
23
+ ScheduledEvent: require('./src/structures/ScheduledEvent'),
23
24
  ProductMetadata: require('./src/structures/ProductMetadata'),
24
25
  List: require('./src/structures/List'),
25
26
  Buttons: require('./src/structures/Buttons'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whatsapp-web.js",
3
- "version": "1.31.1-alpha.0",
3
+ "version": "1.33.0",
4
4
  "description": "Library for interacting with the WhatsApp Web API ",
5
5
  "main": "./index.js",
6
6
  "typings": "./index.d.ts",