whatsapp-web.js 1.22.1 → 1.22.2-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
@@ -140,6 +140,10 @@ client.on('message', async msg => {
140
140
  const attachmentData = await quotedMsg.downloadMedia();
141
141
  client.sendMessage(msg.from, attachmentData, { caption: 'Here\'s your requested media.' });
142
142
  }
143
+ if (quotedMsg.hasMedia && quotedMsg.type === 'audio') {
144
+ const audio = await quotedMsg.downloadMedia();
145
+ await client.sendMessage(msg.from, audio, { sendAudioAsVoice: true });
146
+ }
143
147
  } else if (msg.body === '!isviewonce' && msg.hasQuotedMsg) {
144
148
  const quotedMsg = await msg.getQuotedMessage();
145
149
  if (quotedMsg.hasMedia) {
package/index.d.ts CHANGED
@@ -904,7 +904,7 @@ declare namespace WAWebJS {
904
904
  export interface MessageSendOptions {
905
905
  /** Show links preview. Has no effect on multi-device accounts. */
906
906
  linkPreview?: boolean
907
- /** Send audio as voice message */
907
+ /** Send audio as voice message with a generated waveform */
908
908
  sendAudioAsVoice?: boolean
909
909
  /** Send video as gif */
910
910
  sendVideoAsGif?: boolean
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whatsapp-web.js",
3
- "version": "1.22.1",
3
+ "version": "1.22.2-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
@@ -172,7 +172,7 @@ class Client extends EventEmitter {
172
172
  }
173
173
  );
174
174
 
175
- const INTRO_IMG_SELECTOR = '[data-testid="intro-md-beta-logo-dark"], [data-testid="intro-md-beta-logo-light"], [data-asset-intro-image-light="true"], [data-asset-intro-image-dark="true"]';
175
+ const INTRO_IMG_SELECTOR = '[data-icon=\'search\']';
176
176
  const INTRO_QRCODE_SELECTOR = 'div[data-ref] canvas';
177
177
 
178
178
  // Checks which selector appears first
@@ -785,7 +785,7 @@ class Client extends EventEmitter {
785
785
  * Message options.
786
786
  * @typedef {Object} MessageSendOptions
787
787
  * @property {boolean} [linkPreview=true] - Show links preview. Has no effect on multi-device accounts.
788
- * @property {boolean} [sendAudioAsVoice=false] - Send audio as voice message
788
+ * @property {boolean} [sendAudioAsVoice=false] - Send audio as voice message with a generated waveform
789
789
  * @property {boolean} [sendVideoAsGif=false] - Send video as gif
790
790
  * @property {boolean} [sendMediaAsSticker=false] - Send media as a sticker
791
791
  * @property {boolean} [sendMediaAsDocument=false] - Send media as a document
@@ -41,7 +41,7 @@ class RemoteAuth extends BaseAuthStrategy {
41
41
  this.clientId = clientId;
42
42
  this.backupSyncIntervalMs = backupSyncIntervalMs;
43
43
  this.dataPath = path.resolve(dataPath || './.wwebjs_auth/');
44
- this.tempDir = `${this.dataPath}/wwebjs_temp_session`;
44
+ this.tempDir = `${this.dataPath}/wwebjs_temp_session_${this.clientId}`;
45
45
  this.requiredDirs = ['Default', 'IndexedDB', 'Local Storage']; /* => Required Files & Dirs in WWebJS to restore session */
46
46
  }
47
47
 
@@ -168,8 +168,8 @@ class Message extends Base {
168
168
  inviteCodeExp: data.inviteCodeExp,
169
169
  groupId: data.inviteGrp,
170
170
  groupName: data.inviteGrpName,
171
- fromId: data.from?._serialized ? data.from._serialized : data.from,
172
- toId: data.to?._serialized ? data.to._serialized : data.to
171
+ fromId: '_serialized' in data.from ? data.from._serialized : data.from,
172
+ toId: '_serialized' in data.to ? data.to._serialized : data.to
173
173
  } : undefined;
174
174
 
175
175
  /**
@@ -390,6 +390,9 @@ exports.LoadUtils = () => {
390
390
 
391
391
  if (forceVoice && mediaData.type === 'audio') {
392
392
  mediaData.type = 'ptt';
393
+ const waveform = mediaObject.contentInfo.waveform;
394
+ mediaData.waveform =
395
+ waveform ?? await window.WWebJS.generateWaveform(file);
393
396
  }
394
397
 
395
398
  if (forceGif && mediaData.type === 'video') {
@@ -632,6 +635,42 @@ exports.LoadUtils = () => {
632
635
  return result;
633
636
  };
634
637
 
638
+ /**
639
+ * Referenced from and modified:
640
+ * @see https://github.com/wppconnect-team/wa-js/commit/290ebfefe6021b3d17f7fdfdda5545bb0473b26f
641
+ */
642
+ window.WWebJS.generateWaveform = async (audioFile) => {
643
+ try {
644
+ const audioData = await audioFile.arrayBuffer();
645
+ const audioContext = new AudioContext();
646
+ const audioBuffer = await audioContext.decodeAudioData(audioData);
647
+
648
+ const rawData = audioBuffer.getChannelData(0);
649
+ const samples = 64;
650
+ const blockSize = Math.floor(rawData.length / samples);
651
+ const filteredData = [];
652
+ for (let i = 0; i < samples; i++) {
653
+ const blockStart = blockSize * i;
654
+ let sum = 0;
655
+ for (let j = 0; j < blockSize; j++) {
656
+ sum = sum + Math.abs(rawData[blockStart + j]);
657
+ }
658
+ filteredData.push(sum / blockSize);
659
+ }
660
+
661
+ const multiplier = Math.pow(Math.max(...filteredData), -1);
662
+ const normalizedData = filteredData.map((n) => n * multiplier);
663
+
664
+ const waveform = new Uint8Array(
665
+ normalizedData.map((n) => Math.floor(100 * n))
666
+ );
667
+
668
+ return waveform;
669
+ } catch (e) {
670
+ return undefined;
671
+ }
672
+ };
673
+
635
674
  window.WWebJS.sendClearChat = async (chatId) => {
636
675
  let chat = window.Store.Chat.get(chatId);
637
676
  if (chat !== undefined) {