@periskope/baileys 6.7.12-alpha.3 → 6.7.13-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/README.md CHANGED
@@ -44,7 +44,7 @@ To run the example script, download or clone the repo and then type the followin
44
44
 
45
45
  Use the stable version:
46
46
  ```
47
- yarn add @whiskeysockets/baileys
47
+ yarn add baileys
48
48
  ```
49
49
 
50
50
  Use the edge version (no guarantee of stability, but latest fixes + features)
@@ -52,9 +52,9 @@ Use the edge version (no guarantee of stability, but latest fixes + features)
52
52
  yarn add github:WhiskeySockets/Baileys
53
53
  ```
54
54
 
55
- Then import your code using:
55
+ Then import the default function in your code:
56
56
  ```ts
57
- import makeWASocket from '@whiskeysockets/baileys'
57
+ import makeWASocket from 'baileys'
58
58
  ```
59
59
 
60
60
  # Links
@@ -183,7 +183,7 @@ WhatsApp provides a multi-device API that allows Baileys to be authenticated as
183
183
  > You can customize browser name if you connect with **QR-CODE**, with `Browser` constant, we have some browsers config, **see [here](https://baileys.whiskeysockets.io/types/BrowsersMap.html)**
184
184
 
185
185
  ```ts
186
- import makeWASocket from '@whiskeysockets/baileys'
186
+ import makeWASocket from 'baileys'
187
187
 
