@queenanya/baileys 8.2.7 → 8.3.1

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.
Files changed (78) hide show
  1. package/WAProto/index.d.ts +1590 -6
  2. package/WAProto/index.js +4635 -3
  3. package/engine-requirements.js +1 -1
  4. package/lib/Defaults/baileys-version.json +1 -1
  5. package/lib/Defaults/index.d.ts +232 -1
  6. package/lib/Defaults/index.js +21 -6
  7. package/lib/Defaults/phonenumber-mcc.json +223 -0
  8. package/lib/Socket/Client/index.d.ts +3 -2
  9. package/lib/Socket/Client/index.js +3 -2
  10. package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
  11. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  12. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
  13. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +3 -3
  14. package/lib/Socket/business.d.ts +4 -9
  15. package/lib/Socket/chats.d.ts +3 -9
  16. package/lib/Socket/chats.js +6 -89
  17. package/lib/Socket/groups.d.ts +3 -7
  18. package/lib/Socket/groups.js +13 -9
  19. package/lib/Socket/index.d.ts +6 -9
  20. package/lib/Socket/index.js +2 -2
  21. package/lib/Socket/messages-recv.d.ts +4 -9
  22. package/lib/Socket/messages-recv.js +14 -27
  23. package/lib/Socket/messages-send.d.ts +3 -8
  24. package/lib/Socket/messages-send.js +55 -86
  25. package/lib/Socket/newsletter.d.ts +3 -7
  26. package/lib/Socket/newsletter.js +2 -4
  27. package/lib/Socket/registration.d.ts +266 -0
  28. package/lib/Socket/registration.js +166 -0
  29. package/lib/Socket/socket.d.ts +1 -2
  30. package/lib/Socket/socket.js +15 -10
  31. package/lib/Socket/usync.d.ts +1 -1
  32. package/lib/Socket/usync.js +15 -10
  33. package/lib/Store/make-in-memory-store.js +10 -8
  34. package/lib/Types/Auth.d.ts +6 -0
  35. package/lib/Types/Chat.d.ts +2 -8
  36. package/lib/Types/Contact.d.ts +4 -5
  37. package/lib/Types/GroupMetadata.d.ts +4 -3
  38. package/lib/Types/Label.d.ts +0 -11
  39. package/lib/Types/Message.d.ts +5 -5
  40. package/lib/Types/Socket.d.ts +3 -5
  41. package/lib/Utils/auth-utils.js +7 -0
  42. package/lib/Utils/chat-utils.d.ts +8 -8
  43. package/lib/Utils/chat-utils.js +4 -30
  44. package/lib/Utils/crypto.d.ts +1 -1
  45. package/lib/Utils/crypto.js +1 -3
  46. package/lib/Utils/decode-wa-message.d.ts +2 -4
  47. package/lib/Utils/decode-wa-message.js +18 -161
  48. package/lib/Utils/event-buffer.js +6 -4
  49. package/lib/Utils/generics.d.ts +18 -8
  50. package/lib/Utils/generics.js +93 -7
  51. package/lib/Utils/history.js +1 -1
  52. package/lib/Utils/messages-media.d.ts +9 -16
  53. package/lib/Utils/messages-media.js +175 -88
  54. package/lib/Utils/messages.d.ts +1 -1
  55. package/lib/Utils/messages.js +17 -15
  56. package/lib/Utils/noise-handler.d.ts +2 -1
  57. package/lib/Utils/noise-handler.js +10 -5
  58. package/lib/Utils/validate-connection.d.ts +1 -0
  59. package/lib/Utils/validate-connection.js +50 -16
  60. package/lib/WABinary/constants.d.ts +4 -4
  61. package/lib/WABinary/constants.js +1271 -8
  62. package/lib/WABinary/encode.js +5 -7
  63. package/lib/WABinary/jid-utils.d.ts +4 -4
  64. package/lib/WABinary/jid-utils.js +19 -19
  65. package/lib/WAM/constants.d.ts +2 -3
  66. package/lib/WAM/encode.js +2 -2
  67. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  68. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
  69. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +3 -3
  70. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  71. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
  72. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -1
  73. package/lib/WAUSync/USyncQuery.js +13 -17
  74. package/package.json +9 -5
  75. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  76. package/lib/Store/make-cache-manager-store.js +0 -83
  77. /package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +0 -0
  78. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -50,11 +50,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
50
50
  buffer.push((value >> (curShift * 8)) & 0xff);
51
51
  }
52
52
  };
53
- const pushBytes = (bytes) => {
54
- for (const b of bytes) {
55
- buffer.push(b);
56
- }
57
- };
53
+ const pushBytes = (bytes) => (bytes.forEach(b => buffer.push(b)));
58
54
  const pushInt16 = (value) => {
59
55
  pushBytes([(value >> 8) & 0xff, value & 0xff]);
60
56
  };
