@kanaraa/baileys 3.1.9 → 3.2.0

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.
@@ -1429,6 +1429,9 @@ export const makeMessagesRecvSocket = (config) => {
1429
1429
  }
1430
1430
  }
1431
1431
  cleanMessage(msg, authState.creds.me.id, authState.creds.me.lid);
1432
+ if (isLidUser(msg.key.remoteJid) && msg.key.remoteJidAlt && isPnUser(msg.key.remoteJidAlt)) {
1433
+ msg.key.remoteJid = msg.key.remoteJidAlt;
1434
+ }
1432
1435
  await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
1433
1436
  });
1434
1437
  }
@@ -7,7 +7,7 @@ import { getUrlInfo } from '../Utils/link-preview.js';
7
7
  import { makeKeyedMutex, makeMutex } from '../Utils/make-mutex.js';
8
8
  import { getMessageReportingToken, shouldIncludeReportingToken } from '../Utils/reporting-utils.js';
9
9
  import { buildMergedTcTokenIndexWrite, isTcTokenExpired, resolveIssuanceJid, resolveTcTokenJid, shouldSendNewTcToken, storeTcTokensFromIqResult } from '../Utils/tc-token-utils.js';
10
- import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isJidBot, isJidGroup, isJidMetaAI, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, PSA_WID, S_WHATSAPP_NET } from '../WABinary/index.js';
10
+ import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isJidBot, isJidGroup, isJidMetaAI, isJidNewsletter, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, PSA_WID, S_WHATSAPP_NET } from '../WABinary/index.js';
11
11
  import { USyncQuery, USyncUser } from '../WAUSync/index.js';
12
12
  import { makeNewsletterSocket } from './newsletter.js';
13
13
  export const makeMessagesSocket = (config) => {
@@ -475,7 +475,7 @@ export const makeMessagesSocket = (config) => {
475
475
  const bytes = encodeNewsletterMessage(patched);
476
476
  binaryNodeContent.push({
477
477
  tag: 'plaintext',
478
- attrs: {},
478
+ attrs: mediaType ? { mediatype: mediaType } : {},
479
479
  content: bytes
480
480
  });
481
481
  const stanza = {
@@ -1110,7 +1110,10 @@ export const makeMessagesSocket = (config) => {
1110
1110
  //TODO: CACHE
1111
1111
  getProfilePicUrl: sock.profilePictureUrl,
1112
1112
  getCallLink: sock.createCallLink,
1113
- upload: waUploadToServer,
1113
+ upload: (readStream, opts) => {
1114
+ const up = waUploadToServer(readStream, { ...opts, newsletter: isJidNewsletter(jid) });
1115
+ return up;
1116
+ },
1114
1117
  mediaCache: config.mediaCache,
1115
1118
  options: config.options,
1116
1119
  messageId: generateMessageIDV2(sock.user?.id),
@@ -4,21 +4,22 @@ import { getBinaryNodeChild } from '../WABinary/index.js';
4
4
  import { makeGroupsSocket } from './groups.js';
5
5
  import { executeWMexQuery as genericExecuteWMexQuery } from './mex.js';
6
6
  const parseNewsletterCreateResponse = (response) => {
7
- const { id, thread_metadata: thread, viewer_metadata: viewer } = response;
7
+ const { id, thread_metadata: rawThread, viewer_metadata: viewer } = response;
8
+ const thread = rawThread ?? {};
8
9
  return {
9
10
  id: id,
10
11
  owner: undefined,
11
- name: thread.name.text,
12
- creation_time: parseInt(thread.creation_time, 10),
13
- description: thread.description.text,
12
+ name: thread.name?.text ?? '',
13
+ creation_time: parseInt(thread.creation_time ?? 0, 10),
14
+ description: thread.description?.text ?? '',
14
15
  invite: thread.invite,
15
- subscribers: parseInt(thread.subscribers_count, 10),
16
+ subscribers: parseInt(thread.subscribers_count ?? 0, 10),
16
17
  verification: thread.verification,
17
18
  picture: {
18
- id: thread.picture.id,
19
- directPath: thread.picture.direct_path
19
+ id: thread.picture?.id,
20
+ directPath: thread.picture?.direct_path
20
21
  },
21
- mute_state: viewer.mute
22
+ mute_state: viewer?.mute
22
23
  };
23
24
  };
24
25
  const parseNewsletterMetadata = (result) => {
@@ -641,12 +641,16 @@ const uploadMedia = async (params, logger) => {
641
641
  }
642
642
  };
643
643
  export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
644
- return async (filePath, { mediaType, fileEncSha256B64, timeoutMs }) => {
644
+ return async (filePath, { mediaType, fileEncSha256B64, newsletter, timeoutMs }) => {
645
645
  // send a query JSON to obtain the url & auth token to upload our media
646
646
  let uploadInfo = await refreshMediaConn(false);
647
647
  let urls;
648
648
  const hosts = [...customUploadHosts, ...uploadInfo.hosts];
649
649
  fileEncSha256B64 = encodeBase64EncodedStringForUpload(fileEncSha256B64);
650
+ let media = MEDIA_PATH_MAP[mediaType];
651
+ if (newsletter) {
652
+ media = media?.replace('/mms/', '/newsletter/newsletter-');
653
+ }
650
654
  // Prepare common headers
651
655
  const customHeaders = (() => {
652
656
  const hdrs = options?.headers;
@@ -662,7 +666,7 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
662
666
  for (const { hostname } of hosts) {
663
667
  logger.debug(`uploading to "${hostname}"`);
664
668
  const auth = encodeURIComponent(uploadInfo.auth);
665
- const url = `https://${hostname}${MEDIA_PATH_MAP[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
669
+ const url = `https://${hostname}${media}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
666
670
  let result;
667
671
  try {
668
672
  result = await uploadMedia({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kanaraa/baileys",
3
3
  "type": "module",
4
- "version": "3.1.9",
4
+ "version": "3.2.0",
5
5
  "description": "Modded Baileys v7, Rebuilt on top of official @whiskeysockets/baileys 7.0.0-rc13, with the interactive & rich-message content types (buttons, lists, carousel, cards, shop/collection, native flow, AI rich response, sticker packs, admin invite, payments, etc.).",
6
6
  "keywords": [
7
7
  "whatsapp",