@nexustechpro/baileys 1.0.7 → 1.0.9

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.
@@ -717,6 +717,7 @@ export const makeSocket = (config) => {
717
717
  logger.debug("Triggering background pre-key check after stream error")
718
718
  triggerPreKeyCheck("stream-error-recovery", "normal")
719
719
  }
720
+ end(new Boom(`Stream Errored (${reason})`, { statusCode, data: node }))
720
721
  })
721
722
 
722
723
  ws.on("CB:failure", (node) => {
@@ -505,21 +505,32 @@ const REUPLOAD_STATUS = [410, 404];
505
505
 
506
506
  export const downloadMediaMessage = async (message, type, options, ctx) => {
507
507
  const downloadMsg = async () => {
508
- const mContent = extractMessageContent(message.message);
508
+ let normalizedMessage = message;
509
+ if (!message.message && message.key && message.participant) {
510
+ normalizedMessage = { key: message.key, message: message, messageTimestamp: message.messageTimestamp };
511
+ }
512
+ if (!normalizedMessage.message && typeof message === 'object') {
513
+ const possibleMessage = message.message || message.quoted?.message || message;
514
+ normalizedMessage = { key: message.key || {}, message: possibleMessage, messageTimestamp: message.messageTimestamp };
515
+ }
516
+ const mContent = extractMessageContent(normalizedMessage.message);
509
517
  if (!mContent) throw new Boom('No message present', { statusCode: 400, data: message });
510
-
511
518
  const contentType = getContentType(mContent);
512
519
  let mediaType = contentType?.replace('Message', '');
513
520
  const media = mContent[contentType];
514
-
515
521
  if (!media || typeof media !== 'object' || (!('url' in media) && !('thumbnailDirectPath' in media)))
516
522
  throw new Boom(`"${contentType}" is not a media message`);
517
-
518
523
  const download = 'thumbnailDirectPath' in media && !('url' in media) ? { directPath: media.thumbnailDirectPath, mediaKey: media.mediaKey } : media;
519
524
  const stream = await downloadContentFromMessage(download, mediaType, options);
520
- return type === 'buffer' ? Buffer.concat(await Promise.all((await stream).iterator().map(c => Promise.resolve(c)))) : stream;
525
+ if (type === 'buffer') {
526
+ const chunks = [];
527
+ for await (const chunk of stream) {
528
+ chunks.push(chunk);
529
+ }
530
+ return Buffer.concat(chunks);
531
+ }
532
+ return stream;
521
533
  };
522
-
523
534
  return downloadMsg().catch(async (error) => {
524
535
  if (ctx && typeof error?.status === 'number' && REUPLOAD_STATUS.includes(error.status)) {
525
536
  message = await ctx.reuploadRequest(message);
package/lib/index.js CHANGED
@@ -31,7 +31,7 @@ const banner = `
31
31
  const info = `
32
32
  ┌───────────────────────────────────────────────────────────────────────┐
33
33
  │ 📦 Package: @nexustechpro/baileys │
34
- │ 🔖 Version: 1.0.7
34
+ │ 🔖 Version: 1.0.9
35
35
  │ ⚡ Status: Production Ready │
36
36
  ├───────────────────────────────────────────────────────────────────────┤
37
37
  │ 🚀 Advanced WhatsApp Web API Client │
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nexustechpro/baileys",
3
3
  "type": "module",
4
- "version": "1.0.7",
4
+ "version": "1.0.9",
5
5
  "description": "Advanced WhatsApp Web API client with interactive messages, product catalogs, carousels, events, payments, and polls.",
6
6
  "keywords": [
7
7
  "whatsapp",