whatsapp-web.js 1.23.1-alpha.1 → 1.23.1-alpha.2

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
@@ -66,6 +66,9 @@ client.on('message', async msg => {
66
66
  } else if (msg.body.startsWith('!echo ')) {
67
67
  // Replies with the same message
68
68
  msg.reply(msg.body.slice(6));
69
+ } else if (msg.body.startsWith('!preview ')) {
70
+ const text = msg.body.slice(9);
71
+ msg.reply(text, null, { linkPreview: true });
69
72
  } else if (msg.body.startsWith('!desc ')) {
70
73
  // Change the group description
71
74
  let chat = await msg.getChat();
@@ -383,6 +386,14 @@ client.on('message_create', (msg) => {
383
386
  }
384
387
  });
385
388
 
389
+ client.on('message_ciphertext', (msg) => {
390
+ // Receiving new incoming messages that have been encrypted
391
+ // msg.type === 'ciphertext'
392
+ msg.body = 'Waiting for this message. Check your phone.';
393
+
394
+ // do stuff here
395
+ });
396
+
386
397
  client.on('message_revoke_everyone', async (after, before) => {
387
398
  // Fired whenever a message is deleted by anyone (including you)
388
399
  console.log(after); // message after it was deleted.
package/index.d.ts CHANGED
@@ -304,6 +304,12 @@ declare namespace WAWebJS {
304
304
  /** The message that was created */
305
305
  message: Message
306
306
  ) => void): this
307
+
308
+ /** Emitted when a new message ciphertext is received */
309
+ on(event: 'message_ciphertext', listener: (
310
+ /** The message that was ciphertext */
311
+ message: Message
312
+ ) => void): this
307
313
 
308
314
  /** Emitted when a message is deleted for everyone in the chat */
309
315
  on(event: 'message_revoke_everyone', listener: (
@@ -440,7 +446,7 @@ declare namespace WAWebJS {
440
446
  /** User agent to use in puppeteer.
441
447
  * @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' */
442
448
  userAgent?: string
443
- /** Ffmpeg path to use when formating videos to webp while sending stickers
449
+ /** Ffmpeg path to use when formatting videos to webp while sending stickers
444
450
  * @default 'ffmpeg' */
445
451
  ffmpegPath?: string,
446
452
  /** Object with proxy autentication requirements @default: undefined */
@@ -647,6 +653,7 @@ declare namespace WAWebJS {
647
653
  AUTHENTICATION_FAILURE = 'auth_failure',
648
654
  READY = 'ready',
649
655
  MESSAGE_RECEIVED = 'message',
656
+ MESSAGE_CIPHERTEXT = 'message_ciphertext',
650
657
  MESSAGE_CREATE = 'message_create',
651
658
  MESSAGE_REVOKED_EVERYONE = 'message_revoke_everyone',
652
659
  MESSAGE_REVOKED_ME = 'message_revoke_me',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whatsapp-web.js",
3
- "version": "1.23.1-alpha.1",
3
+ "version": "1.23.1-alpha.2",
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
@@ -30,7 +30,7 @@ const NoAuth = require('./authStrategies/NoAuth');
30
30
  * @param {number} options.takeoverOnConflict - If another whatsapp web session is detected (another browser), take over the session in the current browser
31
31
  * @param {number} options.takeoverTimeoutMs - How much time to wait before taking over the session
32
32
  * @param {string} options.userAgent - User agent to use in puppeteer
33
- * @param {string} options.ffmpegPath - Ffmpeg path to use when formating videos to webp while sending stickers
33
+ * @param {string} options.ffmpegPath - Ffmpeg path to use when formatting videos to webp while sending stickers
34
34
  * @param {boolean} options.bypassCSP - Sets bypassing of page's Content-Security-Policy.
35
35
  * @param {object} options.proxyAuthentication - Proxy Authentication object.
36
36
  *
@@ -43,6 +43,7 @@ const NoAuth = require('./authStrategies/NoAuth');
43
43
  * @fires Client#message_create
44
44
  * @fires Client#message_revoke_me
45
45
  * @fires Client#message_revoke_everyone
46
+ * @fires Client#message_ciphertext
46
47
  * @fires Client#message_edit
47
48
  * @fires Client#media_uploaded
48
49
  * @fires Client#group_join
@@ -659,6 +660,16 @@ class Client extends EventEmitter {
659
660
  */
660
661
  this.emit(Events.MESSAGE_EDIT, new Message(this, msg), newBody, prevBody);
661
662
  });
663
+
664
+ await page.exposeFunction('onAddMessageCiphertextEvent', msg => {
665
+
666
+ /**
667
+ * Emitted when messages are edited
668
+ * @event Client#message_ciphertext
669
+ * @param {Message} message
670
+ */
671
+ this.emit(Events.MESSAGE_CIPHERTEXT, new Message(this, msg));
672
+ });
662
673
 
663
674
  await page.evaluate(() => {
664
675
  window.Store.Msg.on('change', (msg) => { window.onChangeMessageEvent(window.WWebJS.getMessageModel(msg)); });
@@ -677,6 +688,7 @@ class Client extends EventEmitter {
677
688
  if(msg.type === 'ciphertext') {
678
689
  // defer message event until ciphertext is resolved (type changed)
679
690
  msg.once('change:type', (_msg) => window.onAddMessageEvent(window.WWebJS.getMessageModel(_msg)));
691
+ window.onAddMessageCiphertextEvent(window.WWebJS.getMessageModel(msg));
680
692
  } else {
681
693
  window.onAddMessageEvent(window.WWebJS.getMessageModel(msg));
682
694
  }
@@ -892,7 +904,7 @@ class Client extends EventEmitter {
892
904
 
893
905
 
894
906
  if (sendSeen) {
895
- window.WWebJS.sendSeen(chatId);
907
+ await window.WWebJS.sendSeen(chatId);
896
908
  }
897
909
 
898
910
  const msg = await window.WWebJS.sendMessage(chat, message, options, sendSeen);
@@ -44,6 +44,7 @@ exports.Events = {
44
44
  CHAT_REMOVED: 'chat_removed',
45
45
  CHAT_ARCHIVED: 'chat_archived',
46
46
  MESSAGE_RECEIVED: 'message',
47
+ MESSAGE_CIPHERTEXT: 'message_ciphertext',
47
48
  MESSAGE_CREATE: 'message_create',
48
49
  MESSAGE_REVOKED_EVERYONE: 'message_revoke_everyone',
49
50
  MESSAGE_REVOKED_ME: 'message_revoke_me',
@@ -50,6 +50,7 @@ exports.ExposeStore = (moduleRaidStr) => {
50
50
  window.Store.EphemeralFields = window.mR.findModule('getEphemeralFields')[0];
51
51
  window.Store.MsgActionChecks = window.mR.findModule('canSenderRevokeMsg')[0];
52
52
  window.Store.QuotedMsg = window.mR.findModule('getQuotedMsgObj')[0];
53
+ window.Store.LinkPreview = window.mR.findModule('getLinkPreview')[0];
53
54
  window.Store.Socket = window.mR.findModule('deprecatedSendIq')[0];
54
55
  window.Store.SocketWap = window.mR.findModule('wap')[0];
55
56
  window.Store.SearchContext = window.mR.findModule('getSearchContext')[0].getSearchContext;
@@ -107,12 +108,6 @@ exports.ExposeStore = (moduleRaidStr) => {
107
108
  // eslint-disable-next-line no-undef
108
109
  if ((m = window.mR.findModule('ChatCollection')[0]) && m.ChatCollection && typeof m.ChatCollection.findImpl === 'undefined' && typeof m.ChatCollection._find !== 'undefined') m.ChatCollection.findImpl = m.ChatCollection._find;
109
110
 
110
- // TODO remove these once everybody has been updated to WWebJS with legacy sessions removed
111
- const _linkPreview = window.mR.findModule('queryLinkPreview');
112
- if (_linkPreview && _linkPreview[0] && _linkPreview[0].default) {
113
- window.Store.Wap = _linkPreview[0].default;
114
- }
115
-
116
111
  const _isMDBackend = window.mR.findModule('isMDBackend');
117
112
  if(_isMDBackend && _isMDBackend[0] && _isMDBackend[0].isMDBackend) {
118
113
  window.Store.MDBackend = _isMDBackend[0].isMDBackend();
@@ -176,9 +171,7 @@ exports.LoadUtils = () => {
176
171
  forceGif: options.sendVideoAsGif
177
172
  });
178
173
 
179
- if (options.caption){
180
- attOptions.caption = options.caption;
181
- }
174
+ attOptions.caption = options.caption;
182
175
  content = options.sendMediaAsSticker ? undefined : attOptions.preview;
183
176
  attOptions.isViewOnce = options.isViewOnce;
184
177
 
@@ -271,15 +264,14 @@ exports.LoadUtils = () => {
271
264
 
272
265
  if (options.linkPreview) {
273
266
  delete options.linkPreview;
274
-
275
- // Not supported yet by WhatsApp Web on MD
276
- if(!window.Store.MDBackend) {
277
- const link = window.Store.Validators.findLink(content);
278
- if (link) {
279
- const preview = await window.Store.Wap.queryLinkPreview(link.url);
267
+ const link = window.Store.Validators.findLink(content);
268
+ if (link) {
269
+ let preview = await window.Store.LinkPreview.getLinkPreview(link);
270
+ if (preview && preview.data) {
271
+ preview = preview.data;
280
272
  preview.preview = true;
281
273
  preview.subtype = 'url';
282
- options = { ...options, ...preview };
274
+ options = {...options, ...preview};
283
275
  }
284
276
  }
285
277
  }
@@ -379,17 +371,13 @@ exports.LoadUtils = () => {
379
371
  }
380
372
 
381
373
  if (options.linkPreview) {
382
- options.linkPreview = null;
383
-
384
- // Not supported yet by WhatsApp Web on MD
385
- if(!window.Store.MDBackend) {
386
- const link = window.Store.Validators.findLink(content);
387
- if (link) {
388
- const preview = await window.Store.Wap.queryLinkPreview(link.url);
389
- preview.preview = true;
390
- preview.subtype = 'url';
391
- options = { ...options, ...preview };
392
- }
374
+ delete options.linkPreview;
375
+ const link = window.Store.Validators.findLink(content);
376
+ if (link) {
377
+ const preview = await window.Store.LinkPreview.getLinkPreview(link);
378
+ preview.preview = true;
379
+ preview.subtype = 'url';
380
+ options = { ...options, ...preview };
393
381
  }
394
382
  }
395
383