@nuiisweety/baileys 0.1.17 → 0.1.19

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.
@@ -478,10 +478,19 @@ export const makeMessagesSocket = (config) => {
478
478
  }
479
479
  if (isNewsletter) {
480
480
  const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
481
+ // Evaluate mediaType from patched message (after patchMessageBeforeSending),
482
+ // and place it in plaintext attrs — NOT in stanza attrs (WA server requires it there)
483
+ const newsletterMediaType = getMediaType(normalizeMessageContent(patched) || patched);
484
+ if (newsletterMediaType) {
485
+ extraAttrs['mediatype'] = newsletterMediaType;
486
+ }
487
+ if (patched.interactiveMessage && !extraAttrs['mediatype']) {
488
+ extraAttrs['mediatype'] = 'interactive';
489
+ }
481
490
  const bytes = encodeNewsletterMessage(patched);
482
491
  binaryNodeContent.push({
483
492
  tag: 'plaintext',
484
- attrs: {},
493
+ attrs: extraAttrs,
485
494
  content: bytes
486
495
  });
487
496
  const stanza = {
@@ -489,13 +498,12 @@ export const makeMessagesSocket = (config) => {
489
498
  attrs: {
490
499
  to: jid,
491
500
  id: msgId,
492
- type: getMessageType(message),
493
- ...(extraAttrs || {}),
501
+ type: getMessageType(patched),
494
502
  ...(additionalAttributes || {})
495
503
  },
496
504
  content: binaryNodeContent
497
505
  };
498
- logger.debug({ msgId }, `sending newsletter message to ${jid}`);
506
+ logger.debug({ msgId, mediaType: newsletterMediaType, extraAttrs }, `sending newsletter message to ${jid}`);
499
507
  await sendNode(stanza);
500
508
  return;
501
509
  }
@@ -490,6 +490,7 @@ export const makeMessagesSocket = (config) => {
490
490
  to: jid,
491
491
  id: msgId,
492
492
  type: getMessageType(message),
493
+ ...(extraAttrs || {}),
493
494
  ...(additionalAttributes || {})
494
495
  },
495
496
  content: binaryNodeContent
@@ -295,10 +295,25 @@ export async function generateThumbnail(file, mediaType, options) {
295
295
  };
296
296
  }
297
297
  export const getHttpStream = async (url, options = {}) => {
298
- const response = await fetch(url.toString(), {
298
+ const urlStr = url.toString();
299
+ // Auto-inject Referer for domains that require it (e.g. tikwm.com)
300
+ let autoHeaders = {};
301
+ try {
302
+ const parsedUrl = new URL(urlStr);
303
+ const origin = parsedUrl.origin;
304
+ autoHeaders = {
305
+ 'Referer': origin + '/',
306
+ 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Mobile Safari/537.36'
307
+ };
308
+ } catch (_) {}
309
+ const mergedHeaders = {
310
+ ...autoHeaders,
311
+ ...(options.headers || {})
312
+ };
313
+ const response = await fetch(urlStr, {
299
314
  dispatcher: options.dispatcher,
300
315
  method: 'GET',
301
- headers: options.headers
316
+ headers: mergedHeaders
302
317
  });
303
318
  if (!response.ok) {
304
319
  throw new Boom(`Failed to fetch stream from ${url}`, { statusCode: response.status, data: { url } });