@@ -156,7 +152,8 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
156
152
  if (!str || str.length > TAGS.PACKED_MAX) {
157
153
  return false;
158
154
  }
159
- for (const char of str) {
155
+ for (let i = 0; i < str.length; i++) {
156
+ const char = str[i];
160
157
  const isInNibbleRange = char >= '0' && char <= '9';
161
158
  if (!isInNibbleRange && char !== '-' && char !== '.') {
162
159
  return false;
@@ -168,7 +165,8 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
168
165
  if (!str || str.length > TAGS.PACKED_MAX) {
169
166
  return false;
170
167
  }
171
- for (const char of str) {
168
+ for (let i = 0; i < str.length; i++) {
169
+ const char = str[i];
172
170
  const isInNibbleRange = char >= '0' && char <= '9';
173
171
  if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
174
172
  return false;
@@ -10,16 +10,15 @@ export type JidWithDevice = {
10
10
  device?: number;
11
11
  };
12
12
  export type FullJid = JidWithDevice & {
13
- server: JidServer;
13
+ server: JidServer | string;
14
14
  domainType?: number;
15
15
  };
16
- export declare const getBotJid: (jid: string) => string;
17
16
  export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number, agent?: number) => string;
18
17
  export declare const jidDecode: (jid: string | undefined) => FullJid | undefined;
19
18
  /** is the jid a user */
20
19
  export declare const areJidsSameUser: (jid1: string | undefined, jid2: string | undefined) => boolean;
21
- /** is the jid Meta AI */
22
- export declare const isJidMetaAI: (jid: string | undefined) => boolean | undefined;
20
+ /** is the jid Meta IA */
21
+ export declare const isJidMetaAi: (jid: string | undefined) => boolean | undefined;
23
22
  /** is the jid a user */
24
23
  export declare const isJidUser: (jid: string | undefined) => boolean | undefined;
25
24
  /** is the jid a group */
@@ -34,3 +33,4 @@ export declare const isJidGroup: (jid: string | undefined) => boolean | undefine
34
33
  export declare const isJidStatusBroadcast: (jid: string) => jid is "status@broadcast";
35
34
  export declare const isJidBot: (jid: string | undefined) => boolean | "" | undefined;
36
35
  export declare const jidNormalizedUser: (jid: string | undefined) => string;
36
+ export declare const getBotJid: (jid: string) => string;
@@ -1,26 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jidNormalizedUser = exports.isJidBot = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidNewsletter = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.isJidMetaAI = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.getBotJid = exports.META_AI_JID = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
3
+ exports.getBotJid = exports.jidNormalizedUser = exports.isJidBot = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidNewsletter = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.isJidMetaAi = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.META_AI_JID = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
4
4
  exports.S_WHATSAPP_NET = '@s.whatsapp.net';
5
5
  exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
6
6
  exports.SERVER_JID = 'server@c.us';
7
7
  exports.PSA_WID = '0@c.us';
8
8
  exports.STORIES_JID = 'status@broadcast';
9
9
  exports.META_AI_JID = '13135550002@c.us';
10
- const getBotJid = (jid) => {
11
- const BOT_MAP = new Map([["867051314767696", "13135550002"], ["1061492271844689", "13135550005"], ["245886058483988", "13135550009"], ["3509905702656130", "13135550012"], ["1059680132034576", "13135550013"], ["715681030623646", "13135550014"], ["1644971366323052", "13135550015"], ["582497970646566", "13135550019"], ["645459357769306", "13135550022"], ["294997126699143", "13135550023"], ["1522631578502677", "13135550027"], ["719421926276396", "13135550030"], ["1788488635002167", "13135550031"], ["24232338603080193", "13135550033"], ["689289903143209", "13135550035"], ["871626054177096", "13135550039"], ["362351902849370", "13135550042"], ["1744617646041527", "13135550043"], ["893887762270570", "13135550046"], ["1155032702135830", "13135550047"], ["333931965993883", "13135550048"], ["853748013058752", "13135550049"], ["1559068611564819", "13135550053"], ["890487432705716", "13135550054"], ["240254602395494", "13135550055"], ["1578420349663261", "13135550062"], ["322908887140421", "13135550065"], ["3713961535514771", "13135550067"], ["997884654811738", "13135550070"], ["403157239387035", "13135550081"], ["535242369074963", "13135550082"], ["946293427247659", "13135550083"], ["3664707673802291", "13135550084"], ["1821827464894892", "13135550085"], ["1760312477828757", "13135550086"], ["439480398712216", "13135550087"], ["1876735582800984", "13135550088"], ["984025089825661", "13135550089"], ["1001336351558186", "13135550090"], ["3739346336347061", "13135550091"], ["3632749426974980", "13135550092"], ["427864203481615", "13135550093"], ["1434734570493055", "13135550094"], ["992873449225921", "13135550095"], ["813087747426445", "13135550096"], ["806369104931434", "13135550098"], ["1220982902403148", "13135550099"], ["1365893374104393", "13135550100"], ["686482033622048", "13135550200"], ["1454999838411253", "13135550201"], ["718584497008509", "13135550202"], ["743520384213443", "13135550301"], ["1147715789823789", "13135550302"], ["1173034540372201", "13135550303"], ["974785541030953", "13135550304"], ["1122200255531507", "13135550305"], ["899669714813162", "13135550306"], ["631880108970650", "13135550307"], ["435816149330026", "13135550308"], ["1368717161184556", "13135550309"], ["7849963461784891", "13135550310"], ["3609617065968984", "13135550312"], ["356273980574602", "13135550313"], ["1043447920539760", "13135550314"], ["1052764336525346", "13135550315"], ["2631118843732685", "13135550316"], ["510505411332176", "13135550317"], ["1945664239227513", "13135550318"], ["1518594378764656", "13135550319"], ["1378821579456138", "13135550320"], ["490214716896013", "13135550321"], ["1028577858870699", "13135550322"], ["308915665545959", "13135550323"], ["845884253678900", "13135550324"], ["995031308616442", "13135550325"], ["2787365464763437", "13135550326"], ["1532790990671645", "13135550327"], ["302617036180485", "13135550328"], ["723376723197227", "13135550329"], ["8393570407377966", "13135550330"], ["1931159970680725", "13135550331"], ["401073885688605", "13135550332"], ["2234478453565422", "13135550334"], ["814748673882312", "13135550335"], ["26133635056281592", "13135550336"], ["1439804456676119", "13135550337"], ["889851503172161", "13135550338"], ["1018283232836879", "13135550339"], ["1012781386779537", "13135559000"], ["823280953239532", "13135559001"], ["1597090934573334", "13135559002"], ["485965054020343", "13135559003"], ["1033381648363446", "13135559004"], ["491802010206446", "13135559005"], ["1017139033184870", "13135559006"], ["499638325922174", "13135559008"], ["468946335863664", "13135559009"], ["1570389776875816", "13135559010"], ["1004342694328995", "13135559011"], ["1012240323971229", "13135559012"], ["392171787222419", "13135559013"], ["952081212945019", "13135559016"], ["444507875070178", "13135559017"], ["1274819440594668", "13135559018"], ["1397041101147050", "13135559019"], ["425657699872640", "13135559020"], ["532292852562549", "13135559021"], ["705863241720292", "13135559022"], ["476449815183959", "13135559023"], ["488071553854222", "13135559024"], ["468693832665397", "13135559025"], ["517422564037340", "13135559026"], ["819805466613825", "13135559027"], ["1847708235641382", "13135559028"], ["716282970644228", "13135559029"], ["521655380527741", "13135559030"], ["476193631941905", "13135559031"], ["485600497445562", "13135559032"], ["440217235683910", "13135559033"], ["523342446758478", "13135559034"], ["514784864360240", "13135559035"], ["505790121814530", "13135559036"], ["420008964419580", "13135559037"], ["492141680204555", "13135559038"], ["388462787271952", "13135559039"], ["423473920752072", "13135559040"], ["489574180468229", "13135559041"], ["432360635854105", "13135559042"], ["477878201669248", "13135559043"], ["351656951234045", "13135559044"], ["430178036732582", "13135559045"], ["434537312944552", "13135559046"], ["1240614300631808", "13135559047"], ["473135945605128", "13135559048"], ["423669800729310", "13135559049"], ["3685666705015792", "13135559050"], ["504196509016638", "13135559051"], ["346844785189449", "13135559052"], ["504823088911074", "13135559053"], ["402669415797083", "13135559054"], ["490939640234431", "13135559055"], ["875124128063715", "13135559056"], ["468788962654605", "13135559057"], ["562386196354570", "13135559058"], ["372159285928791", "13135559059"], ["531017479591050", "13135559060"], ["1328873881401826", "13135559061"], ["1608363646390484", "13135559062"], ["1229628561554232", "13135559063"], ["348802211530364", "13135559064"], ["3708535859420184", "13135559065"], ["415517767742187", "13135559066"], ["479330341612638", "13135559067"], ["480785414723083", "13135559068"], ["387299107507991", "13135559069"], ["333389813188944", "13135559070"], ["391794130316996", "13135559071"], ["457893470576314", "13135559072"], ["435550496166469", "13135559073"], ["1620162702100689", "13135559074"], ["867491058616043", "13135559075"], ["816224117357759", "13135559076"], ["334065176362830", "13135559077"], ["489973170554709", "13135559078"], ["473060669049665", "13135559079"], ["1221505815643060", "13135559080"], ["889000703096359", "13135559081"], ["475235961979883", "13135559082"], ["3434445653519934", "13135559084"], ["524503026827421", "13135559085"], ["1179639046403856", "13135559086"], ["471563305859144", "13135559087"], ["533896609192881", "13135559088"], ["365443583168041", "13135559089"], ["836082305329393", "13135559090"], ["1056787705969916", "13135559091"], ["503312598958357", "13135559092"], ["3718606738453460", "13135559093"], ["826066052850902", "13135559094"], ["1033611345091888", "13135559095"], ["3868390816783240", "13135559096"], ["7462677740498860", "13135559097"], ["436288576108573", "13135559098"], ["1047559746718900", "13135559099"], ["1099299455255491", "13135559100"], ["1202037301040633", "13135559101"], ["1720619402074074", "13135559102"], ["1030422235101467", "13135559103"], ["827238979523502", "13135559104"], ["1516443722284921", "13135559105"], ["1174442747196709", "13135559106"], ["1653165225503842", "13135559107"], ["1037648777635013", "13135559108"], ["551617757299900", "13135559109"], ["1158813558718726", "13135559110"], ["2463236450542262", "13135559111"], ["1550393252501466", "13135559112"], ["2057065188042796", "13135559113"], ["506163028760735", "13135559114"], ["2065249100538481", "13135559115"], ["1041382867195858", "13135559116"], ["886500209499603", "13135559117"], ["1491615624892655", "13135559118"], ["486563697299617", "13135559119"], ["1175736513679463", "13135559120"], ["491811473512352", "13165550064"]]);
12
- const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
13
- if (sepIdx < 0) {
14
- return jid;
15
- }
16
- const server = jid.slice(sepIdx + 1);
17
- if (server !== 'bot')
18
- return jid;
19
- const user = jid.slice(0, sepIdx);
20
- const mappedNumber = BOT_MAP.get(user);
21
- return mappedNumber ? `${mappedNumber}@s.whatsapp.net` : jid;
22
- };
23
- exports.getBotJid = getBotJid;
24
10
  const jidEncode = (user, server, device, agent) => {
25
11
  return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;
26
12
  };
@@ -35,7 +21,7 @@ const jidDecode = (jid) => {
35
21
  const [userAgent, device] = userCombined.split(':');
36
22
  const user = userAgent.split('_')[0];
37
23
  return {
38
- server: server,
24
+ server,
39
25
  user,
40
26
  domainType: server === 'lid' ? 1 : 0,
41
27
  device: device ? +device : undefined
@@ -48,9 +34,9 @@ const areJidsSameUser = (jid1, jid2) => {
48
34
  return (((_a = (0, exports.jidDecode)(jid1)) === null || _a === void 0 ? void 0 : _a.user) === ((_b = (0, exports.jidDecode)(jid2)) === null || _b === void 0 ? void 0 : _b.user));
49
35
  };
50
36
  exports.areJidsSameUser = areJidsSameUser;
51
- /** is the jid Meta AI */
52
- const isJidMetaAI = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@bot'));
53
- exports.isJidMetaAI = isJidMetaAI;
37
+ /** is the jid Meta IA */
38
+ const isJidMetaAi = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@bot'));
39
+ exports.isJidMetaAi = isJidMetaAi;
54
40
  /** is the jid a user */
55
41
  const isJidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@s.whatsapp.net'));
56
42
  exports.isJidUser = isJidUser;
@@ -81,3 +67,17 @@ const jidNormalizedUser = (jid) => {
81
67
  return (0, exports.jidEncode)(user, server === 'c.us' ? 's.whatsapp.net' : server);
82
68
  };
83
69
  exports.jidNormalizedUser = jidNormalizedUser;
70
+ const getBotJid = (jid) => {
71
+ const BOT_MAP = new Map([["867051314767696", "13135550002"], ["1061492271844689", "13135550005"], ["245886058483988", "13135550009"], ["3509905702656130", "13135550012"], ["1059680132034576", "13135550013"], ["715681030623646", "13135550014"], ["1644971366323052", "13135550015"], ["582497970646566", "13135550019"], ["645459357769306", "13135550022"], ["294997126699143", "13135550023"], ["1522631578502677", "13135550027"], ["719421926276396", "13135550030"], ["1788488635002167", "13135550031"], ["24232338603080193", "13135550033"], ["689289903143209", "13135550035"], ["871626054177096", "13135550039"], ["362351902849370", "13135550042"], ["1744617646041527", "13135550043"], ["893887762270570", "13135550046"], ["1155032702135830", "13135550047"], ["333931965993883", "13135550048"], ["853748013058752", "13135550049"], ["1559068611564819", "13135550053"], ["890487432705716", "13135550054"], ["240254602395494", "13135550055"], ["1578420349663261", "13135550062"], ["322908887140421", "13135550065"], ["3713961535514771", "13135550067"], ["997884654811738", "13135550070"], ["403157239387035", "13135550081"], ["535242369074963", "13135550082"], ["946293427247659", "13135550083"], ["3664707673802291", "13135550084"], ["1821827464894892", "13135550085"], ["1760312477828757", "13135550086"], ["439480398712216", "13135550087"], ["1876735582800984", "13135550088"], ["984025089825661", "13135550089"], ["1001336351558186", "13135550090"], ["3739346336347061", "13135550091"], ["3632749426974980", "13135550092"], ["427864203481615", "13135550093"], ["1434734570493055", "13135550094"], ["992873449225921", "13135550095"], ["813087747426445", "13135550096"], ["806369104931434", "13135550098"], ["1220982902403148", "13135550099"], ["1365893374104393", "13135550100"], ["686482033622048", "13135550200"], ["1454999838411253", "13135550201"], ["718584497008509", "13135550202"], ["743520384213443", "13135550301"], ["1147715789823789", "13135550302"], ["1173034540372201", "13135550303"], ["974785541030953", "13135550304"], ["1122200255531507", "13135550305"], ["899669714813162", "13135550306"], ["631880108970650", "13135550307"], ["435816149330026", "13135550308"], ["1368717161184556", "13135550309"], ["7849963461784891", "13135550310"], ["3609617065968984", "13135550312"], ["356273980574602", "13135550313"], ["1043447920539760", "13135550314"], ["1052764336525346", "13135550315"], ["2631118843732685", "13135550316"], ["510505411332176", "13135550317"], ["1945664239227513", "13135550318"], ["1518594378764656", "13135550319"], ["1378821579456138", "13135550320"], ["490214716896013", "13135550321"], ["1028577858870699", "13135550322"], ["308915665545959", "13135550323"], ["845884253678900", "13135550324"], ["995031308616442", "13135550325"], ["2787365464763437", "13135550326"], ["1532790990671645", "13135550327"], ["302617036180485", "13135550328"], ["723376723197227", "13135550329"], ["8393570407377966", "13135550330"], ["1931159970680725", "13135550331"], ["401073885688605", "13135550332"], ["2234478453565422", "13135550334"], ["814748673882312", "13135550335"], ["26133635056281592", "13135550336"], ["1439804456676119", "13135550337"], ["889851503172161", "13135550338"], ["1018283232836879", "13135550339"], ["1012781386779537", "13135559000"], ["823280953239532", "13135559001"], ["1597090934573334", "13135559002"], ["485965054020343", "13135559003"], ["1033381648363446", "13135559004"], ["491802010206446", "13135559005"], ["1017139033184870", "13135559006"], ["499638325922174", "13135559008"], ["468946335863664", "13135559009"], ["1570389776875816", "13135559010"], ["1004342694328995", "13135559011"], ["1012240323971229", "13135559012"], ["392171787222419", "13135559013"], ["952081212945019", "13135559016"], ["444507875070178", "13135559017"], ["1274819440594668", "13135559018"], ["1397041101147050", "13135559019"], ["425657699872640", "13135559020"], ["532292852562549", "13135559021"], ["705863241720292", "13135559022"], ["476449815183959", "13135559023"], ["488071553854222", "13135559024"], ["468693832665397", "13135559025"], ["517422564037340", "13135559026"], ["819805466613825", "13135559027"], ["1847708235641382", "13135559028"], ["716282970644228", "13135559029"], ["521655380527741", "13135559030"], ["476193631941905", "13135559031"], ["485600497445562", "13135559032"], ["440217235683910", "13135559033"], ["523342446758478", "13135559034"], ["514784864360240", "13135559035"], ["505790121814530", "13135559036"], ["420008964419580", "13135559037"], ["492141680204555", "13135559038"], ["388462787271952", "13135559039"], ["423473920752072", "13135559040"], ["489574180468229", "13135559041"], ["432360635854105", "13135559042"], ["477878201669248", "13135559043"], ["351656951234045", "13135559044"], ["430178036732582", "13135559045"], ["434537312944552", "13135559046"], ["1240614300631808", "13135559047"], ["473135945605128", "13135559048"], ["423669800729310", "13135559049"], ["3685666705015792", "13135559050"], ["504196509016638", "13135559051"], ["346844785189449", "13135559052"], ["504823088911074", "13135559053"], ["402669415797083", "13135559054"], ["490939640234431", "13135559055"], ["875124128063715", "13135559056"], ["468788962654605", "13135559057"], ["562386196354570", "13135559058"], ["372159285928791", "13135559059"], ["531017479591050", "13135559060"], ["1328873881401826", "13135559061"], ["1608363646390484", "13135559062"], ["1229628561554232", "13135559063"], ["348802211530364", "13135559064"], ["3708535859420184", "13135559065"], ["415517767742187", "13135559066"], ["479330341612638", "13135559067"], ["480785414723083", "13135559068"], ["387299107507991", "13135559069"], ["333389813188944", "13135559070"], ["391794130316996", "13135559071"], ["457893470576314", "13135559072"], ["435550496166469", "13135559073"], ["1620162702100689", "13135559074"], ["867491058616043", "13135559075"], ["816224117357759", "13135559076"], ["334065176362830", "13135559077"], ["489973170554709", "13135559078"], ["473060669049665", "13135559079"], ["1221505815643060", "13135559080"], ["889000703096359", "13135559081"], ["475235961979883", "13135559082"], ["3434445653519934", "13135559084"], ["524503026827421", "13135559085"], ["1179639046403856", "13135559086"], ["471563305859144", "13135559087"], ["533896609192881", "13135559088"], ["365443583168041", "13135559089"], ["836082305329393", "13135559090"], ["1056787705969916", "13135559091"], ["503312598958357", "13135559092"], ["3718606738453460", "13135559093"], ["826066052850902", "13135559094"], ["1033611345091888", "13135559095"], ["3868390816783240", "13135559096"], ["7462677740498860", "13135559097"], ["436288576108573", "13135559098"], ["1047559746718900", "13135559099"], ["1099299455255491", "13135559100"], ["1202037301040633", "13135559101"], ["1720619402074074", "13135559102"], ["1030422235101467", "13135559103"], ["827238979523502", "13135559104"], ["1516443722284921", "13135559105"], ["1174442747196709", "13135559106"], ["1653165225503842", "13135559107"], ["1037648777635013", "13135559108"], ["551617757299900", "13135559109"], ["1158813558718726", "13135559110"], ["2463236450542262", "13135559111"], ["1550393252501466", "13135559112"], ["2057065188042796", "13135559113"], ["506163028760735", "13135559114"], ["2065249100538481", "13135559115"], ["1041382867195858", "13135559116"], ["886500209499603", "13135559117"], ["1491615624892655", "13135559118"], ["486563697299617", "13135559119"], ["1175736513679463", "13135559120"], ["491811473512352", "13165550064"]]);
72
+ const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
73
+ if (sepIdx < 0) {
74
+ return jid;
75
+ }
76
+ const server = jid.slice(sepIdx + 1);
77
+ if (server !== 'bot')
78
+ return jid;
79
+ const user = jid.slice(0, sepIdx);
80
+ const mappedNumber = BOT_MAP.get(user);
81
+ return mappedNumber ? `${mappedNumber}@s.whatsapp.net` : jid;
82
+ };
83
+ exports.getBotJid = getBotJid;
@@ -28,12 +28,11 @@ type EventByName<T extends Event['name']> = Extract<Event, {
28
28
  export type EventInputType = {
29
29
  [key in Event['name']]: {
30
30
  props: {
31
- [k in keyof EventByName<key>['props']]: Value;
31
+ [k in keyof EventByName<key>['props']]: any;
32
32
  };
33
33
  globals: {
34
- [x: string]: Value;
34
+ [x: string]: any;
35
35
  };
36
36
  };
37
37
  } & {};
38
- export type Value = number | null | string;
39
38
  export {};
package/lib/WAM/encode.js CHANGED
@@ -13,10 +13,10 @@ const encodeWAM = (binaryInfo) => {
13
13
  .reduce((a, b) => a + b);
14
14
  const buffer = Buffer.alloc(totalSize);
15
15
  let offset = 0;
16
- for (const buffer_ of binaryInfo.buffer) {
16
+ binaryInfo.buffer.forEach((buffer_) => {
17
17
  buffer_.copy(buffer, offset);
18
18
  offset += buffer_.length;
19
- }
19
+ });
20
20
  return buffer;
21
21
  };
22
22
  exports.encodeWAM = encodeWAM;
@@ -9,7 +9,7 @@ class USyncContactProtocol {
9
9
  getQueryElement() {
10
10
  return {
11
11
  tag: 'contact',
12
- attrs: {}
12
+ attrs: {},
13
13
  };
14
14
  }
15
15
  getUserElement(user) {
@@ -17,7 +17,7 @@ class USyncContactProtocol {
17
17
  return {
18
18
  tag: 'contact',
19
19
  attrs: {},
20
- content: user.phone
20
+ content: user.phone,
21
21
  };
22
22
  }
23
23
  parser(node) {
@@ -10,8 +10,8 @@ class USyncDeviceProtocol {
10
10
  return {
11
11
  tag: 'devices',
12
12
  attrs: {
13
- version: '2'
14
- }
13
+ version: '2',
14
+ },
15
15
  };
16
16
  }
17
17
  getUserElement( /* user: USyncUser */) {
@@ -9,20 +9,20 @@ class USyncDisappearingModeProtocol {
9
9
  getQueryElement() {
10
10
  return {
11
11
  tag: 'disappearing_mode',
12
- attrs: {}
12
+ attrs: {},
13
13
  };
14
14
  }
15
15
  getUserElement() {
16
16
  return null;
17
17
  }
18
18
  parser(node) {
19
- if (node.tag === 'status') {
19
+ if (node.tag === 'disappearing_mode') {
20
20
  (0, WABinary_1.assertNodeErrorFree)(node);
21
21
  const duration = +(node === null || node === void 0 ? void 0 : node.attrs.duration);
22
22
  const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
23
23
  return {
24
24
  duration,
25
- setAt
25
+ setAt,
26
26
  };
27
27
  }
28
28
  }
@@ -9,7 +9,7 @@ class USyncStatusProtocol {
9
9
  getQueryElement() {
10
10
  return {
11
11
  tag: 'status',
12
- attrs: {}
12
+ attrs: {},
13
13
  };
14
14
  }
15
15
  getUserElement() {
@@ -34,7 +34,7 @@ class USyncStatusProtocol {
34
34
  }
35
35
  return {
36
36
  status,
37
- setAt
37
+ setAt,
38
38
  };
39
39
  }
40
40
  }
@@ -17,7 +17,7 @@ class USyncBotProfileProtocol {
17
17
  return {
18
18
  tag: 'bot',
19
19
  attrs: {},
20
- content: [{ tag: 'profile', attrs: { persona_id: user.personaId } }]
20
+ content: [{ tag: 'profile', attrs: { 'persona_id': user.personaId } }]
21
21
  };
22
22
  }
23
23
  parser(node) {
@@ -8,7 +8,7 @@ class USyncLIDProtocol {
8
8
  getQueryElement() {
9
9
  return {
10
10
  tag: 'lid',
11
- attrs: {}
11
+ attrs: {},
12
12
  };
13
13
  }
14
14
  getUserElement() {
@@ -28,13 +28,13 @@ class USyncQuery {
28
28
  if (result.attrs.type !== 'result') {
29
29
  return;
30
30
  }
31
- const protocolMap = Object.fromEntries(this.protocols.map(protocol => {
31
+ const protocolMap = Object.fromEntries(this.protocols.map((protocol) => {
32
32
  return [protocol.name, protocol.parser];
33
33
  }));
34
34
  const queryResult = {
35
35
  // TODO: implement errors etc.
36
36
  list: [],
37
- sideList: []
37
+ sideList: [],
38
38
  };
39
39
  const usyncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'usync');
40
40
  //TODO: implement error backoff, refresh etc.
@@ -42,22 +42,18 @@ class USyncQuery {
42
42
  //const resultNode = getBinaryNodeChild(usyncNode, 'result')
43
43
  const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
44
44
  if (Array.isArray(listNode === null || listNode === void 0 ? void 0 : listNode.content) && typeof listNode !== 'undefined') {
45
- queryResult.list = listNode.content.map(node => {
45
+ queryResult.list = listNode.content.map((node) => {
46
46
  const id = node === null || node === void 0 ? void 0 : node.attrs.jid;
47
- const data = Array.isArray(node === null || node === void 0 ? void 0 : node.content)
48
- ? Object.fromEntries(node.content
49
- .map(content => {
50
- const protocol = content.tag;
51
- const parser = protocolMap[protocol];
52
- if (parser) {
53
- return [protocol, parser(content)];
54
- }
55
- else {
56
- return [protocol, null];
57
- }
58
- })
59
- .filter(([, b]) => b !== null))
60
- : {};
47
+ const data = Array.isArray(node === null || node === void 0 ? void 0 : node.content) ? Object.fromEntries(node.content.map((content) => {
48
+ const protocol = content.tag;
49
+ const parser = protocolMap[protocol];
50
+ if (parser) {
51
+ return [protocol, parser(content)];
52
+ }
53
+ else {
54
+ return [protocol, null];
55
+ }
56
+ }).filter(([, b]) => b !== null)) : {};
61
57
  return { ...data, id };
62
58
  });
63
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@queenanya/baileys",
3
- "version": "8.2.7",
3
+ "version": "8.3.1",
4
4
  "description": "Custom Baileys WhatsApp API",
5
5
  "keywords": [
6
6
  "baileys",
@@ -32,22 +32,25 @@
32
32
  "dependencies": {
33
33
  "@adiwajshing/keyed-db": "^0.2.4",
34
34
  "@cacheable/node-cache": "^1.4.0",
35
- "@queenanya/eslint-config": "github:whiskeysockets/eslint-config",
36
35
  "@hapi/boom": "^10.0.1",
37
36
  "async-lock": "^1.4.1",
38
37
  "async-mutex": "^0.5.0",
39
38
  "audio-decode": "^2.1.3",
40
39
  "axios": "^1.7.3",
41
40
  "cache-manager": "^5.7.6",
42
- "libsignal": "npm:@queenanya/libsignal@latest",
41
+ "libphonenumber-js": "^1.10.20",
42
+ "libsignal": "github:nstar-y/libsignal",
43
43
  "lodash": "^4.17.21",
44
44
  "music-metadata": "^7.12.3",
45
45
  "pino": "^9.6",
46
46
  "protobufjs": "^7.2.4",
47
- "qrcode-terminal": "0.12.x",
47
+ "uuid": "^10.0.0",
48
48
  "ws": "^8.18.0"
49
49
  },
50
50
  "devDependencies": {
51
+ "@adiwajshing/eslint-config": "github:adiwajshing/eslint-config",
52
+ "@queenanya/eslint-config": "github:adiwajshing/eslint-config",
53
+ "@types/got": "^9.6.11",
51
54
  "@types/jest": "^29.5.12",
52
55
  "@types/node": "^20.14.10",
53
56
  "@types/ws": "^8.5.11",
@@ -59,8 +62,9 @@
59
62
  "link-preview-js": "^3.0.5",
60
63
  "open": "^10.1.0",
61
64
  "protobufjs-cli": "^1.1.3",
65
+ "qrcode-terminal": "^0.12.0",
62
66
  "release-it": "^17.6.0",
63
- "sharp": "^0.33.4",
67
+ "sharp": "^0.34.1",
64
68
  "ts-jest": "^29.2.2",
65
69
  "ts-node": "^10.9.2",
66
70
  "typedoc": "^0.27.9",
@@ -1,14 +0,0 @@
1
- import { Store } from 'cache-manager';
2
- import { AuthenticationCreds } from '../Types';
3
- declare const makeCacheManagerAuthState: (store: Store, sessionKey: string) => Promise<{
4
- clearState: () => Promise<void>;
5
- saveCreds: () => Promise<void>;
6
- state: {
7
- creds: AuthenticationCreds;
8
- keys: {
9
- get: (type: string, ids: string[]) => Promise<{}>;
10
- set: (data: any) => Promise<void>;
11
- };
12
- };
13
- }>;
14
- export default makeCacheManagerAuthState;
@@ -1,83 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const cache_manager_1 = require("cache-manager");
7
- const WAProto_1 = require("../../WAProto");
8
- const Utils_1 = require("../Utils");
9
- const logger_1 = __importDefault(require("../Utils/logger"));
10
- const makeCacheManagerAuthState = async (store, sessionKey) => {
11
- const defaultKey = (file) => `${sessionKey}:${file}`;
12
- const databaseConn = await (0, cache_manager_1.caching)(store);
13
- const writeData = async (file, data) => {
14
- let ttl = undefined;
15
- if (file === 'creds') {
16
- ttl = 63115200; // 2 years
17
- }
18
- await databaseConn.set(defaultKey(file), JSON.stringify(data, Utils_1.BufferJSON.replacer), ttl);
19
- };
20
- const readData = async (file) => {
21
- try {
22
- const data = await databaseConn.get(defaultKey(file));
23
- if (data) {
24
- return JSON.parse(data, Utils_1.BufferJSON.reviver);
25
- }
26
- return null;
27
- }
28
- catch (error) {
29
- logger_1.default.error(error);
30
- return null;
31
- }
32
- };
33
- const removeData = async (file) => {
34
- try {
35
- return await databaseConn.del(defaultKey(file));
36
- }
37
- catch (_a) {
38
- logger_1.default.error(`Error removing ${file} from session ${sessionKey}`);
39
- }
40
- };
41
- const clearState = async () => {
42
- try {
43
- const result = await databaseConn.store.keys(`${sessionKey}*`);
44
- await Promise.all(result.map(async (key) => await databaseConn.del(key)));
45
- }
46
- catch (err) {
47
- }
48
- };
49
- const creds = (await readData('creds')) || (0, Utils_1.initAuthCreds)();
50
- return {
51
- clearState,
52
- saveCreds: () => writeData('creds', creds),
53
- state: {
54
- creds,
55
- keys: {
56
- get: async (type, ids) => {
57
- const data = {};
58
- await Promise.all(ids.map(async (id) => {
59
- let value = await readData(`${type}-${id}`);
60
- if (type === 'app-state-sync-key' && value) {
61
- value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
62
- }
63
- data[id] = value;
64
- }));
65
- return data;
66
- },
67
- set: async (data) => {
68
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
- const tasks = [];
70
- for (const category in data) {
71
- for (const id in data[category]) {
72
- const value = data[category][id];
73
- const key = `${category}-${id}`;
74
- tasks.push(value ? writeData(key, value) : removeData(key));
75
- }
76
- }
77
- await Promise.all(tasks);
78
- },
79
- }
80
- }
81
- };
82
- };
83
- exports.default = makeCacheManagerAuthState;