whatsapp-web.js 1.29.0 → 1.30.1-alpha.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
@@ -470,6 +470,36 @@ client.on('message', async msg => {
470
470
  console.log(statuses);
471
471
  const chat = await statuses[0]?.getChat(); // Get user chat of a first status
472
472
  console.log(chat);
473
+ } else if (msg.body === '!sendMediaHD' && msg.hasQuotedMsg) {
474
+ const quotedMsg = await msg.getQuotedMessage();
475
+ if (quotedMsg.hasMedia) {
476
+ const media = await quotedMsg.downloadMedia();
477
+ await client.sendMessage(msg.from, media, { sendMediaAsHd: true });
478
+ }
479
+ } else if (msg.body === '!parseVCard') {
480
+ const vCard =
481
+ 'BEGIN:VCARD\n' +
482
+ 'VERSION:3.0\n' +
483
+ 'FN:John Doe\n' +
484
+ 'ORG:Microsoft;\n' +
485
+ 'EMAIL;type=INTERNET:john.doe@gmail.com\n' +
486
+ 'URL:www.johndoe.com\n' +
487
+ 'TEL;type=CELL;type=VOICE;waid=18006427676:+1 (800) 642 7676\n' +
488
+ 'END:VCARD';
489
+ const vCardExtended =
490
+ 'BEGIN:VCARD\n' +
491
+ 'VERSION:3.0\n' +
492
+ 'FN:John Doe\n' +
493
+ 'ORG:Microsoft;\n' +
494
+ 'item1.TEL:+1 (800) 642 7676\n' +
495
+ 'item1.X-ABLabel:USA Customer Service\n' +
496
+ 'item2.TEL:+55 11 4706 0900\n' +
497
+ 'item2.X-ABLabel:Brazil Customer Service\n' +
498
+ 'PHOTO;BASE64:here you can paste a binary data of a contact photo in Base64 encoding\n' +
499
+ 'END:VCARD';
500
+ const userId = 'XXXXXXXXXX@c.us';
501
+ await client.sendMessage(userId, vCard);
502
+ await client.sendMessage(userId, vCardExtended);
473
503
  } else if (msg.body === '!changeSync') {
474
504
  // NOTE: this action will take effect after you restart the client.
475
505
  const backgroundSync = await client.setBackgroundSync(true);
package/index.d.ts CHANGED
@@ -991,15 +991,11 @@ declare namespace WAWebJS {
991
991
  /** MediaKey that represents the sticker 'ID' */
992
992
  mediaKey?: string,
993
993
  /** Indicates the mentions in the message body. */
994
- mentionedIds: ChatId[],
994
+ mentionedIds: string[],
995
995
  /** Indicates whether there are group mentions in the message body */
996
996
  groupMentions: {
997
997
  groupSubject: string;
998
- groupJid: {
999
- server: string;
1000
- user: string;
1001
- _serialized: string;
1002
- };
998
+ groupJid: string;
1003
999
  }[],
1004
1000
  /** Unix timestamp for when the message was created */
1005
1001
  timestamp: number,
@@ -1229,6 +1225,8 @@ declare namespace WAWebJS {
1229
1225
  sendMediaAsSticker?: boolean
1230
1226
  /** Send media as document */
1231
1227
  sendMediaAsDocument?: boolean
1228
+ /** Send media as quality HD */
1229
+ sendMediaAsHd?: boolean
1232
1230
  /** Send photo/video as a view once message */
1233
1231
  isViewOnce?: boolean
1234
1232
  /** Automatically parse vCards and send them as contacts */
@@ -1261,7 +1259,7 @@ declare namespace WAWebJS {
1261
1259
  /** Sticker categories, if sendMediaAsSticker is true */
1262
1260
  stickerCategories?: string[],
1263
1261
  /** Should the bot send a quoted message without the quoted message if it fails to get the quote?
1264
- * @default false (disabled) */
1262
+ * @default true (enabled) */
1265
1263
  ignoreQuoteErrors?: boolean
1266
1264
  }
1267
1265
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whatsapp-web.js",
3
- "version": "1.29.0",
3
+ "version": "1.30.1-alpha.0",
4
4
  "description": "Library for interacting with the WhatsApp Web API ",
5
5
  "main": "./index.js",
6
6
  "typings": "./index.d.ts",
package/src/Client.js CHANGED
@@ -840,6 +840,7 @@ class Client extends EventEmitter {
840
840
  * @property {boolean} [sendVideoAsGif=false] - Send video as gif
841
841
  * @property {boolean} [sendMediaAsSticker=false] - Send media as a sticker
842
842
  * @property {boolean} [sendMediaAsDocument=false] - Send media as a document
843
+ * @property {boolean} [sendMediaAsHd=false] - Send image as quality HD
843
844
  * @property {boolean} [isViewOnce=false] - Send photo/video as a view once message
844
845
  * @property {boolean} [parseVCards=true] - Automatically parse vCards and send them as contacts
845
846
  * @property {string} [caption] - Image or video caption
@@ -851,6 +852,7 @@ class Client extends EventEmitter {
851
852
  * @property {string} [stickerAuthor=undefined] - Sets the author of the sticker, (if sendMediaAsSticker is true).
852
853
  * @property {string} [stickerName=undefined] - Sets the name of the sticker, (if sendMediaAsSticker is true).
853
854
  * @property {string[]} [stickerCategories=undefined] - Sets the categories of the sticker, (if sendMediaAsSticker is true). Provide emoji char array, can be null.
855
+ * @property {boolean} [ignoreQuoteErrors = true] - Should the bot send a quoted message without the quoted message if it fails to get the quote?
854
856
  * @property {MessageMedia} [media] - Media to be sent
855
857
  * @property {any} [extra] - Extra options
856
858
  */
@@ -893,12 +895,14 @@ class Client extends EventEmitter {
893
895
  sendVideoAsGif: options.sendVideoAsGif,
894
896
  sendMediaAsSticker: options.sendMediaAsSticker,
895
897
  sendMediaAsDocument: options.sendMediaAsDocument,
898
+ sendMediaAsHd: options.sendMediaAsHd,
896
899
  caption: options.caption,
897
900
  quotedMessageId: options.quotedMessageId,
898
901
  parseVCards: options.parseVCards !== false,
899
902
  mentionedJidList: options.mentions || [],
900
903
  groupMentions: options.groupMentions,
901
904
  invokedBotWid: options.invokedBotWid,
905
+ ignoreQuoteErrors: options.ignoreQuoteErrors !== false,
902
906
  extraOptions: options.extra
903
907
  };
904
908
 
@@ -2143,7 +2147,7 @@ class Client extends EventEmitter {
2143
2147
  return false;
2144
2148
  }, chatId);
2145
2149
  }
2146
-
2150
+
2147
2151
  /**
2148
2152
  * Save new contact to user's addressbook or edit the existing one
2149
2153
  * @param {string} phoneNumber The contact's phone number in a format "17182222222", where "1" is a country code
@@ -186,26 +186,16 @@ class Message extends Base {
186
186
  toId: typeof data.to === 'object' && '_serialized' in data.to ? data.to._serialized : data.to
187
187
  } : undefined;
188
188
 
189
- /**
190
- * @typedef {Object} Mention
191
- * @property {string} server
192
- * @property {string} user
193
- * @property {string} _serialized
194
- */
195
-
196
189
  /**
197
190
  * Indicates the mentions in the message body.
198
- * @type {Mention[]}
191
+ * @type {string[]}
199
192
  */
200
193
  this.mentionedIds = data.mentionedJidList || [];
201
194
 
202
195
  /**
203
196
  * @typedef {Object} GroupMention
204
197
  * @property {string} groupSubject The name of the group
205
- * @property {Object} groupJid The group ID
206
- * @property {string} groupJid.server
207
- * @property {string} groupJid.user
208
- * @property {string} groupJid._serialized
198
+ * @property {string} groupJid The group ID
209
199
  */
210
200
 
211
201
  /**
@@ -67,7 +67,6 @@ exports.ExposeStore = () => {
67
67
  window.Store.ContactMethods = window.require('WAWebContactGetters');
68
68
  window.Store.UserConstructor = window.require('WAWebWid');
69
69
  window.Store.Validators = window.require('WALinkify');
70
- window.Store.VCard = window.require('WAWebFrontendVcardUtils');
71
70
  window.Store.WidFactory = window.require('WAWebWidFactory');
72
71
  window.Store.ProfilePic = window.require('WAWebContactProfilePicThumbBridge');
73
72
  window.Store.PresenceUtils = window.require('WAWebPresenceChatAction');
@@ -112,6 +111,11 @@ exports.ExposeStore = () => {
112
111
  window.Store.ForwardUtils = {
113
112
  ...window.require('WAWebForwardMessagesToChat')
114
113
  };
114
+ window.Store.VCard = {
115
+ ...window.require('WAWebFrontendVcardUtils'),
116
+ ...window.require('WAWebVcardParsingUtils'),
117
+ ...window.require('WAWebVcardGetNameFromParsed')
118
+ };
115
119
  window.Store.StickerTools = {
116
120
  ...window.require('WAWebImageUtils'),
117
121
  ...window.require('WAWebAddWebpMetadata')
@@ -34,6 +34,7 @@ exports.LoadUtils = () => {
34
34
  forceGif: options.sendVideoAsGif,
35
35
  forceVoice: options.sendAudioAsVoice,
36
36
  forceDocument: options.sendMediaAsDocument,
37
+ forceMediaHd: options.sendMediaAsHd,
37
38
  sendToChannel: isChannel
38
39
  });
39
40
  mediaOptions.caption = options.caption;
@@ -48,7 +49,7 @@ exports.LoadUtils = () => {
48
49
  let quotedMessage = window.Store.Msg.get(options.quotedMessageId);
49
50
  !quotedMessage && (quotedMessage = (await window.Store.Msg.getMessagesById([options.quotedMessageId]))?.messages?.[0]);
50
51
 
51
- if (quotedMessage['messages'].length == 1) {
52
+ if (quotedMessage['messages']?.length == 1) {
52
53
  quotedMessage = quotedMessage['messages'][0];
53
54
 
54
55
  const canReply = window.Store.ReplyUtils
@@ -135,11 +136,12 @@ exports.LoadUtils = () => {
135
136
  vcardOptions = {
136
137
  type: 'multi_vcard',
137
138
  vcardList: vcards,
138
- body: undefined
139
+ body: null
139
140
  };
140
141
  delete options.contactCardList;
141
142
  } else if (options.parseVCards && typeof (content) === 'string' && content.startsWith('BEGIN:VCARD')) {
142
143
  delete options.parseVCards;
144
+ delete options.linkPreview;
143
145
  try {
144
146
  const parsed = window.Store.VCard.parseVcard(content);
145
147
  if (parsed) {
@@ -362,16 +364,21 @@ exports.LoadUtils = () => {
362
364
  };
363
365
  };
364
366
 
365
- window.WWebJS.processMediaData = async (mediaInfo, { forceSticker, forceGif, forceVoice, forceDocument, sendToChannel }) => {
367
+ window.WWebJS.processMediaData = async (mediaInfo, { forceSticker, forceGif, forceVoice, forceDocument, forceMediaHd, sendToChannel }) => {
366
368
  const file = window.WWebJS.mediaInfoToFile(mediaInfo);
367
369
  const opaqueData = await window.Store.OpaqueData.createFromData(file, file.type);
368
- const mediaPrep = window.Store.MediaPrep.prepRawMedia(
369
- opaqueData, {
370
- asSticker: forceSticker,
371
- asGif: forceGif,
372
- isPtt: forceVoice,
373
- asDocument: forceDocument
374
- });
370
+ const mediaParams = {
371
+ asSticker: forceSticker,
372
+ asGif: forceGif,
373
+ isPtt: forceVoice,
374
+ asDocument: forceDocument
375
+ };
376
+
377
+ if (forceMediaHd && file.type.indexOf('image/') === 0) {
378
+ mediaParams.maxDimension = 2560;
379
+ }
380
+
381
+ const mediaPrep = window.Store.MediaPrep.prepRawMedia(opaqueData, mediaParams);
375
382
  const mediaData = await mediaPrep.waitForPrep();
376
383
  const mediaObject = window.Store.MediaObject.getOrCreateMediaObject(mediaData.filehash);
377
384
  const mediaType = window.Store.MediaTypes.msgToMediaType({
@@ -550,7 +557,7 @@ exports.LoadUtils = () => {
550
557
  model.isGroup = true;
551
558
  const chatWid = window.Store.WidFactory.createWid(chat.id._serialized);
552
559
  await window.Store.GroupMetadata.update(chatWid);
553
- model.groupMetadata.participants._models
560
+ chat.groupMetadata.participants._models
554
561
  .filter(x => x.id._serialized.endsWith('@lid'))
555
562
  .forEach(x => { x.id = x.contact.phoneNumber; });
556
563
  model.groupMetadata = chat.groupMetadata.serialize();