@realvare/based 2.6.1 → 2.6.11

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.
@@ -698,8 +698,7 @@ const makeSocket = (config) => {
698
698
  values,
699
699
  selectableCount: selectableCount || 1,
700
700
  };
701
- // @ts-ignore
702
- return ws.sendMessage(jid, { poll: pollCreation });
701
+ return sock.sendMessage(jid, { poll: pollCreation });
703
702
  },
704
703
  // lid related functions
705
704
  assertLid: (jid) => {
@@ -36,12 +36,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.getUrlInfo = void 0;
37
37
  const messages_1 = require("./messages");
38
38
  const messages_media_1 = require("./messages-media");
39
- const THUMBNAIL_WIDTH_PX = 192;
39
+ const THUMBNAIL_WIDTH_PX = 1200;
40
40
  /** Fetches an image and generates a thumbnail for it */
41
- const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
42
- const stream = await (0, messages_media_1.getHttpStream)(url, fetchOpts);
43
- const result = await (0, messages_media_1.extractImageThumb)(stream, thumbnailWidth);
44
- return result;
41
+ const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts, logger }) => {
42
+ try {
43
+ const stream = await (0, messages_media_1.getHttpStream)(url, fetchOpts);
44
+ const result = await (0, messages_media_1.extractImageThumb)(stream, thumbnailWidth);
45
+ logger?.debug({ url, thumbnailWidth }, 'Successfully generated compressed JPEG thumbnail');
46
+ return result;
47
+ } catch (error) {
48
+ logger?.warn({ url, thumbnailWidth, error: error.message }, 'Failed to generate compressed JPEG thumbnail, attempting fallback');
49
+ // Fallback to lower quality if high quality fails
50
+ try {
51
+ const stream = await (0, messages_media_1.getHttpStream)(url, fetchOpts);
52
+ const result = await (0, messages_media_1.extractImageThumb)(stream, Math.min(thumbnailWidth, 512));
53
+ logger?.debug({ url, fallbackWidth: Math.min(thumbnailWidth, 512) }, 'Successfully generated fallback thumbnail');
54
+ return result;
55
+ } catch (fallbackError) {
56
+ logger?.error({ url, error: fallbackError.message }, 'Failed to generate fallback thumbnail');
57
+ throw fallbackError;
58
+ }
59
+ }
45
60
  };
46
61
  /**
47
62
  * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
@@ -86,6 +101,7 @@ const getUrlInfo = async (text, opts = {
86
101
  });
87
102
  if (info && 'title' in info && info.title) {
88
103
  const [image] = info.images;
104
+ opts.logger?.debug({ url: previewLink, title: info.title, imageCount: info.images.length }, 'Fetched link preview info');
89
105
  const urlInfo = {
90
106
  'canonical-url': info.url,
91
107
  'matched-text': text,
@@ -107,7 +123,7 @@ const getUrlInfo = async (text, opts = {
107
123
  else {
108
124
  try {
109
125
  urlInfo.jpegThumbnail = image
110
- ? (await getCompressedJpegThumbnail(image, opts)).buffer
126
+ ? (await getCompressedJpegThumbnail(image, { ...opts, logger: opts.logger })).buffer
111
127
  : undefined;
112
128
  }
113
129
  catch (error) {
@@ -479,21 +479,8 @@ async function generateThumbnail(file, mediaType, options) {
479
479
  };
480
480
  }
481
481
  const getHttpStream = async (url, options = {}) => {
482
- const { retryRequestDelayMs, maxMsgRetryCount } = options;
483
- let retries = 0;
484
- while (retries < maxMsgRetryCount) {
485
- try {
486
- const fetched = await axios_1.default.get(url.toString(), { ...options, responseType: 'stream' });
487
- return fetched.data;
488
- }
489
- catch (error) {
490
- retries++;
491
- if (retries >= maxMsgRetryCount) {
492
- throw error;
493
- }
494
- await (0, generics_1.delay)(retryRequestDelayMs || 1000);
495
- }
496
- }
482
+ const fetched = await axios_1.default.get(url.toString(), { ...options, responseType: 'stream' });
483
+ return fetched.data;
497
484
  };
498
485
  exports.getHttpStream = getHttpStream;
499
486
  const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
@@ -245,14 +245,14 @@ const generateWAMessageContent = async (message, options) => {
245
245
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
246
246
  var _p, _q;
247
247
 
248
- // iOS-specific externalAdReply handling
248
+ // Cross-platform externalAdReply thumbnail handling
249
249
  if (message.contextInfo?.externalAdReply) {
250
250
  const externalAdReply = message.contextInfo.externalAdReply;
251
251
 
252
- // If thumbnailUrl is provided but no thumbnail binary data, try to fetch and convert for iOS
252
+ // If thumbnailUrl is provided but no thumbnail binary data, try to fetch and convert for all platforms
253
253
  if (externalAdReply.thumbnailUrl && !externalAdReply.thumbnail) {
254
254
  try {
255
- // Attempt to download the thumbnail image for iOS compatibility
255
+ // Attempt to download the thumbnail image for cross-platform compatibility
256
256
  const axiosResponse = await axios_1.default.get(externalAdReply.thumbnailUrl, {
257
257
  responseType: 'arraybuffer',
258
258
  timeout: 5000,
@@ -265,13 +265,20 @@ const generateWAMessageContent = async (message, options) => {
265
265
  externalAdReply.thumbnail = Buffer.from(axiosResponse.data);
266
266
  // Clear thumbnailUrl since we now have binary data
267
267
  delete externalAdReply.thumbnailUrl;
268
+ options.logger?.debug('Successfully downloaded externalAdReply thumbnail for cross-platform compatibility');
268
269
  }
269
270
  } catch (error) {
270
- // If thumbnail download fails, keep thumbnailUrl as is
271
- options.logger?.warn('Failed to download externalAdReply thumbnail for iOS:', error.message);
271
+ // If thumbnail download fails, keep thumbnailUrl as fallback
272
+ options.logger?.warn('Failed to download externalAdReply thumbnail for cross-platform compatibility:', error.message);
272
273
  }
273
274
  }
274
275
 
276
+ // Ensure renderLargerThumbnail is set for better display across platforms
277
+ if (externalAdReply.renderLargerThumbnail === undefined) {
278
+ externalAdReply.renderLargerThumbnail = true;
279
+ options.logger?.debug('Set renderLargerThumbnail=true for improved cross-platform display');
280
+ }
281
+
275
282
  // Update the contextInfo with modified externalAdReply
276
283
  message.contextInfo.externalAdReply = externalAdReply;
277
284
  }
@@ -557,7 +564,7 @@ const generateWAMessageContent = async (message, options) => {
557
564
  thumbnail: extAdReply.thumbnail,
558
565
  sourceUrl: extAdReply.sourceUrl,
559
566
  showAdAttribution: extAdReply.showAdAttribution || false,
560
- renderLargerThumbnail: extAdReply.renderLargerThumbnail || false
567
+ renderLargerThumbnail: extAdReply.renderLargerThumbnail !== false
561
568
  }
562
569
  }
563
570
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realvare/based",
3
- "version": "2.6.01",
3
+ "version": "2.6.11",
4
4
  "description": "whatsapp api by sam",
5
5
  "keywords": [
6
6
  "baileys",