188
188
  const sock = makeWASocket({
189
189
  // can provide additional config here
@@ -203,13 +203,13 @@ If the connection is successful, you will see a QR code printed on your terminal
203
203
  The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
204
204
 
205
205
  ```ts
206
- import makeWASocket from '@whiskeysockets/baileys'
206
+ import makeWASocket from 'baileys'
207
207
 
208
208
  const sock = makeWASocket({
209
209
  // can provide additional config here
210
210
  printQRInTerminal: false //need to be false
211
211
  })
212
-
212
+ // NOTE: WAIT TILL QR EVENT BEFORE REQUESTING THE PAIRING CODE
213
213
  if (!sock.authState.creds.registered) {
214
214
  const number = 'XXXXXXXXXXX'
215
215
  const code = await sock.requestPairingCode(number)
@@ -276,7 +276,7 @@ You obviously don't want to keep scanning the QR code every time you want to con
276
276
 
277
277
  So, you can load the credentials to log back in:
278
278
  ```ts
279
- import makeWASocket, { useMultiFileAuthState } from '@whiskeysockets/baileys'
279
+ import makeWASocket, { useMultiFileAuthState } from 'baileys'
280
280
 
281
281
  const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
282
282
 
@@ -316,7 +316,7 @@ sock.ev.on('messages.upsert', ({ messages }) => {
316
316
  > This example includes basic auth storage too
317
317
 
318
318
  ```ts
319
- import makeWASocket, { DisconnectReason, useMultiFileAuthState } from '@whiskeysockets/baileys'
319
+ import makeWASocket, { DisconnectReason, useMultiFileAuthState } from 'baileys'
320
320
  import { Boom } from '@hapi/boom'
321
321
 
322
322
  async function connectToWhatsApp () {
@@ -398,7 +398,7 @@ sock.ev.on('messages.update', event => {
398
398
  It can be used as follows:
399
399
 
400
400
  ```ts
401
- import makeWASocket, { makeInMemoryStore } from '@whiskeysockets/baileys'
401
+ import makeWASocket, { makeInMemoryStore } from 'baileys'
402
402
  // the store maintains the data of the WA connection in memory
403
403
  // can be written out to a file & read from it
404
404
  const store = makeInMemoryStore({ })
@@ -714,7 +714,7 @@ await sock.sendMessage(jid, {
714
714
  If you want to save the media you received
715
715
  ```ts
716
716
  import { createWriteStream } from 'fs'
717
- import { downloadMediaMessage, getContentType } from '@whiskeysockets/baileys'
717
+ import { downloadMediaMessage, getContentType } from 'baileys'
718
718
 
719
719
  sock.ev.on('messages.upsert', async ({ [m] }) => {
720
720
  if (!m.message) return // if there is no text or media message
@@ -242,7 +242,7 @@ exports.getAudioDuration = getAudioDuration;
242
242
  */
243
243
  async function getAudioWaveform(buffer, logger) {
244
244
  try {
245
- const audioDecode = (buffer) => Promise.resolve().then(() => __importStar(require('audio-decode'))).then(({ default: audioDecode }) => audioDecode(buffer));
245
+ const { default: decoder } = await eval('import(\'audio-decode\')');
246
246
  let audioData;
247
247
  if (Buffer.isBuffer(buffer)) {
248
248
  audioData = buffer;
@@ -254,7 +254,7 @@ async function getAudioWaveform(buffer, logger) {
254
254
  else {
255
255
  audioData = await (0, exports.toBuffer)(buffer);
256
256
  }
257
- const audioBuffer = await audioDecode(audioData);
257
+ const audioBuffer = await decoder(audioData);
258
258
  const rawData = audioBuffer.getChannelData(0); // We only need to work with one channel of data
259
259
  const samples = 64; // Number of samples we want to have in our final data set
260
260
  const blockSize = Math.floor(rawData.length / samples); // the number of samples in each subdivision
@@ -157,8 +157,14 @@ const prepareWAMessageMedia = async (message, options) => {
157
157
  encWriteStream.destroy();
158
158
  // remove tmp files
159
159
  if (didSaveToTmpPath && bodyPath) {
160
- await fs_1.promises.unlink(bodyPath);
161
- logger === null || logger === void 0 ? void 0 : logger.debug('removed tmp files');
160
+ try {
161
+ await fs_1.promises.access(bodyPath);
162
+ await fs_1.promises.unlink(bodyPath);
163
+ logger === null || logger === void 0 ? void 0 : logger.debug('removed tmp file');
164
+ }
165
+ catch (error) {
166
+ logger === null || logger === void 0 ? void 0 : logger.warn('failed to remove tmp file');
167
+ }
162
168
  }
163
169
  });
164
170
  const obj = Types_1.WAProto.Message.fromObject({
@@ -106,7 +106,7 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
106
106
  }
107
107
  exports.decryptPollVote = decryptPollVote;
108
108
  const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }) => {
109
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
109
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
110
110
  const meId = creds.me.id;
111
111
  const { accountSettings } = creds;
112
112
  const chat = { id: (0, WABinary_1.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
@@ -220,7 +220,8 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
220
220
  case WAProto_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
221
221
  ev.emit('messages.update', [
222
222
  {
223
- key: protocolMsg.key,
223
+ // flip the sender / fromMe properties because they're in the perspective of the sender
224
+ key: { ...message.key, id: (_d = protocolMsg.key) === null || _d === void 0 ? void 0 : _d.id },
224
225
  update: {
225
226
  message: {
226
227
  editedMessage: {
@@ -243,11 +244,11 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
243
244
  };
244
245
  ev.emit('messages.reaction', [{
245
246
  reaction,
246
- key: (_d = content.reactionMessage) === null || _d === void 0 ? void 0 : _d.key,
247
+ key: (_e = content.reactionMessage) === null || _e === void 0 ? void 0 : _e.key,
247
248
  }]);
248
249
  }
249
250
  else if (message.messageStubType) {
250
- const jid = (_e = message.key) === null || _e === void 0 ? void 0 : _e.remoteJid;
251
+ const jid = (_f = message.key) === null || _f === void 0 ? void 0 : _f.remoteJid;
251
252
  //let actor = whatsappID (message.participant)
252
253
  let participants;
253
254
  const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
@@ -291,39 +292,39 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
291
292
  emitParticipantsUpdate('promote');
292
293
  break;
293
294
  case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
294
- const announceValue = (_f = message.messageStubParameters) === null || _f === void 0 ? void 0 : _f[0];
295
+ const announceValue = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
295
296
  emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
296
297
  break;
297
298
  case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
298
- const restrictValue = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
299
+ const restrictValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
299
300
  emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
300
301
  break;
301
302
  case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
302
- const name = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
303
+ const name = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
303
304
  chat.name = name;
304
305
  emitGroupUpdate({ subject: name });
305
306
  break;
306
307
  case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
307
- const description = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
308
+ const description = (_k = message.messageStubParameters) === null || _k === void 0 ? void 0 : _k[0];
308
309
  chat.description = description;
309
310
  emitGroupUpdate({ desc: description });
310
311
  break;
311
312
  case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
312
- const code = (_k = message.messageStubParameters) === null || _k === void 0 ? void 0 : _k[0];
313
+ const code = (_l = message.messageStubParameters) === null || _l === void 0 ? void 0 : _l[0];
313
314
  emitGroupUpdate({ inviteCode: code });
314
315
  break;
315
316
  case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
316
- const memberAddValue = (_l = message.messageStubParameters) === null || _l === void 0 ? void 0 : _l[0];
317
+ const memberAddValue = (_m = message.messageStubParameters) === null || _m === void 0 ? void 0 : _m[0];
317
318
  emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
318
319
  break;
319
320
  case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
320
- const approvalMode = (_m = message.messageStubParameters) === null || _m === void 0 ? void 0 : _m[0];
321
+ const approvalMode = (_o = message.messageStubParameters) === null || _o === void 0 ? void 0 : _o[0];
321
322
  emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
322
323
  break;
323
324
  case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
324
- const participant = (_o = message.messageStubParameters) === null || _o === void 0 ? void 0 : _o[0];
325
- const action = (_p = message.messageStubParameters) === null || _p === void 0 ? void 0 : _p[1];
326
- const method = (_q = message.messageStubParameters) === null || _q === void 0 ? void 0 : _q[2];
325
+ const participant = (_p = message.messageStubParameters) === null || _p === void 0 ? void 0 : _p[0];
326
+ const action = (_q = message.messageStubParameters) === null || _q === void 0 ? void 0 : _q[1];
327
+ const method = (_r = message.messageStubParameters) === null || _r === void 0 ? void 0 : _r[2];
327
328
  emitGroupRequestJoin(participant, action, method);
328
329
  break;
329
330
  }
@@ -336,7 +337,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
336
337
  const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
337
338
  const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
338
339
  const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
339
- const pollEncKey = (_r = pollMsg.messageContextInfo) === null || _r === void 0 ? void 0 : _r.messageSecret;
340
+ const pollEncKey = (_s = pollMsg.messageContextInfo) === null || _s === void 0 ? void 0 : _s.messageSecret;
340
341
  try {
341
342
  const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
342
343
  pollEncKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@periskope/baileys",
3
- "version": "6.7.12-alpha.3",
3
+ "version": "6.7.13-alpha.1",
4
4
  "description": "WhatsApp API",
5
5
  "keywords": [
6
6
  "whatsapp",