whatsapp-web.js 1.30.0 → 1.30.1-alpha.1

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 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whatsapp-web.js",
3
- "version": "1.30.0",
3
+ "version": "1.30.1-alpha.1",
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
@@ -894,6 +895,7 @@ class Client extends EventEmitter {
894
895
  sendVideoAsGif: options.sendVideoAsGif,
895
896
  sendMediaAsSticker: options.sendMediaAsSticker,
896
897
  sendMediaAsDocument: options.sendMediaAsDocument,
898
+ sendMediaAsHd: options.sendMediaAsHd,
897
899
  caption: options.caption,
898
900
  quotedMessageId: options.quotedMessageId,
899
901
  parseVCards: options.parseVCards !== false,
@@ -2145,7 +2147,7 @@ class Client extends EventEmitter {
2145
2147
  return false;
2146
2148
  }, chatId);
2147
2149
  }
2148
-
2150
+
2149
2151
  /**
2150
2152
  * Save new contact to user's addressbook or edit the existing one
2151
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;
@@ -47,9 +48,7 @@ exports.LoadUtils = () => {
47
48
  if (options.quotedMessageId) {
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
- if (quotedMessage['messages']?.length == 1) {
52
- quotedMessage = quotedMessage['messages'][0];
51
+ if (quotedMessage) {
53
52
 
54
53
  const canReply = window.Store.ReplyUtils
55
54
  ? window.Store.ReplyUtils.canReplyMsg(quotedMessage.unsafe())
@@ -135,11 +134,12 @@ exports.LoadUtils = () => {
135
134
  vcardOptions = {
136
135
  type: 'multi_vcard',
137
136
  vcardList: vcards,
138
- body: undefined
137
+ body: null
139
138
  };
140
139
  delete options.contactCardList;
141
140
  } else if (options.parseVCards && typeof (content) === 'string' && content.startsWith('BEGIN:VCARD')) {
142
141
  delete options.parseVCards;
142
+ delete options.linkPreview;
143
143
  try {
144
144
  const parsed = window.Store.VCard.parseVcard(content);
145
145
  if (parsed) {
@@ -362,16 +362,21 @@ exports.LoadUtils = () => {
362
362
  };
363
363
  };
364
364
 
365
- window.WWebJS.processMediaData = async (mediaInfo, { forceSticker, forceGif, forceVoice, forceDocument, sendToChannel }) => {
365
+ window.WWebJS.processMediaData = async (mediaInfo, { forceSticker, forceGif, forceVoice, forceDocument, forceMediaHd, sendToChannel }) => {
366
366
  const file = window.WWebJS.mediaInfoToFile(mediaInfo);
367
367
  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
- });
368
+ const mediaParams = {
369
+ asSticker: forceSticker,
370
+ asGif: forceGif,
371
+ isPtt: forceVoice,
372
+ asDocument: forceDocument
373
+ };
374
+
375
+ if (forceMediaHd && file.type.indexOf('image/') === 0) {
376
+ mediaParams.maxDimension = 2560;
377
+ }
378
+
379
+ const mediaPrep = window.Store.MediaPrep.prepRawMedia(opaqueData, mediaParams);
375
380
  const mediaData = await mediaPrep.waitForPrep();
376
381
  const mediaObject = window.Store.MediaObject.getOrCreateMediaObject(mediaData.filehash);
377
382
  const mediaType = window.Store.MediaTypes.msgToMediaType({
@@ -551,8 +556,8 @@ exports.LoadUtils = () => {
551
556
  const chatWid = window.Store.WidFactory.createWid(chat.id._serialized);
552
557
  await window.Store.GroupMetadata.update(chatWid);
553
558
  chat.groupMetadata.participants._models
554
- .filter(x => x.id._serialized.endsWith('@lid'))
555
- .forEach(x => { x.id = x.contact.phoneNumber; });
559
+ .filter(x => x.id?._serialized?.endsWith('@lid'))
560
+ .forEach(x => x.contact?.phoneNumber && (x.id = x.contact.phoneNumber));
556
561
  model.groupMetadata = chat.groupMetadata.serialize();
557
562
  model.isReadOnly = chat.groupMetadata.announce;
558
563
  }