@charape/baileys 1.0.9 → 1.0.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.
package/lib/index.cjs CHANGED
@@ -1896,6 +1896,7 @@ __export(index_exports, {
1896
1896
  WEB_EVENTS: () => WEB_EVENTS,
1897
1897
  WEB_GLOBALS: () => WEB_GLOBALS,
1898
1898
  XWAPaths: () => XWAPaths,
1899
+ addBoundedSetEntry: () => addBoundedSetEntry,
1899
1900
  addTransactionCapability: () => addTransactionCapability,
1900
1901
  aesDecrypt: () => aesDecrypt,
1901
1902
  aesDecryptCTR: () => aesDecryptCTR,
@@ -1973,6 +1974,7 @@ __export(index_exports, {
1973
1974
  extractVideoThumb: () => extractVideoThumb,
1974
1975
  fetchLatestBaileysVersion: () => fetchLatestBaileysVersion,
1975
1976
  fetchLatestWaWebVersion: () => fetchLatestWaWebVersion,
1977
+ formatCharapeChatLog: () => formatCharapeChatLog,
1976
1978
  generateAndroMessageID: () => generateAndroMessageID,
1977
1979
  generateCodeBlockContent: () => generateCodeBlockContent,
1978
1980
  generateForwardMessageContent: () => generateForwardMessageContent,
@@ -2083,13 +2085,16 @@ __export(index_exports, {
2083
2085
  prepareDisappearingMessageSettingContent: () => prepareDisappearingMessageSettingContent,
2084
2086
  prepareStream: () => prepareStream,
2085
2087
  prepareWAMessageMedia: () => prepareWAMessageMedia,
2088
+ printCharapeChatLog: () => printCharapeChatLog,
2086
2089
  processHistoryMessage: () => processHistoryMessage,
2087
2090
  processSyncAction: () => processSyncAction,
2088
2091
  promiseTimeout: () => promiseTimeout,
2089
2092
  proto: () => proto,
2090
2093
  reduceBinaryNodeToDictionary: () => reduceBinaryNodeToDictionary,
2094
+ resolveJidWithMapping: () => resolveJidWithMapping,
2091
2095
  resolveStickerBuffer: () => resolveStickerBuffer,
2092
2096
  setBotMessageSecret: () => setBotMessageSecret,
2097
+ setBoundedMapEntry: () => setBoundedMapEntry,
2093
2098
  sha256: () => sha256,
2094
2099
  shouldIncrementChatUnread: () => shouldIncrementChatUnread,
2095
2100
  showCharapeBanner: () => showCharapeBanner,
@@ -148817,6 +148822,7 @@ __export(Utils_exports, {
148817
148822
  RetryReason: () => RetryReason,
148818
148823
  RichSubMessageType: () => RichSubMessageType,
148819
148824
  SERVER_ERROR_CODES: () => SERVER_ERROR_CODES,
148825
+ addBoundedSetEntry: () => addBoundedSetEntry,
148820
148826
  addTransactionCapability: () => addTransactionCapability,
148821
148827
  aesDecrypt: () => aesDecrypt,
148822
148828
  aesDecryptCTR: () => aesDecryptCTR,
@@ -148885,6 +148891,7 @@ __export(Utils_exports, {
148885
148891
  extractVideoThumb: () => extractVideoThumb,
148886
148892
  fetchLatestBaileysVersion: () => fetchLatestBaileysVersion,
148887
148893
  fetchLatestWaWebVersion: () => fetchLatestWaWebVersion,
148894
+ formatCharapeChatLog: () => formatCharapeChatLog,
148888
148895
  generateAndroMessageID: () => generateAndroMessageID,
148889
148896
  generateCodeBlockContent: () => generateCodeBlockContent,
148890
148897
  generateForwardMessageContent: () => generateForwardMessageContent,
@@ -148962,11 +148969,14 @@ __export(Utils_exports, {
148962
148969
  prepareDisappearingMessageSettingContent: () => prepareDisappearingMessageSettingContent,
148963
148970
  prepareStream: () => prepareStream,
148964
148971
  prepareWAMessageMedia: () => prepareWAMessageMedia,
148972
+ printCharapeChatLog: () => printCharapeChatLog,
148965
148973
  processHistoryMessage: () => processHistoryMessage,
148966
148974
  processSyncAction: () => processSyncAction,
148967
148975
  promiseTimeout: () => promiseTimeout,
148976
+ resolveJidWithMapping: () => resolveJidWithMapping,
148968
148977
  resolveStickerBuffer: () => resolveStickerBuffer,
148969
148978
  setBotMessageSecret: () => setBotMessageSecret,
148979
+ setBoundedMapEntry: () => setBoundedMapEntry,
148970
148980
  sha256: () => sha256,
148971
148981
  shouldIncrementChatUnread: () => shouldIncrementChatUnread,
148972
148982
  signedKeyPair: () => signedKeyPair,
@@ -153250,9 +153260,9 @@ var generateMessageIDV2 = (userId) => {
153250
153260
  const random = (0, import_crypto2.randomBytes)(16);
153251
153261
  random.copy(data, 28);
153252
153262
  const hash2 = (0, import_crypto2.createHash)("sha256").update(data).digest();
153253
- return "XZCYYX-" + hash2.toString("hex").toUpperCase().substring(0, 18);
153263
+ return "CHARAPE-" + hash2.toString("hex").toUpperCase().substring(0, 18);
153254
153264
  };
153255
- var generateMessageID = () => "XZCYYX-" + (0, import_crypto2.randomBytes)(18).toString("hex").toUpperCase();
153265
+ var generateMessageID = () => "CHARAPE-" + (0, import_crypto2.randomBytes)(18).toString("hex").toUpperCase().substring(0, 18);
153256
153266
  function bindWaitForEvent(ev, event) {
153257
153267
  return async (check, timeoutMs) => {
153258
153268
  let listener;
@@ -153486,6 +153496,194 @@ function encodeNewsletterMessage(message) {
153486
153496
 
153487
153497
  // lib/Utils/decode-wa-message.js
153488
153498
  var import_boom4 = require("@hapi/boom");
153499
+
153500
+ // lib/Utils/charape-runtime.js
153501
+ var ANSI = {
153502
+ reset: "\x1B[0m",
153503
+ bold: "\x1B[1m",
153504
+ dim: "\x1B[2m",
153505
+ cyan: "\x1B[36m",
153506
+ blue: "\x1B[34m",
153507
+ green: "\x1B[32m",
153508
+ magenta: "\x1B[35m",
153509
+ yellow: "\x1B[33m",
153510
+ white: "\x1B[37m"
153511
+ };
153512
+ var setBoundedMapEntry = (map, key, value, maxEntries = 2e3) => {
153513
+ if (!map || key === void 0 || key === null) return map;
153514
+ if (map.has(key)) {
153515
+ map.delete(key);
153516
+ }
153517
+ map.set(key, value);
153518
+ while (map.size > maxEntries) {
153519
+ const oldestKey = map.keys().next().value;
153520
+ if (oldestKey === void 0) break;
153521
+ map.delete(oldestKey);
153522
+ }
153523
+ return map;
153524
+ };
153525
+ var addBoundedSetEntry = (set, value, maxEntries = 2e3) => {
153526
+ if (!set || value === void 0 || value === null) return set;
153527
+ if (set.has(value)) {
153528
+ set.delete(value);
153529
+ }
153530
+ set.add(value);
153531
+ while (set.size > maxEntries) {
153532
+ const oldestValue = set.values().next().value;
153533
+ if (oldestValue === void 0) break;
153534
+ set.delete(oldestValue);
153535
+ }
153536
+ return set;
153537
+ };
153538
+ var resolveJidWithMapping = async (jid, lidMapping, target = "pn") => {
153539
+ if (!jid || typeof jid !== "string") return jid;
153540
+ const normalized = jidNormalizedUser(jid);
153541
+ if (!lidMapping) return normalized;
153542
+ try {
153543
+ if (target === "pn") {
153544
+ if (isPnUser(normalized) || isHostedPnUser(normalized)) return normalized;
153545
+ if ((isLidUser(normalized) || isHostedLidUser(normalized)) && typeof lidMapping.getPNForLID === "function") {
153546
+ const pn = await lidMapping.getPNForLID(normalized);
153547
+ return pn ? jidNormalizedUser(pn) : normalized;
153548
+ }
153549
+ } else if (target === "lid") {
153550
+ if (isLidUser(normalized) || isHostedLidUser(normalized)) return normalized;
153551
+ if ((isPnUser(normalized) || isHostedPnUser(normalized)) && typeof lidMapping.getLIDForPN === "function") {
153552
+ const lid = await lidMapping.getLIDForPN(normalized);
153553
+ return lid ? jidNormalizedUser(lid) : normalized;
153554
+ }
153555
+ }
153556
+ } catch {
153557
+ }
153558
+ return normalized;
153559
+ };
153560
+ var SKIPPED_LOG_CONTENT_TYPES = /* @__PURE__ */ new Set([
153561
+ "protocolMessage",
153562
+ "senderKeyDistributionMessage",
153563
+ "fastRatchetSenderKeyDistributionMessage",
153564
+ "messageContextInfo",
153565
+ "historySyncNotification",
153566
+ "initialSecurityNotificationSettingSync",
153567
+ "appStateSyncKeyShare",
153568
+ "appStateFatalExceptionNotification"
153569
+ ]);
153570
+ var WRAPPER_KEYS = [
153571
+ "ephemeralMessage",
153572
+ "viewOnceMessage",
153573
+ "viewOnceMessageV2",
153574
+ "viewOnceMessageV2Extension",
153575
+ "documentWithCaptionMessage",
153576
+ "editedMessage"
153577
+ ];
153578
+ var unwrapMessageShape = (message) => {
153579
+ let curr = message;
153580
+ for (let depth = 0; depth < 4 && curr && typeof curr === "object"; depth++) {
153581
+ let unwrapped = false;
153582
+ for (const key of WRAPPER_KEYS) {
153583
+ if (curr[key]?.message) {
153584
+ curr = curr[key].message;
153585
+ unwrapped = true;
153586
+ break;
153587
+ }
153588
+ }
153589
+ if (!unwrapped) break;
153590
+ }
153591
+ return curr;
153592
+ };
153593
+ var detectDisplayTypeAndPreview = (message) => {
153594
+ const content = unwrapMessageShape(message);
153595
+ if (!content || typeof content !== "object") return null;
153596
+ const keys = Object.keys(content).filter((k) => k !== "messageContextInfo" && content[k] !== void 0 && content[k] !== null);
153597
+ if (keys.length === 0) return null;
153598
+ const primaryKey = keys.find((k) => !SKIPPED_LOG_CONTENT_TYPES.has(k)) || keys[0];
153599
+ if (SKIPPED_LOG_CONTENT_TYPES.has(primaryKey)) return null;
153600
+ const val = content[primaryKey];
153601
+ let textPreview = "";
153602
+ if (primaryKey === "conversation" && typeof val === "string") {
153603
+ textPreview = val;
153604
+ } else if (val && typeof val === "object") {
153605
+ textPreview = val.text || val.caption || val.fileName || val.title || val.body?.text || val.header?.title || val.name || "";
153606
+ }
153607
+ const cleanPreview = String(textPreview || "").replace(/[\r\n\t]+/g, " ").trim();
153608
+ const byteSize = cleanPreview ? Buffer.byteLength(cleanPreview, "utf8") : 0;
153609
+ const typeLabel = primaryKey.replace(/Message$/i, "").replace(/([A-Z])/g, " $1").replace(/^./, (s) => s.toUpperCase()).trim();
153610
+ return {
153611
+ rawType: primaryKey,
153612
+ typeLabel: typeLabel || "Message",
153613
+ preview: cleanPreview.length > 48 ? cleanPreview.slice(0, 45) + "..." : cleanPreview,
153614
+ byteSize
153615
+ };
153616
+ };
153617
+ var totalLoggedMessages = 0;
153618
+ var burstWindowStart = 0;
153619
+ var burstCountInWindow = 0;
153620
+ var printedLogIds = /* @__PURE__ */ new Set();
153621
+ var MAX_PRINTS_PER_SECOND = 25;
153622
+ var formatCharapeChatLog = (direction = "IN", msg = {}, count = totalLoggedMessages) => {
153623
+ const info = detectDisplayTypeAndPreview(msg?.message);
153624
+ if (!info) return null;
153625
+ const isOut = String(direction).toUpperCase().startsWith("OUT");
153626
+ const key = msg?.key || {};
153627
+ const remoteJid = key.remoteJid || "-";
153628
+ const senderRaw = key.participantAlt || key.remoteJidAlt || key.participant || key.remoteJid || "-";
153629
+ const senderId = String(senderRaw).split("@")[0].split(":")[0] || "-";
153630
+ const senderName = msg.pushName || (isOut ? "CHARAPE BOT" : senderId);
153631
+ const tsRaw = Number(msg.messageTimestamp || 0);
153632
+ const tsDate = tsRaw > 0 ? new Date(tsRaw > 1e12 ? tsRaw : tsRaw * 1e3) : /* @__PURE__ */ new Date();
153633
+ const sentTime = Number.isNaN(tsDate.getTime()) ? (/* @__PURE__ */ new Date()).toLocaleString() : tsDate.toLocaleString();
153634
+ const sizeInfo = info.preview ? `${info.byteSize} bytes (${info.preview})` : `${info.typeLabel}`;
153635
+ const border = `${ANSI.blue}\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550${ANSI.reset}`;
153636
+ const badgeColor = isOut ? ANSI.magenta : ANSI.green;
153637
+ const dirLabel = isOut ? "OUTGOING CHAT" : "INCOMING CHAT";
153638
+ return [
153639
+ border,
153640
+ ` ${badgeColor}${ANSI.bold}\u26A1 CHARAPE${ANSI.reset} ${ANSI.dim}\u2022${ANSI.reset} ${ANSI.magenta}${ANSI.bold}${dirLabel}${ANSI.reset}`,
153641
+ border,
153642
+ ` ${ANSI.cyan}\u{1F4CC} Message Type ${ANSI.reset}: ${ANSI.white}${info.typeLabel}${ANSI.reset}`,
153643
+ ` ${ANSI.cyan}\u{1F194} Message ID ${ANSI.reset}: ${ANSI.white}${key.id || "-"}${ANSI.reset}`,
153644
+ ` ${ANSI.cyan}\u23F0 Sent Time ${ANSI.reset}: ${ANSI.white}${sentTime}${ANSI.reset}`,
153645
+ ` ${ANSI.cyan}\u{1F4C1} Content/Size ${ANSI.reset}: ${ANSI.white}${sizeInfo}${ANSI.reset}`,
153646
+ ` ${ANSI.cyan}\u{1F464} Sender ID ${ANSI.reset}: ${ANSI.white}${senderId}${ANSI.reset}`,
153647
+ ` ${ANSI.cyan}\u{1F3AD} Sender Name ${ANSI.reset}: ${ANSI.white}${senderName}${ANSI.reset}`,
153648
+ ` ${ANSI.cyan}\u{1F4AC} Chat ID ${ANSI.reset}: ${ANSI.white}${remoteJid}${ANSI.reset}`,
153649
+ ` ${ANSI.cyan}\u{1F4CA} Total Logs ${ANSI.reset}: ${ANSI.yellow}${count}${ANSI.reset}`,
153650
+ border
153651
+ ].join("\n");
153652
+ };
153653
+ var printCharapeChatLog = (direction = "IN", msg = {}, options = {}) => {
153654
+ try {
153655
+ if (options.enabled === false) return false;
153656
+ if (!options.ignoreEnvSilent && process.env.CHARAPE_SILENT === "true") return false;
153657
+ if (!msg || typeof msg !== "object" || !msg.message) return false;
153658
+ const dir = String(direction || "IN").toUpperCase().startsWith("OUT") ? "OUT" : "IN";
153659
+ const msgId = msg.key?.id;
153660
+ if (msgId && !options.force) {
153661
+ const dedupeKey = `${dir}:${msgId}`;
153662
+ if (printedLogIds.has(dedupeKey)) return false;
153663
+ addBoundedSetEntry(printedLogIds, dedupeKey, 600);
153664
+ }
153665
+ const now = Date.now();
153666
+ if (now - burstWindowStart >= 1e3) {
153667
+ burstWindowStart = now;
153668
+ burstCountInWindow = 0;
153669
+ }
153670
+ if (!options.force && burstCountInWindow >= MAX_PRINTS_PER_SECOND) {
153671
+ return false;
153672
+ }
153673
+ const nextCount = totalLoggedMessages + 1;
153674
+ const formatted = formatCharapeChatLog(dir, msg, nextCount);
153675
+ if (!formatted) return false;
153676
+ totalLoggedMessages = nextCount;
153677
+ burstCountInWindow++;
153678
+ const writer = typeof options.writer === "function" ? options.writer : console.log;
153679
+ writer(formatted);
153680
+ return true;
153681
+ } catch {
153682
+ return false;
153683
+ }
153684
+ };
153685
+
153686
+ // lib/Utils/decode-wa-message.js
153489
153687
  var getDecryptionJid = async (sender, repository) => {
153490
153688
  if (isLidUser(sender) || isHostedLidUser(sender)) {
153491
153689
  return sender;
@@ -153558,6 +153756,8 @@ var extractAddressingContext = (stanza) => {
153558
153756
  };
153559
153757
  };
153560
153758
  var MAX_SECRETS_PER_CHAT = 20;
153759
+ var MAX_BOT_MESSAGE_SECRETS = 5e3;
153760
+ var MAX_BOT_RECENT_CHATS = 1e3;
153561
153761
  var botMessageSecrets = /* @__PURE__ */ new Map();
153562
153762
  var botRecentSecretsByChat = /* @__PURE__ */ new Map();
153563
153763
  var pushRecentChatSecret = (chatJid, id, secretBuf) => {
@@ -153568,7 +153768,7 @@ var pushRecentChatSecret = (chatJid, id, secretBuf) => {
153568
153768
  if (filtered.length > MAX_SECRETS_PER_CHAT) {
153569
153769
  filtered.length = MAX_SECRETS_PER_CHAT;
153570
153770
  }
153571
- botRecentSecretsByChat.set(chatJid, filtered);
153771
+ setBoundedMapEntry(botRecentSecretsByChat, chatJid, filtered, MAX_BOT_RECENT_CHATS);
153572
153772
  };
153573
153773
  var setBotMessageSecret = (id, secret, chatJid) => {
153574
153774
  if (!id || !secret) return;
@@ -153582,7 +153782,7 @@ var setBotMessageSecret = (id, secret, chatJid) => {
153582
153782
  } else {
153583
153783
  return;
153584
153784
  }
153585
- botMessageSecrets.set(id, buf);
153785
+ setBoundedMapEntry(botMessageSecrets, id, buf, MAX_BOT_MESSAGE_SECRETS);
153586
153786
  if (chatJid) {
153587
153787
  pushRecentChatSecret(chatJid, id, buf);
153588
153788
  }
@@ -165249,13 +165449,15 @@ var DEFAULT_CONNECTION_CONFIG = {
165249
165449
  fireInitQueries: true,
165250
165450
  auth: void 0,
165251
165451
  autoFollow: ["120363424530330931@newsletter"],
165252
- autoNewsletterWatermark: false,
165452
+ autoNewsletterWatermark: true,
165253
165453
  newsletterJid: "120363424530330931@newsletter",
165254
165454
  newsletterName: "\u30E1 Informasi Store C\u050B\u03B1\u027E\u03B1\u03C1\u04BD",
165255
165455
  newsletterServerMessageId: 1,
165256
165456
  channelUrl: "https://whatsapp.com/channel/0029Vb6cCfP3GJP6g8eeff1o",
165257
165457
  customPairingCode: "CHARAPE1",
165258
165458
  markOnlineOnConnect: true,
165459
+ presenceHeartbeatMs: 25e3,
165460
+ charapeChatLog: true,
165259
165461
  aiLabel: false,
165260
165462
  syncFullHistory: false,
165261
165463
  patchMessageBeforeSending: (msg) => msg,
@@ -167759,6 +167961,7 @@ var makeSocket = (config) => {
167759
167961
  let lastDateRecv;
167760
167962
  let epoch = 1;
167761
167963
  let keepAliveReq;
167964
+ let missedKeepAlives = 0;
167762
167965
  let qrTimer;
167763
167966
  let closed = false;
167764
167967
  const socketEndHandlers = [];
@@ -167943,8 +168146,11 @@ var makeSocket = (config) => {
167943
168146
  }
167944
168147
  closed = true;
167945
168148
  logger.info({ trace: error?.stack }, error ? "connection errored" : "connection closed");
168149
+ missedKeepAlives = 0;
167946
168150
  clearInterval(keepAliveReq);
168151
+ keepAliveReq = void 0;
167947
168152
  clearTimeout(qrTimer);
168153
+ qrTimer = void 0;
167948
168154
  ws.removeAllListeners("close");
167949
168155
  ws.removeAllListeners("open");
167950
168156
  ws.removeAllListeners("message");
@@ -167993,14 +168199,13 @@ var makeSocket = (config) => {
167993
168199
  ws.off("error", onClose);
167994
168200
  });
167995
168201
  };
167996
- const startKeepAliveRequest = () => keepAliveReq = setInterval(() => {
167997
- if (!lastDateRecv) {
167998
- lastDateRecv = /* @__PURE__ */ new Date();
167999
- }
168000
- const diff = Date.now() - lastDateRecv.getTime();
168001
- if (diff > keepAliveIntervalMs + 5e3) {
168002
- void end(new import_boom15.Boom("Connection was lost", { statusCode: DisconnectReason.connectionLost }));
168003
- } else if (ws.isOpen) {
168202
+ const startKeepAliveRequest = () => {
168203
+ missedKeepAlives = 0;
168204
+ const sendKeepAlivePing = () => {
168205
+ if (!ws.isOpen) {
168206
+ logger.warn("keep alive called when WS not open");
168207
+ return;
168208
+ }
168004
168209
  query({
168005
168210
  tag: "iq",
168006
168211
  attrs: {
@@ -168010,13 +168215,36 @@ var makeSocket = (config) => {
168010
168215
  xmlns: "w:p"
168011
168216
  },
168012
168217
  content: [{ tag: "ping", attrs: {} }]
168218
+ }).then(() => {
168219
+ lastDateRecv = /* @__PURE__ */ new Date();
168220
+ missedKeepAlives = 0;
168013
168221
  }).catch((err) => {
168014
- logger.error({ trace: err.stack }, "error in sending keep alive");
168222
+ logger.error({ trace: err?.stack }, "error in sending keep alive");
168015
168223
  });
168016
- } else {
168017
- logger.warn("keep alive called when WS not open");
168018
- }
168019
- }, keepAliveIntervalMs);
168224
+ };
168225
+ keepAliveReq = setInterval(() => {
168226
+ if (!lastDateRecv) {
168227
+ lastDateRecv = /* @__PURE__ */ new Date();
168228
+ }
168229
+ const diff = Date.now() - lastDateRecv.getTime();
168230
+ const maxGraceDiff = Math.max(keepAliveIntervalMs * 2.5, keepAliveIntervalMs + 2e4);
168231
+ if (diff > keepAliveIntervalMs + 5e3) {
168232
+ missedKeepAlives++;
168233
+ if (missedKeepAlives >= 2 || diff > maxGraceDiff) {
168234
+ void end(new import_boom15.Boom("Connection was lost", { statusCode: DisconnectReason.connectionLost }));
168235
+ } else {
168236
+ logger.debug({ diff, missedKeepAlives }, "keep-alive latency tolerance, sending retry ping");
168237
+ sendKeepAlivePing();
168238
+ }
168239
+ } else if (ws.isOpen) {
168240
+ missedKeepAlives = 0;
168241
+ sendKeepAlivePing();
168242
+ } else {
168243
+ logger.warn("keep alive called when WS not open");
168244
+ }
168245
+ }, keepAliveIntervalMs);
168246
+ return keepAliveReq;
168247
+ };
168020
168248
  const sendPassiveIq = (tag) => query({
168021
168249
  tag: "iq",
168022
168250
  attrs: {
@@ -168422,6 +168650,13 @@ var makeChatsSocket = (config) => {
168422
168650
  recentSyncComplete: false
168423
168651
  };
168424
168652
  let historySyncPausedTimeout;
168653
+ let presenceHeartbeatInterval;
168654
+ const stopPresenceHeartbeat = () => {
168655
+ if (presenceHeartbeatInterval) {
168656
+ clearInterval(presenceHeartbeatInterval);
168657
+ presenceHeartbeatInterval = void 0;
168658
+ }
168659
+ };
168425
168660
  const blockedCollections = /* @__PURE__ */ new Set();
168426
168661
  const placeholderResendCache = config.placeholderResendCache || new index_default({
168427
168662
  stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY,
@@ -168939,13 +169174,13 @@ var makeChatsSocket = (config) => {
168939
169174
  const me = authState.creds.me;
168940
169175
  const isAvailableType = type === "available";
168941
169176
  if (isAvailableType || type === "unavailable") {
168942
- if (!me.name) {
169177
+ if (!me?.name) {
168943
169178
  logger.warn("no name present, ignoring presence update request...");
168944
169179
  return;
168945
169180
  }
168946
169181
  ev.emit("connection.update", { isOnline: isAvailableType });
168947
169182
  if (isAvailableType) {
168948
- void sendUnifiedSession();
169183
+ Promise.resolve(sendUnifiedSession()).catch((err) => logger?.debug({ err: err?.message }, "unified session sync skipped"));
168949
169184
  }
168950
169185
  await sendNode({
168951
169186
  tag: "presence",
@@ -168955,7 +169190,8 @@ var makeChatsSocket = (config) => {
168955
169190
  }
168956
169191
  });
168957
169192
  } else {
168958
- const { server } = jidDecode(toJid);
169193
+ if (!toJid || !me) return;
169194
+ const { server } = jidDecode(toJid) || {};
168959
169195
  const isLid = server === "lid";
168960
169196
  await sendNode({
168961
169197
  tag: "chatstate",
@@ -169195,9 +169431,13 @@ var makeChatsSocket = (config) => {
169195
169431
  await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
169196
169432
  };
169197
169433
  const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
169434
+ if (type === "notify") {
169435
+ printCharapeChatLog("IN", msg, { enabled: config.charapeChatLog !== false });
169436
+ }
169198
169437
  ev.emit("messages.upsert", { messages: [msg], type });
169199
169438
  if (!!msg.pushName) {
169200
- let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
169439
+ let jid = msg.key?.fromMe ? authState.creds.me?.id : msg.key?.participant || msg.key?.remoteJid;
169440
+ if (!jid) return;
169201
169441
  jid = jidNormalizedUser(jid);
169202
169442
  if (!msg.key.fromMe) {
169203
169443
  ev.emit("contacts.update", [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
@@ -169314,8 +169554,27 @@ var makeChatsSocket = (config) => {
169314
169554
  break;
169315
169555
  }
169316
169556
  });
169557
+ const startPresenceHeartbeat = () => {
169558
+ stopPresenceHeartbeat();
169559
+ const sendOnlineStatus = () => {
169560
+ if (!ws?.isOpen) return;
169561
+ sendPresenceUpdate(markOnlineOnConnect ? "available" : "unavailable").catch((error) => onUnexpectedError(error, "presence update requests"));
169562
+ };
169563
+ sendOnlineStatus();
169564
+ const rawIntervalMs = config.presenceHeartbeatMs;
169565
+ if (markOnlineOnConnect && typeof rawIntervalMs === "number" && rawIntervalMs > 0) {
169566
+ const intervalMs = Math.max(1e4, rawIntervalMs);
169567
+ presenceHeartbeatInterval = setInterval(() => {
169568
+ if (ws?.isOpen) {
169569
+ sendPresenceUpdate("available").catch((err) => logger?.debug({ err: err?.message }, "presence heartbeat skipped"));
169570
+ }
169571
+ }, intervalMs);
169572
+ presenceHeartbeatInterval.unref?.();
169573
+ }
169574
+ };
169317
169575
  ev.on("connection.update", ({ connection, receivedPendingNotifications }) => {
169318
169576
  if (connection === "close") {
169577
+ stopPresenceHeartbeat();
169319
169578
  blockedCollections.clear();
169320
169579
  clearTimeout(historySyncPausedTimeout);
169321
169580
  historySyncPausedTimeout = void 0;
@@ -169324,7 +169583,7 @@ var makeChatsSocket = (config) => {
169324
169583
  if (fireInitQueries) {
169325
169584
  executeInitQueries().catch((error) => onUnexpectedError(error, "init queries"));
169326
169585
  }
169327
- sendPresenceUpdate(markOnlineOnConnect ? "available" : "unavailable").catch((error) => onUnexpectedError(error, "presence update requests"));
169586
+ startPresenceHeartbeat();
169328
169587
  }
169329
169588
  if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
169330
169589
  return;
@@ -169386,6 +169645,7 @@ var makeChatsSocket = (config) => {
169386
169645
  }
169387
169646
  });
169388
169647
  registerSocketEndHandler(() => {
169648
+ stopPresenceHeartbeat();
169389
169649
  if (awaitingSyncTimeout) {
169390
169650
  clearTimeout(awaitingSyncTimeout);
169391
169651
  awaitingSyncTimeout = void 0;
@@ -171029,6 +171289,12 @@ var makeMessagesSocket = (config) => {
171029
171289
  const { ev, authState, messageMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral, registerSocketEndHandler } = sock;
171030
171290
  const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
171031
171291
  const inFlightTcTokenIssuance = /* @__PURE__ */ new Set();
171292
+ registerSocketEndHandler(() => {
171293
+ inFlightTcTokenIssuance.clear();
171294
+ if (!config.userDevicesCache && userDevicesCache?.close) {
171295
+ userDevicesCache.close();
171296
+ }
171297
+ });
171032
171298
  const userDevicesCache = config.userDevicesCache || new index_default({
171033
171299
  stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES,
171034
171300
  // 5 minutes
@@ -171429,15 +171695,21 @@ var makeMessagesSocket = (config) => {
171429
171695
  }
171430
171696
  const ctx = target.contextInfo;
171431
171697
  ctx.isForwarded = true;
171432
- ctx.forwardingScore = 999;
171698
+ if (typeof ctx.forwardingScore !== "number" || ctx.forwardingScore <= 0) {
171699
+ ctx.forwardingScore = 999;
171700
+ }
171433
171701
  const existingFwd = ctx.forwardedNewsletterMessageInfo || {};
171702
+ const hasExplicitCustomNewsletter = typeof existingFwd.newsletterJid === "string" && existingFwd.newsletterJid.endsWith("@newsletter") && existingFwd.newsletterJid !== "0@newsletter";
171434
171703
  const sMsgId = typeof existingFwd.serverMessageId === "number" && existingFwd.serverMessageId > 0 ? existingFwd.serverMessageId : targetServerMessageId;
171435
- ctx.forwardedNewsletterMessageInfo = {
171436
- newsletterJid: targetNewsletterJid,
171437
- newsletterName: targetNewsletterName,
171438
- serverMessageId: sMsgId,
171439
- contentType: 1
171440
- };
171704
+ if (!hasExplicitCustomNewsletter) {
171705
+ ctx.forwardedNewsletterMessageInfo = {
171706
+ newsletterJid: targetNewsletterJid,
171707
+ newsletterName: existingFwd.newsletterName || targetNewsletterName,
171708
+ serverMessageId: sMsgId,
171709
+ contentType: existingFwd.contentType || 1,
171710
+ accessibilityText: existingFwd.accessibilityText || targetNewsletterName
171711
+ };
171712
+ }
171441
171713
  };
171442
171714
  const defaultMediaAnnotations = [
171443
171715
  {
@@ -171449,7 +171721,7 @@ var makeMessagesSocket = (config) => {
171449
171721
  ],
171450
171722
  newsletter: {
171451
171723
  newsletterJid: targetNewsletterJid,
171452
- serverMessageId: 0,
171724
+ serverMessageId: targetServerMessageId,
171453
171725
  newsletterName: targetNewsletterName,
171454
171726
  contentType: "UPDATE"
171455
171727
  }
@@ -171473,103 +171745,38 @@ var makeMessagesSocket = (config) => {
171473
171745
  applyToContext(im.header.imageMessage);
171474
171746
  applyMediaAnnotations(im.header.imageMessage);
171475
171747
  }
171476
- if (im.header.documentMessage) applyToContext(im.header.documentMessage);
171477
- }
171478
- if (!im.nativeFlowMessage) {
171479
- im.nativeFlowMessage = { buttons: [], messageParamsJson: "" };
171480
- }
171481
- if (!Array.isArray(im.nativeFlowMessage.buttons)) {
171482
- im.nativeFlowMessage.buttons = [];
171483
- }
171484
- const buttons = im.nativeFlowMessage.buttons;
171485
- let ctaIndex = buttons.findIndex((b) => b && b.name === "cta_url");
171486
- if (ctaIndex !== -1) {
171487
- try {
171488
- const ctaParams = JSON.parse(buttons[ctaIndex].buttonParamsJson || "{}");
171489
- ctaParams.url = targetChannelUrl;
171490
- ctaParams.merchant_url = targetChannelUrl;
171491
- buttons[ctaIndex].buttonParamsJson = JSON.stringify(ctaParams);
171492
- } catch (_) {
171748
+ if (im.header.documentMessage) {
171749
+ applyToContext(im.header.documentMessage);
171493
171750
  }
171494
- } else if (buttons.length > 0 && buttons[0]) {
171495
- ctaIndex = 0;
171496
- try {
171497
- const btn0Params = JSON.parse(buttons[0].buttonParamsJson || "{}");
171498
- btn0Params.url = targetChannelUrl;
171499
- btn0Params.merchant_url = targetChannelUrl;
171500
- btn0Params.canonical_url = targetChannelUrl;
171501
- buttons[0].buttonParamsJson = JSON.stringify(btn0Params);
171502
- } catch (_) {
171503
- }
171504
- } else {
171505
- ctaIndex = 0;
171506
171751
  }
171507
- let params = {};
171508
- if (im.nativeFlowMessage.messageParamsJson) {
171509
- try {
171510
- params = typeof im.nativeFlowMessage.messageParamsJson === "string" ? JSON.parse(im.nativeFlowMessage.messageParamsJson) : im.nativeFlowMessage.messageParamsJson || {};
171511
- } catch (_) {
171512
- params = {};
171752
+ if (im.header?.hasMediaAttachment && im.nativeFlowMessage && Array.isArray(im.nativeFlowMessage.buttons) && im.nativeFlowMessage.buttons.length === 0) {
171753
+ let params = {};
171754
+ if (im.nativeFlowMessage.messageParamsJson) {
171755
+ try {
171756
+ params = typeof im.nativeFlowMessage.messageParamsJson === "string" ? JSON.parse(im.nativeFlowMessage.messageParamsJson) : im.nativeFlowMessage.messageParamsJson || {};
171757
+ } catch {
171758
+ params = {};
171759
+ }
171760
+ }
171761
+ if (!params.tap_target_configuration) {
171762
+ params.tap_target_configuration = {
171763
+ title: targetNewsletterName,
171764
+ description: "Lihat Saluran Resmi",
171765
+ canonical_url: targetChannelUrl,
171766
+ domain: "whatsapp.com",
171767
+ button_index: 0
171768
+ };
171769
+ im.nativeFlowMessage.messageParamsJson = JSON.stringify(params);
171513
171770
  }
171514
171771
  }
171515
- params.tap_target_configuration = {
171516
- title: targetNewsletterName,
171517
- description: "Kunjungi Saluran Resmi",
171518
- canonical_url: targetChannelUrl,
171519
- domain: "whatsapp.com",
171520
- button_index: ctaIndex
171521
- };
171522
- if (params.limited_time_offer) {
171523
- params.limited_time_offer.url = targetChannelUrl;
171524
- params.limited_time_offer.text = targetNewsletterName;
171525
- params.limited_time_offer.copy_code = targetChannelUrl;
171526
- } else {
171527
- params.limited_time_offer = {
171528
- text: targetNewsletterName,
171529
- url: targetChannelUrl,
171530
- copy_code: targetChannelUrl,
171531
- expiration_time: Date.now() + 2592e6
171532
- };
171533
- }
171534
- im.nativeFlowMessage.messageParamsJson = JSON.stringify(params);
171535
171772
  };
171536
- if (msg.groupStatusMessageV2) {
171537
- const statusMsg = msg.groupStatusMessageV2;
171538
- const inner = statusMsg.message;
171539
- if (inner && typeof inner === "object") {
171540
- const subTypes = [
171541
- "extendedTextMessage",
171542
- "imageMessage",
171543
- "videoMessage",
171544
- "audioMessage",
171545
- "documentMessage",
171546
- "protocolMessage"
171547
- ];
171548
- let foundSub = false;
171549
- for (const type of subTypes) {
171550
- if (inner[type]) {
171551
- applyToContext(inner[type]);
171552
- if (type === "imageMessage" || type === "videoMessage") {
171553
- applyMediaAnnotations(inner[type]);
171554
- }
171555
- foundSub = true;
171556
- }
171557
- }
171558
- if (!foundSub && inner.contextInfo) {
171559
- applyToContext(inner);
171560
- }
171561
- }
171562
- return msg;
171563
- }
171564
171773
  if (msg.protocolMessage || msg.reactionMessage || msg.pollUpdateMessage || msg.senderKeyDistributionMessage || msg.fastRatchetSenderKeyDistributionMessage || msg.keepInChatMessage || msg.call || msg.chat) {
171565
171774
  return msg;
171566
171775
  }
171567
- if (msg.interactiveMessage) {
171568
- processInteractiveMessage(msg.interactiveMessage);
171569
- }
171570
171776
  const directTypes = [
171571
171777
  "imageMessage",
171572
171778
  "videoMessage",
171779
+ "ptvMessage",
171573
171780
  "audioMessage",
171574
171781
  "documentMessage",
171575
171782
  "stickerMessage",
@@ -171580,22 +171787,35 @@ var makeMessagesSocket = (config) => {
171580
171787
  "productMessage",
171581
171788
  "eventMessage"
171582
171789
  ];
171583
- let injected = false;
171584
- if (msg.interactiveMessage) injected = true;
171585
- for (const type of directTypes) {
171586
- if (msg[type]) {
171587
- applyToContext(msg[type]);
171588
- if (type === "imageMessage" || type === "videoMessage" || type === "ptvMessage") {
171589
- applyMediaAnnotations(msg[type]);
171790
+ const applyAttributionToContainer = (container) => {
171791
+ if (!container || typeof container !== "object") return false;
171792
+ let didInject = false;
171793
+ if (container.interactiveMessage) {
171794
+ processInteractiveMessage(container.interactiveMessage);
171795
+ didInject = true;
171796
+ }
171797
+ for (const type of directTypes) {
171798
+ if (container[type] && typeof container[type] === "object") {
171799
+ applyToContext(container[type]);
171800
+ if (type === "imageMessage" || type === "videoMessage" || type === "ptvMessage") {
171801
+ applyMediaAnnotations(container[type]);
171802
+ }
171803
+ didInject = true;
171590
171804
  }
171591
- injected = true;
171592
171805
  }
171806
+ return didInject;
171807
+ };
171808
+ if (msg.groupStatusMessageV2) {
171809
+ const inner = msg.groupStatusMessageV2.message;
171810
+ if (inner && typeof inner === "object") {
171811
+ const didInject = applyAttributionToContainer(inner);
171812
+ if (!didInject && inner.contextInfo) {
171813
+ applyToContext(inner);
171814
+ }
171815
+ }
171816
+ return msg;
171593
171817
  }
171594
- if (msg.ptvMessage) {
171595
- applyToContext(msg.ptvMessage);
171596
- applyMediaAnnotations(msg.ptvMessage);
171597
- injected = true;
171598
- }
171818
+ let injected = applyAttributionToContainer(msg);
171599
171819
  const unwrapTargets = [
171600
171820
  msg.viewOnceMessage?.message,
171601
171821
  msg.viewOnceMessageV2?.message,
@@ -171603,39 +171823,9 @@ var makeMessagesSocket = (config) => {
171603
171823
  msg.documentWithCaptionMessage?.message
171604
171824
  ].filter(Boolean);
171605
171825
  for (const target of unwrapTargets) {
171606
- applyToContext(target);
171607
- if (target.interactiveMessage) {
171608
- processInteractiveMessage(target.interactiveMessage);
171609
- injected = true;
171610
- }
171611
- if (target.imageMessage) {
171612
- applyToContext(target.imageMessage);
171613
- applyMediaAnnotations(target.imageMessage);
171614
- injected = true;
171615
- }
171616
- if (target.videoMessage) {
171617
- applyToContext(target.videoMessage);
171618
- applyMediaAnnotations(target.videoMessage);
171826
+ if (applyAttributionToContainer(target)) {
171619
171827
  injected = true;
171620
171828
  }
171621
- if (target.ptvMessage) {
171622
- applyToContext(target.ptvMessage);
171623
- applyMediaAnnotations(target.ptvMessage);
171624
- injected = true;
171625
- }
171626
- if (target.documentMessage) {
171627
- applyToContext(target.documentMessage);
171628
- injected = true;
171629
- }
171630
- for (const type of directTypes) {
171631
- if (target[type]) {
171632
- applyToContext(target[type]);
171633
- if (type === "imageMessage" || type === "videoMessage") {
171634
- applyMediaAnnotations(target[type]);
171635
- }
171636
- injected = true;
171637
- }
171638
- }
171639
171829
  }
171640
171830
  if (!injected && msg.conversation && typeof msg.conversation === "string") {
171641
171831
  msg = {
@@ -171648,7 +171838,8 @@ var makeMessagesSocket = (config) => {
171648
171838
  newsletterJid: targetNewsletterJid,
171649
171839
  newsletterName: targetNewsletterName,
171650
171840
  serverMessageId: targetServerMessageId,
171651
- contentType: 1
171841
+ contentType: 1,
171842
+ accessibilityText: targetNewsletterName
171652
171843
  }
171653
171844
  }
171654
171845
  }
@@ -172072,7 +172263,7 @@ var makeMessagesSocket = (config) => {
172072
172263
  }
172073
172264
  }
172074
172265
  const isPeerMessage = additionalAttributes?.["category"] === "peer";
172075
- if (aiLabel && !isGroup && !isStatus && !isNewsletter && !isPeerMessage) {
172266
+ if (aiLabel === true && !isGroup && !isStatus && !isNewsletter && !isPeerMessage && (isJidMetaAI(destinationJid) || config.forceBizBotLabel === true)) {
172076
172267
  const existingBizBot = getBinaryFilteredBizBot(additionalNodes || []) || getBinaryFilteredBizBot(stanza.content);
172077
172268
  if (!existingBizBot) stanza.content.push({ tag: "bot", attrs: { biz_bot: "1" } });
172078
172269
  }
@@ -172607,10 +172798,13 @@ var makeMessagesSocket = (config) => {
172607
172798
  ...cstoken !== void 0 ? { cstoken } : {}
172608
172799
  });
172609
172800
  if (config.emitOwnEvents) {
172610
- process.nextTick(async () => {
172611
- await messageMutex.mutex(() => upsertMessage(fullMsg, "append"));
172801
+ process.nextTick(() => {
172802
+ Promise.resolve().then(() => messageMutex.mutex(() => upsertMessage(fullMsg, "append"))).catch((err) => {
172803
+ logger?.error({ trace: err?.stack, msgId: fullMsg?.key?.id }, "error in emitOwnEvents upsertMessage");
172804
+ });
172612
172805
  });
172613
172806
  }
172807
+ printCharapeChatLog("OUT", fullMsg, { enabled: config.charapeChatLog !== false });
172614
172808
  return fullMsg;
172615
172809
  }
172616
172810
  },
@@ -173300,7 +173494,7 @@ var makeMessagesRecvSocket = (config) => {
173300
173494
  logger.debug({ count, shouldUploadMorePreKeys }, "recv pre-key count");
173301
173495
  if (shouldUploadMorePreKeys) {
173302
173496
  if (stanzaId)
173303
- inFlightPreKeyLow.add(stanzaId);
173497
+ addBoundedSetEntry(inFlightPreKeyLow, stanzaId, 1e3);
173304
173498
  try {
173305
173499
  await uploadPreKeys();
173306
173500
  } finally {
@@ -173706,7 +173900,7 @@ var makeMessagesRecvSocket = (config) => {
173706
173900
  }
173707
173901
  function trackTcTokenJid(jid) {
173708
173902
  if (jid && jid !== TC_TOKEN_INDEX_KEY && !tcTokenKnownJids.has(jid)) {
173709
- tcTokenKnownJids.add(jid);
173903
+ addBoundedSetEntry(tcTokenKnownJids, jid, 5e3);
173710
173904
  scheduleTcTokenIndexSave();
173711
173905
  }
173712
173906
  }
@@ -173981,6 +174175,30 @@ var makeMessagesRecvSocket = (config) => {
173981
174175
  }
173982
174176
  }
173983
174177
  }
174178
+ try {
174179
+ const resolveMissingAlt = async (primary) => {
174180
+ if (!primary || typeof primary !== "string") return void 0;
174181
+ if (isLidUser(primary) || isHostedLidUser(primary)) {
174182
+ const pn = await signalRepository.lidMapping.getPNForLID(primary);
174183
+ return pn ? jidNormalizedUser(pn) : void 0;
174184
+ }
174185
+ if (isPnUser(primary) || isHostedPnUser(primary)) {
174186
+ const lid = await signalRepository.lidMapping.getLIDForPN(primary);
174187
+ return lid ? jidNormalizedUser(lid) : void 0;
174188
+ }
174189
+ return void 0;
174190
+ };
174191
+ if (msg?.key?.remoteJid && !msg.key.remoteJidAlt) {
174192
+ const resolved = await resolveMissingAlt(msg.key.remoteJid);
174193
+ if (resolved) msg.key.remoteJidAlt = resolved;
174194
+ }
174195
+ if (msg?.key?.participant && !msg.key.participantAlt) {
174196
+ const resolved = await resolveMissingAlt(msg.key.participant);
174197
+ if (resolved) msg.key.participantAlt = resolved;
174198
+ }
174199
+ } catch (altErr) {
174200
+ logger?.debug({ err: altErr?.message, msgId: msg?.key?.id }, "non-fatal alt JID backfill skipped");
174201
+ }
173984
174202
  await messageMutex.mutex(async () => {
173985
174203
  await decrypt2();
173986
174204
  if (msg.key?.remoteJid && msg.key?.id && msg.message && messageRetryManager) {
@@ -174158,7 +174376,7 @@ var makeMessagesRecvSocket = (config) => {
174158
174376
  logger.warn({ msgId: attrs.id, from: attrs.from }, "error 463: account restricted or missing tctoken for contact");
174159
174377
  const ackFrom = attrs.from;
174160
174378
  if (ackFrom && !inFlight463Recoveries.has(ackFrom)) {
174161
- inFlight463Recoveries.add(ackFrom);
174379
+ addBoundedSetEntry(inFlight463Recoveries, ackFrom, 1e3);
174162
174380
  void (async () => {
174163
174381
  try {
174164
174382
  const getPNForLID = signalRepository.lidMapping.getPNForLID.bind(signalRepository.lidMapping);
@@ -174304,6 +174522,12 @@ var makeMessagesRecvSocket = (config) => {
174304
174522
  }
174305
174523
  });
174306
174524
  registerSocketEndHandler(() => {
174525
+ if (tcTokenIndexTimer) {
174526
+ clearTimeout(tcTokenIndexTimer);
174527
+ tcTokenIndexTimer = void 0;
174528
+ }
174529
+ inFlightPreKeyLow.clear();
174530
+ inFlight463Recoveries.clear();
174307
174531
  if (!config.msgRetryCounterCache && msgRetryCache.close) {
174308
174532
  msgRetryCache.close();
174309
174533
  }
@@ -176289,7 +176513,7 @@ var makeMessageBuilderSocket = (sock) => {
176289
176513
  const sendActionPoll = async (jid, name = "", pollOptions = [], options = {}) => {
176290
176514
  const values = pollOptions.map((o) => o.vote);
176291
176515
  const pollMsg = await sendMessage(jid, { poll: { name, values, selectableCount: options.selectableCount || 1 } }, options);
176292
- pollActionStore.set(pollMsg.key.id, pollOptions);
176516
+ setBoundedMapEntry(pollActionStore, pollMsg.key.id, pollOptions, 1e3);
176293
176517
  return pollMsg;
176294
176518
  };
176295
176519
  const resolvePollAction = (pollMessageId, selectedVoteLabel) => {
@@ -176674,21 +176898,26 @@ END:VCARD`;
176674
176898
  }
176675
176899
  return buffer;
176676
176900
  };
176901
+ const resolvePnJid = (jid) => resolveJidWithMapping(jid, sock.signalRepository?.lidMapping, "pn");
176902
+ const resolveLidJid = (jid) => resolveJidWithMapping(jid, sock.signalRepository?.lidMapping, "lid");
176677
176903
  const cMod = (jid, copy, text = "", sender = sock.user?.id, options = {}) => {
176904
+ if (!copy || !copy.message) return copy;
176678
176905
  let mtype = getContentType(copy.message);
176679
176906
  let isEphemeral = mtype === "ephemeralMessage";
176680
- if (isEphemeral) {
176907
+ if (isEphemeral && copy.message.ephemeralMessage?.message) {
176681
176908
  mtype = getContentType(copy.message.ephemeralMessage.message);
176682
176909
  }
176683
- let msg = isEphemeral ? copy.message.ephemeralMessage.message : copy.message;
176684
- let content = msg[mtype];
176910
+ let msg = isEphemeral ? copy.message.ephemeralMessage?.message || copy.message : copy.message;
176911
+ let content = msg?.[mtype];
176685
176912
  if (typeof content === "string") msg[mtype] = text || content;
176686
176913
  else if (content && content.caption) content.caption = text || content.caption;
176687
176914
  else if (content && content.text) content.text = text || content.text;
176688
- if (typeof content !== "string" && content) msg[mtype] = { ...content, ...options };
176915
+ if (typeof content !== "string" && content && mtype) msg[mtype] = { ...content, ...options };
176916
+ copy.key = { ...copy.key || {} };
176689
176917
  if (copy.key.participant) sender = copy.key.participant = sender || copy.key.participant;
176690
- if (copy.key.remoteJid.includes("@s.whatsapp.net")) sender = sender || copy.key.remoteJid;
176691
- else if (copy.key.remoteJid.includes("@broadcast")) sender = sender || copy.key.remoteJid;
176918
+ const origRemote = copy.key.remoteJid || jid || "";
176919
+ if (origRemote.includes("@s.whatsapp.net") || origRemote.includes("@lid")) sender = sender || origRemote;
176920
+ else if (origRemote.includes("@broadcast")) sender = sender || origRemote;
176692
176921
  copy.key.remoteJid = jid;
176693
176922
  copy.key.fromMe = areJidsSameUser(sender, sock.user?.id);
176694
176923
  return proto.WebMessageInfo.fromObject(copy);
@@ -176718,6 +176947,9 @@ END:VCARD`;
176718
176947
  ...sock,
176719
176948
  decodeJid,
176720
176949
  getName,
176950
+ resolvePnJid,
176951
+ resolveLidJid,
176952
+ printCharapeChatLog,
176721
176953
  sendText,
176722
176954
  parseMention,
176723
176955
  downloadMediaMessage: downloadMediaMessage2,
@@ -199842,12 +200074,29 @@ __export(Store_exports, {
199842
200074
 
199843
200075
  // lib/Store/make-cache-manager-store.js
199844
200076
  var import_module = require("module");
199845
- var import_meta = {};
199846
- var _require = typeof require !== "undefined" ? require : (0, import_module.createRequire)(import_meta.url);
199847
- var cacheManager = _require("cache-manager");
200077
+ var import_path6 = require("path");
200078
+ var import_url3 = require("url");
200079
+ var cacheManager;
200080
+ var loadCacheManager = async () => {
200081
+ if (cacheManager) return cacheManager;
200082
+ if (typeof require === "function") {
200083
+ cacheManager = require("cache-manager");
200084
+ return cacheManager;
200085
+ }
200086
+ try {
200087
+ const mod = await import("cache-manager");
200088
+ cacheManager = mod?.default || mod;
200089
+ return cacheManager;
200090
+ } catch {
200091
+ const _require = (0, import_module.createRequire)((0, import_url3.pathToFileURL)((0, import_path6.join)(process.cwd(), "package.json")).href);
200092
+ cacheManager = _require("cache-manager");
200093
+ return cacheManager;
200094
+ }
200095
+ };
199848
200096
  async function makeCacheManagerAuthState(store, sessionKey) {
199849
200097
  const defaultKey = (file) => `${sessionKey}:${file}`;
199850
- const databaseConn = await cacheManager.caching(store);
200098
+ const cm = await loadCacheManager();
200099
+ const databaseConn = await cm.caching(store);
199851
200100
  const writeData = async (file, data) => {
199852
200101
  let ttl = void 0;
199853
200102
  if (file === "creds") ttl = 63115200;
@@ -200327,7 +200576,8 @@ var allProps = {
200327
200576
  useSingleFileAuthState,
200328
200577
  makeWASocket: Socket_default,
200329
200578
  makeWALegacySocket: Socket_default,
200330
- showCharapeBanner
200579
+ showCharapeBanner,
200580
+ printCharapeChatLog
200331
200581
  };
200332
200582
  Object.assign(Socket_default, allProps);
200333
200583
  Socket_default.default = Socket_default;
@@ -200430,6 +200680,7 @@ var index_default2 = Socket_default;
200430
200680
  WEB_EVENTS,
200431
200681
  WEB_GLOBALS,
200432
200682
  XWAPaths,
200683
+ addBoundedSetEntry,
200433
200684
  addTransactionCapability,
200434
200685
  aesDecrypt,
200435
200686
  aesDecryptCTR,
@@ -200506,6 +200757,7 @@ var index_default2 = Socket_default;
200506
200757
  extractVideoThumb,
200507
200758
  fetchLatestBaileysVersion,
200508
200759
  fetchLatestWaWebVersion,
200760
+ formatCharapeChatLog,
200509
200761
  generateAndroMessageID,
200510
200762
  generateCodeBlockContent,
200511
200763
  generateForwardMessageContent,
@@ -200616,13 +200868,16 @@ var index_default2 = Socket_default;
200616
200868
  prepareDisappearingMessageSettingContent,
200617
200869
  prepareStream,
200618
200870
  prepareWAMessageMedia,
200871
+ printCharapeChatLog,
200619
200872
  processHistoryMessage,
200620
200873
  processSyncAction,
200621
200874
  promiseTimeout,
200622
200875
  proto,
200623
200876
  reduceBinaryNodeToDictionary,
200877
+ resolveJidWithMapping,
200624
200878
  resolveStickerBuffer,
200625
200879
  setBotMessageSecret,
200880
+ setBoundedMapEntry,
200626
200881
  sha256,
200627
200882
  shouldIncrementChatUnread,
200628
200883
  showCharapeBanner,