@lazyneoaz/metachat 6.0.1 → 6.0.2

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/dist/index.cjs CHANGED
@@ -84866,6 +84866,48 @@ function parseMentions(prng) {
84866
84866
  return [];
84867
84867
  }
84868
84868
  }
84869
+ function getMentionsFromDeltaMessage(m) {
84870
+ const body = m?.body || "";
84871
+ const mentions = {};
84872
+ const prngCandidates = [m?.data?.prng, m?.messageMetadata?.data?.prng];
84873
+ for (const prng of prngCandidates) {
84874
+ const mdata = parseMentions(prng);
84875
+ if (mdata.length > 0) {
84876
+ for (const row of mdata) {
84877
+ const o = parseInt(String(row?.o ?? ""), 10) || 0;
84878
+ const l = parseInt(String(row?.l ?? ""), 10) || 0;
84879
+ mentions[String(row?.i)] = body.substring(o, o + l);
84880
+ }
84881
+ return mentions;
84882
+ }
84883
+ }
84884
+ const collectFromRangeMap = (rangeMap) => {
84885
+ const mapData = rangeMap?.asMap?.data;
84886
+ if (!mapData || typeof mapData !== "object") return;
84887
+ for (const key of Object.keys(mapData)) {
84888
+ const d = mapData[key]?.asMap?.data;
84889
+ if (!d) continue;
84890
+ const rawId = d.id?.asLong != null ? d.id.asLong : d.id;
84891
+ if (rawId == null) continue;
84892
+ const offset = parseInt(String(d.offset?.asLong ?? d.offset ?? 0), 10) || 0;
84893
+ const length = parseInt(String(d.length?.asLong ?? d.length ?? 0), 10) || 0;
84894
+ mentions[String(rawId)] = body.substring(offset, offset + length);
84895
+ }
84896
+ };
84897
+ for (const root2 of [m?.data?.data, m?.messageMetadata?.data?.data]) {
84898
+ if (!root2 || typeof root2 !== "object") continue;
84899
+ collectFromRangeMap(root2.Gb);
84900
+ if (Object.keys(mentions).length > 0) break;
84901
+ for (const key of Object.keys(root2)) {
84902
+ const candidate = root2[key];
84903
+ if (candidate && candidate.asMap && candidate.asMap.data) {
84904
+ collectFromRangeMap(candidate);
84905
+ }
84906
+ }
84907
+ if (Object.keys(mentions).length > 0) break;
84908
+ }
84909
+ return mentions;
84910
+ }
84869
84911
  function getAdminTextMessageType(type) {
84870
84912
  switch (type) {
84871
84913
  case "unpin_messages_v2":
@@ -84894,12 +84936,12 @@ function getAdminTextMessageType(type) {
84894
84936
  }
84895
84937
  function formatDeltaMessage(m) {
84896
84938
  const md = m.delta.messageMetadata || {};
84897
- const mdata = parseMentions(m.delta.data?.prng);
84898
84939
  const body = m.delta.body || "";
84899
- const mentions = {};
84900
- for (const mention of mdata) {
84901
- mentions[mention.i] = body.substring(mention.o, mention.o + mention.l);
84902
- }
84940
+ const mentions = getMentionsFromDeltaMessage({
84941
+ body,
84942
+ data: m.delta.data,
84943
+ messageMetadata: md
84944
+ });
84903
84945
  const messageReply = m.delta.messageReply ? {
84904
84946
  messageID: m.delta.messageReply.messageID,
84905
84947
  senderID: formatID(m.delta.messageReply.senderID),
@@ -84935,11 +84977,11 @@ function formatDeltaNewMessage(m) {
84935
84977
  const threadID = formatID((threadKey.threadFbId || threadKey.otherUserFbId || "").toString());
84936
84978
  const senderID = md.actorFbId ? formatID(md.actorFbId.toString()) : "";
84937
84979
  const body = m.body || "";
84938
- const mdata = parseMentions(m.data?.prng);
84939
- const mentions = {};
84940
- for (const mention of mdata) {
84941
- mentions[mention.i] = body.substring(mention.o, mention.o + mention.l);
84942
- }
84980
+ const mentions = getMentionsFromDeltaMessage({
84981
+ body,
84982
+ data: m.data,
84983
+ messageMetadata: md
84984
+ });
84943
84985
  const rawAttachments = Array.isArray(m.attachments) ? m.attachments : [];
84944
84986
  const attachments = rawAttachments.map((att) => {
84945
84987
  try {
package/dist/index.mjs CHANGED
@@ -84834,6 +84834,48 @@ function parseMentions(prng) {
84834
84834
  return [];
84835
84835
  }
84836
84836
  }
84837
+ function getMentionsFromDeltaMessage(m) {
84838
+ const body = m?.body || "";
84839
+ const mentions = {};
84840
+ const prngCandidates = [m?.data?.prng, m?.messageMetadata?.data?.prng];
84841
+ for (const prng of prngCandidates) {
84842
+ const mdata = parseMentions(prng);
84843
+ if (mdata.length > 0) {
84844
+ for (const row of mdata) {
84845
+ const o = parseInt(String(row?.o ?? ""), 10) || 0;
84846
+ const l = parseInt(String(row?.l ?? ""), 10) || 0;
84847
+ mentions[String(row?.i)] = body.substring(o, o + l);
84848
+ }
84849
+ return mentions;
84850
+ }
84851
+ }
84852
+ const collectFromRangeMap = (rangeMap) => {
84853
+ const mapData = rangeMap?.asMap?.data;
84854
+ if (!mapData || typeof mapData !== "object") return;
84855
+ for (const key of Object.keys(mapData)) {
84856
+ const d = mapData[key]?.asMap?.data;
84857
+ if (!d) continue;
84858
+ const rawId = d.id?.asLong != null ? d.id.asLong : d.id;
84859
+ if (rawId == null) continue;
84860
+ const offset = parseInt(String(d.offset?.asLong ?? d.offset ?? 0), 10) || 0;
84861
+ const length = parseInt(String(d.length?.asLong ?? d.length ?? 0), 10) || 0;
84862
+ mentions[String(rawId)] = body.substring(offset, offset + length);
84863
+ }
84864
+ };
84865
+ for (const root2 of [m?.data?.data, m?.messageMetadata?.data?.data]) {
84866
+ if (!root2 || typeof root2 !== "object") continue;
84867
+ collectFromRangeMap(root2.Gb);
84868
+ if (Object.keys(mentions).length > 0) break;
84869
+ for (const key of Object.keys(root2)) {
84870
+ const candidate = root2[key];
84871
+ if (candidate && candidate.asMap && candidate.asMap.data) {
84872
+ collectFromRangeMap(candidate);
84873
+ }
84874
+ }
84875
+ if (Object.keys(mentions).length > 0) break;
84876
+ }
84877
+ return mentions;
84878
+ }
84837
84879
  function getAdminTextMessageType(type) {
84838
84880
  switch (type) {
84839
84881
  case "unpin_messages_v2":
@@ -84862,12 +84904,12 @@ function getAdminTextMessageType(type) {
84862
84904
  }
84863
84905
  function formatDeltaMessage(m) {
84864
84906
  const md = m.delta.messageMetadata || {};
84865
- const mdata = parseMentions(m.delta.data?.prng);
84866
84907
  const body = m.delta.body || "";
84867
- const mentions = {};
84868
- for (const mention of mdata) {
84869
- mentions[mention.i] = body.substring(mention.o, mention.o + mention.l);
84870
- }
84908
+ const mentions = getMentionsFromDeltaMessage({
84909
+ body,
84910
+ data: m.delta.data,
84911
+ messageMetadata: md
84912
+ });
84871
84913
  const messageReply = m.delta.messageReply ? {
84872
84914
  messageID: m.delta.messageReply.messageID,
84873
84915
  senderID: formatID(m.delta.messageReply.senderID),
@@ -84903,11 +84945,11 @@ function formatDeltaNewMessage(m) {
84903
84945
  const threadID = formatID((threadKey.threadFbId || threadKey.otherUserFbId || "").toString());
84904
84946
  const senderID = md.actorFbId ? formatID(md.actorFbId.toString()) : "";
84905
84947
  const body = m.body || "";
84906
- const mdata = parseMentions(m.data?.prng);
84907
- const mentions = {};
84908
- for (const mention of mdata) {
84909
- mentions[mention.i] = body.substring(mention.o, mention.o + mention.l);
84910
- }
84948
+ const mentions = getMentionsFromDeltaMessage({
84949
+ body,
84950
+ data: m.data,
84951
+ messageMetadata: md
84952
+ });
84911
84953
  const rawAttachments = Array.isArray(m.attachments) ? m.attachments : [];
84912
84954
  const attachments = rawAttachments.map((att) => {
84913
84955
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lazyneoaz/metachat",
3
- "version": "6.0.1",
3
+ "version": "6.0.2",
4
4
  "description": "A modern TypeScript Facebook Chat API client for building reliable Messenger bots, with built-in anti-detection protection, automatic cookie refresh, music search, and AI theme support.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -57,7 +57,7 @@
57
57
  "prepublishOnly": "npm run build",
58
58
  "lint": "npm run typecheck",
59
59
  "format": "prettier --write \"src/**/*.ts\" \"index.ts\"",
60
- "test": "npm run build && node test/smoke.test.cjs && node test/smoke.test.mjs && node test/music-search.test.cjs && node test/mqtt-lifecycle.test.cjs && node test/session-reliability.test.cjs && node test/anti-detection.test.cjs && node test/account-safety.test.cjs && node test/liveness.test.cjs && node test/recovery.test.cjs && node test/cookie-acquisition.test.cjs && node test/realtime-health.test.cjs && node test/attachment-resilience.test.cjs && node test/reaction-validation.test.cjs && node test/api-surface-fixes.test.cjs && node test/threadinfo-regression.test.cjs && node test/new-modules.test.cjs",
60
+ "test": "npm run build && node test/smoke.test.cjs && node test/smoke.test.mjs && node test/music-search.test.cjs && node test/mqtt-lifecycle.test.cjs && node test/session-reliability.test.cjs && node test/anti-detection.test.cjs && node test/account-safety.test.cjs && node test/liveness.test.cjs && node test/recovery.test.cjs && node test/cookie-acquisition.test.cjs && node test/realtime-health.test.cjs && node test/attachment-resilience.test.cjs && node test/reaction-validation.test.cjs && node test/api-surface-fixes.test.cjs && node test/threadinfo-regression.test.cjs && node test/new-modules.test.cjs && node test/mention-parsing.test.cjs",
61
61
  "audit": "npm audit",
62
62
  "audit:fix": "npm audit fix"
63
63
  },