jagproject 26.3.23 → 26.3.26

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 (209) hide show
  1. package/WAProto/GenerateStatics.sh +3 -4
  2. package/WAProto/WAProto.proto +1215 -511
  3. package/WAProto/fix-imports.js +73 -0
  4. package/WAProto/index.d.ts +14017 -0
  5. package/WAProto/index.js +64857 -145167
  6. package/engine-requirements.js +4 -7
  7. package/lib/Defaults/index.d.ts +74 -0
  8. package/lib/Defaults/index.js +49 -35
  9. package/lib/Defaults/phonenumber-mcc.json +223 -0
  10. package/lib/Defaults/wileys-version.json +2 -2
  11. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  12. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  13. package/lib/Signal/Group/group-session-builder.js +5 -3
  14. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  15. package/lib/Signal/Group/group_cipher.js +35 -46
  16. package/lib/Signal/Group/index.d.ts +12 -0
  17. package/lib/Signal/Group/index.js +21 -21
  18. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  19. package/lib/Signal/Group/keyhelper.js +2 -2
  20. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  21. package/lib/Signal/Group/sender-chain-key.js +5 -10
  22. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  23. package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
  24. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  25. package/lib/Signal/Group/sender-key-message.js +8 -8
  26. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  27. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  28. package/lib/Signal/Group/sender-key-record.js +7 -16
  29. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  30. package/lib/Signal/Group/sender-key-state.js +25 -37
  31. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  32. package/lib/Signal/Group/sender-message-key.js +2 -2
  33. package/lib/Signal/libsignal.d.ts +5 -0
  34. package/lib/Signal/libsignal.js +358 -54
  35. package/lib/Signal/lid-mapping.d.ts +19 -0
  36. package/lib/Signal/lid-mapping.js +274 -0
  37. package/lib/Socket/Client/index.d.ts +3 -0
  38. package/lib/Socket/Client/index.js +2 -2
  39. package/lib/Socket/Client/types.d.ts +16 -0
  40. package/lib/Socket/Client/types.js +1 -0
  41. package/lib/Socket/Client/websocket.d.ts +13 -0
  42. package/lib/Socket/Client/websocket.js +18 -30
  43. package/lib/Socket/business.d.ts +202 -0
  44. package/lib/Socket/business.js +160 -38
  45. package/lib/Socket/chats.d.ts +111 -0
  46. package/lib/Socket/chats.js +497 -314
  47. package/lib/Socket/communities.d.ts +258 -0
  48. package/lib/Socket/communities.js +438 -0
  49. package/lib/Socket/community.js +333 -0
  50. package/lib/Socket/groups.d.ts +150 -0
  51. package/lib/Socket/groups.js +229 -91
  52. package/lib/Socket/index.d.ts +245 -0
  53. package/lib/Socket/index.js +9 -6
  54. package/lib/Socket/messages-recv.d.ts +187 -0
  55. package/lib/Socket/messages-recv.js +1105 -501
  56. package/lib/Socket/messages-send.d.ts +183 -0
  57. package/lib/Socket/messages-send.js +1181 -501
  58. package/lib/Socket/mex.d.ts +3 -0
  59. package/lib/Socket/mex.js +45 -0
  60. package/lib/Socket/newsletter.d.ts +160 -0
  61. package/lib/Socket/newsletter.js +227 -200
  62. package/lib/Socket/socket.d.ts +55 -0
  63. package/lib/Socket/socket.js +507 -206
  64. package/lib/Socket/usync.js +6 -6
  65. package/lib/Store/index.js +17 -5
  66. package/lib/Store/make-cache-manager-store.js +83 -0
  67. package/lib/Store/make-in-memory-store.js +48 -89
  68. package/lib/Store/make-ordered-dictionary.js +1 -1
  69. package/lib/Types/Auth.d.ts +116 -0
  70. package/lib/Types/Bussines.d.ts +25 -0
  71. package/lib/Types/Bussines.js +2 -0
  72. package/lib/Types/Call.d.ts +15 -0
  73. package/lib/Types/Chat.d.ts +123 -0
  74. package/lib/Types/Chat.js +7 -1
  75. package/lib/Types/Contact.d.ts +24 -0
  76. package/lib/Types/Events.d.ts +237 -0
  77. package/lib/Types/Events.js +1 -0
  78. package/lib/Types/GroupMetadata.d.ts +67 -0
  79. package/lib/Types/Label.d.ts +47 -0
  80. package/lib/Types/Label.js +1 -3
  81. package/lib/Types/LabelAssociation.d.ts +30 -0
  82. package/lib/Types/LabelAssociation.js +1 -3
  83. package/lib/Types/Message.d.ts +305 -0
  84. package/lib/Types/Message.js +9 -5
  85. package/lib/Types/MexUpdates.js +11 -0
  86. package/lib/Types/Newsletter.d.ts +135 -0
  87. package/lib/Types/Newsletter.js +36 -11
  88. package/lib/Types/Product.d.ts +79 -0
  89. package/lib/Types/Signal.d.ts +76 -0
  90. package/lib/Types/Signal.js +1 -0
  91. package/lib/Types/Socket.d.ts +133 -0
  92. package/lib/Types/Socket.js +1 -0
  93. package/lib/Types/State.d.ts +39 -0
  94. package/lib/Types/State.js +12 -0
  95. package/lib/Types/USync.d.ts +26 -0
  96. package/lib/Types/USync.js +1 -0
  97. package/lib/Types/index.d.ts +65 -0
  98. package/lib/Types/index.js +14 -14
  99. package/lib/Utils/audioToBuffer.js +31 -0
  100. package/lib/Utils/auth-utils.d.ts +19 -0
  101. package/lib/Utils/auth-utils.js +222 -123
  102. package/lib/Utils/baileys-event-stream.js +60 -0
  103. package/lib/Utils/bridge-runtime.d.ts +1 -0
  104. package/lib/Utils/bridge-runtime.js +14 -0
  105. package/lib/Utils/browser-utils.d.ts +4 -0
  106. package/lib/Utils/browser-utils.js +38 -29
  107. package/lib/Utils/business.d.ts +23 -0
  108. package/lib/Utils/business.js +54 -48
  109. package/lib/Utils/chat-utils.d.ts +70 -0
  110. package/lib/Utils/chat-utils.js +284 -189
  111. package/lib/Utils/crypto.d.ts +37 -0
  112. package/lib/Utils/crypto.js +16 -41
  113. package/lib/Utils/decode-wa-message.d.ts +48 -0
  114. package/lib/Utils/decode-wa-message.js +128 -48
  115. package/lib/Utils/event-buffer.d.ts +34 -0
  116. package/lib/Utils/event-buffer.js +124 -62
  117. package/lib/Utils/generics.d.ts +91 -0
  118. package/lib/Utils/generics.js +154 -138
  119. package/lib/Utils/history.d.ts +22 -0
  120. package/lib/Utils/history.js +77 -34
  121. package/lib/Utils/identity-change-handler.d.ts +37 -0
  122. package/lib/Utils/identity-change-handler.js +54 -0
  123. package/lib/Utils/index.d.ts +22 -0
  124. package/lib/Utils/index.js +32 -19
  125. package/lib/Utils/link-preview.d.ts +21 -0
  126. package/lib/Utils/link-preview.js +12 -17
  127. package/lib/Utils/logger.d.ts +13 -0
  128. package/lib/Utils/lt-hash.d.ts +8 -0
  129. package/lib/Utils/lt-hash.js +2 -43
  130. package/lib/Utils/make-mutex.d.ts +9 -0
  131. package/lib/Utils/make-mutex.js +21 -27
  132. package/lib/Utils/message-retry-manager.d.ts +110 -0
  133. package/lib/Utils/message-retry-manager.js +143 -45
  134. package/lib/Utils/messages-media.d.ts +130 -0
  135. package/lib/Utils/messages-media.js +429 -502
  136. package/lib/Utils/messages-newsletter.d.ts +84 -0
  137. package/lib/Utils/messages-newsletter.js +295 -0
  138. package/lib/Utils/messages.d.ts +92 -0
  139. package/lib/Utils/messages.js +1025 -674
  140. package/lib/Utils/noise-handler.d.ts +20 -0
  141. package/lib/Utils/noise-handler.js +145 -91
  142. package/lib/Utils/pre-key-manager.d.ts +28 -0
  143. package/lib/Utils/pre-key-manager.js +112 -0
  144. package/lib/Utils/process-message.d.ts +60 -0
  145. package/lib/Utils/process-message.js +316 -184
  146. package/lib/Utils/reporting-utils.d.ts +11 -0
  147. package/lib/Utils/reporting-utils.js +262 -0
  148. package/lib/Utils/resolve-jid.d.ts +43 -0
  149. package/lib/Utils/resolve-jid.js +95 -0
  150. package/lib/Utils/rust-bridge-shim.d.ts +22 -0
  151. package/lib/Utils/rust-bridge-shim.js +70 -0
  152. package/lib/Utils/serial-task-queue.js +29 -0
  153. package/lib/Utils/signal.d.ts +34 -0
  154. package/lib/Utils/signal.js +56 -39
  155. package/lib/Utils/streamToBuffer.js +17 -0
  156. package/lib/Utils/sync-action-utils.d.ts +19 -0
  157. package/lib/Utils/sync-action-utils.js +52 -0
  158. package/lib/Utils/tc-token-utils.d.ts +12 -0
  159. package/lib/Utils/tc-token-utils.js +20 -0
  160. package/lib/Utils/use-mongo-file-auth-state.js +71 -0
  161. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  162. package/lib/Utils/use-multi-file-auth-state.js +11 -12
  163. package/lib/Utils/use-single-file-auth-state.js +73 -0
  164. package/lib/Utils/validate-connection.d.ts +11 -0
  165. package/lib/Utils/validate-connection.js +59 -82
  166. package/lib/Utils/wileys-event-stream.js +1 -61
  167. package/lib/WABinary/constants.d.ts +28 -0
  168. package/lib/WABinary/decode.d.ts +7 -0
  169. package/lib/WABinary/decode.js +39 -4
  170. package/lib/WABinary/encode.d.ts +3 -0
  171. package/lib/WABinary/encode.js +17 -11
  172. package/lib/WABinary/generic-utils.d.ts +15 -0
  173. package/lib/WABinary/generic-utils.js +46 -18
  174. package/lib/WABinary/index.d.ts +6 -0
  175. package/lib/WABinary/index.js +9 -5
  176. package/lib/WABinary/jid-utils.d.ts +48 -0
  177. package/lib/WABinary/jid-utils.js +67 -37
  178. package/lib/WABinary/types.d.ts +19 -0
  179. package/lib/WABinary/types.js +34 -0
  180. package/lib/WAM/BinaryInfo.d.ts +9 -0
  181. package/lib/WAM/constants.d.ts +40 -0
  182. package/lib/WAM/constants.js +19183 -11678
  183. package/lib/WAM/encode.d.ts +3 -0
  184. package/lib/WAM/encode.js +15 -17
  185. package/lib/WAM/index.d.ts +4 -0
  186. package/lib/WAM/index.js +3 -3
  187. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  188. package/lib/WAUSync/Protocols/USyncContactProtocol.js +6 -6
  189. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  190. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +9 -9
  191. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  192. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +6 -6
  193. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  194. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -8
  195. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  196. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +18 -17
  197. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  198. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
  199. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  200. package/lib/WAUSync/Protocols/index.js +6 -4
  201. package/lib/WAUSync/USyncQuery.d.ts +29 -0
  202. package/lib/WAUSync/USyncQuery.js +38 -30
  203. package/lib/WAUSync/USyncUser.d.ts +13 -0
  204. package/lib/WAUSync/index.d.ts +4 -0
  205. package/lib/WAUSync/index.js +3 -3
  206. package/lib/index.d.ts +12 -0
  207. package/lib/index.js +3 -5
  208. package/package.json +7 -4
  209. package/LICENSE +0 -21
@@ -1,26 +1,116 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extractGroupMetadata = exports.makeGroupsSocket = void 0;
4
- const WAProto_1 = require("../../WAProto");
5
- const Types_1 = require("../Types");
6
- const Utils_1 = require("../Utils");
7
- const WABinary_1 = require("../WABinary");
8
- const chats_1 = require("./chats");
4
+ const index_js_1 = require("../../WAProto/index.js");
5
+ const index_js_2 = require("../Types/index.js");
6
+ const index_js_3 = require("../Utils/index.js");
7
+ const index_js_4 = require("../WABinary/index.js");
8
+ const chats_js_1 = require("./chats.js");
9
9
  const makeGroupsSocket = (config) => {
10
- const sock = (0, chats_1.makeChatsSocket)(config);
10
+ const sock = (0, chats_js_1.makeChatsSocket)(config);
11
11
  const { authState, ev, query, upsertMessage } = sock;
12
- const groupQuery = async (jid, type, content) => (query({
12
+ const { cachedGroupMetadata } = config;
13
+ // ── Built-in group metadata cache ─────────────────────────────────────────
14
+ const groupMetadataCache = new Map();
15
+ const GROUP_CACHE_TTL = (config.groupCacheTTL || 5) * 60 * 1000; // default 5 menit
16
+ const getCachedGroupMetadata = async (jid) => {
17
+ // 1. Cek user-provided cachedGroupMetadata (dari config makeWASocket)
18
+ if (cachedGroupMetadata) {
19
+ const cached = await cachedGroupMetadata(jid);
20
+ if (cached && Array.isArray(cached.participants))
21
+ return cached;
22
+ }
23
+ // 2. Cek internal Map cache
24
+ const entry = groupMetadataCache.get(jid);
25
+ if (entry && Date.now() - entry.ts < GROUP_CACHE_TTL) {
26
+ return entry.data;
27
+ }
28
+ return undefined;
29
+ };
30
+ const setCachedGroupMetadata = (jid, data) => {
31
+ groupMetadataCache.set(jid, { data, ts: Date.now() });
32
+ };
33
+ // Update cache saat groups.update event
34
+ ev.on('groups.update', (updates) => {
35
+ for (const update of updates) {
36
+ const entry = groupMetadataCache.get(update.id);
37
+ if (entry) {
38
+ // Merge update ke cache yang ada
39
+ groupMetadataCache.set(update.id, {
40
+ data: { ...entry.data, ...update },
41
+ ts: entry.ts
42
+ });
43
+ }
44
+ }
45
+ });
46
+ // Update cache saat participant berubah
47
+ // Debounce map to prevent duplicate refresh calls for same group
48
+ const _refreshDebounce = new Map();
49
+ const _refreshGroupMetadata = async (jid) => {
50
+ // Debounce: skip jika refresh sudah dijadwalkan dalam 2 detik terakhir
51
+ if (_refreshDebounce.has(jid))
52
+ return;
53
+ _refreshDebounce.set(jid, true);
54
+ setTimeout(() => _refreshDebounce.delete(jid), 2000);
55
+ try {
56
+ const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
57
+ const meta = (0, exports.extractGroupMetadata)(result);
58
+ setCachedGroupMetadata(jid, meta);
59
+ // Emit groups.update agar subscriber luar (makeInMemoryStore dll) ikut terupdate
60
+ ev.emit('groups.update', [meta]);
61
+ }
62
+ catch (e) {
63
+ // Ignore jika gagal (bot mungkin sudah keluar dari grup)
64
+ }
65
+ };
66
+ ev.on('group-participants.update', ({ id, participants, action }) => {
67
+ const entry = groupMetadataCache.get(id);
68
+ if (entry && Array.isArray(entry.data?.participants)) {
69
+ // Fast-path: update cache lokal secara optimistis tanpa tunggu network
70
+ const meta = { ...entry.data, participants: [...entry.data.participants] };
71
+ if (action === 'add') {
72
+ const existing = new Set(meta.participants.map(p => p.id));
73
+ for (const jid of participants) {
74
+ if (!existing.has(jid))
75
+ meta.participants.push({ id: jid, admin: null });
76
+ }
77
+ }
78
+ else if (action === 'remove') {
79
+ meta.participants = meta.participants.filter(p => !participants.includes(p.id));
80
+ }
81
+ else if (action === 'promote') {
82
+ meta.participants = meta.participants.map(p => participants.includes(p.id) ? { ...p, admin: 'admin' } : p);
83
+ }
84
+ else if (action === 'demote') {
85
+ meta.participants = meta.participants.map(p => participants.includes(p.id) ? { ...p, admin: null } : p);
86
+ }
87
+ groupMetadataCache.set(id, { data: meta, ts: entry.ts });
88
+ }
89
+ // Auto-refresh dari network untuk semua aksi participant
90
+ // Ini memastikan data selalu akurat dari server WA
91
+ _refreshGroupMetadata(id);
92
+ });
93
+ // ── End group metadata cache ───────────────────────────────────────────────
94
+ const groupQuery = async (jid, type, content) => query({
13
95
  tag: 'iq',
14
96
  attrs: {
15
97
  type,
16
98
  xmlns: 'w:g2',
17
- to: jid,
99
+ to: jid
18
100
  },
19
101
  content
20
- }));
102
+ });
21
103
  const groupMetadata = async (jid) => {
104
+ // Cek cache dulu sebelum hit network
105
+ const cached = await getCachedGroupMetadata(jid);
106
+ if (cached)
107
+ return cached;
108
+ // Fetch dari WA
22
109
  const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
23
- return (0, exports.extractGroupMetadata)(result);
110
+ const meta = (0, exports.extractGroupMetadata)(result);
111
+ // Simpan ke cache
112
+ setCachedGroupMetadata(jid, meta);
113
+ return meta;
24
114
  };
25
115
  const groupFetchAllParticipating = async () => {
26
116
  const result = await query({
@@ -28,7 +118,7 @@ const makeGroupsSocket = (config) => {
28
118
  attrs: {
29
119
  to: '@g.us',
30
120
  xmlns: 'w:g2',
31
- type: 'get',
121
+ type: 'get'
32
122
  },
33
123
  content: [
34
124
  {
@@ -42,9 +132,9 @@ const makeGroupsSocket = (config) => {
42
132
  ]
43
133
  });
44
134
  const data = {};
45
- const groupsChild = (0, WABinary_1.getBinaryNodeChild)(result, 'groups');
135
+ const groupsChild = (0, index_js_4.getBinaryNodeChild)(result, 'groups');
46
136
  if (groupsChild) {
47
- const groups = (0, WABinary_1.getBinaryNodeChildren)(groupsChild, 'group');
137
+ const groups = (0, index_js_4.getBinaryNodeChildren)(groupsChild, 'group');
48
138
  for (const groupNode of groups) {
49
139
  const meta = (0, exports.extractGroupMetadata)({
50
140
  tag: 'result',
@@ -54,11 +144,12 @@ const makeGroupsSocket = (config) => {
54
144
  data[meta.id] = meta;
55
145
  }
56
146
  }
147
+ // TODO: properly parse LID / PN DATA
57
148
  sock.ev.emit('groups.update', Object.values(data));
58
149
  return data;
59
150
  };
60
151
  sock.ws.on('CB:ib,,dirty', async (node) => {
61
- const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
152
+ const { attrs } = (0, index_js_4.getBinaryNodeChild)(node, 'dirty');
62
153
  if (attrs.type !== 'groups') {
63
154
  return;
64
155
  }
@@ -67,10 +158,9 @@ const makeGroupsSocket = (config) => {
67
158
  });
68
159
  return {
69
160
  ...sock,
70
- groupQuery,
71
161
  groupMetadata,
72
162
  groupCreate: async (subject, participants) => {
73
- const key = (0, Utils_1.generateMessageIDV2)();
163
+ const key = (0, index_js_3.generateMessageIDV2)();
74
164
  const result = await groupQuery('@g.us', 'set', [
75
165
  {
76
166
  tag: 'create',
@@ -91,9 +181,7 @@ const makeGroupsSocket = (config) => {
91
181
  {
92
182
  tag: 'leave',
93
183
  attrs: {},
94
- content: [
95
- { tag: 'group', attrs: { id } }
96
- ]
184
+ content: [{ tag: 'group', attrs: { id } }]
97
185
  }
98
186
  ]);
99
187
  },
@@ -113,12 +201,13 @@ const makeGroupsSocket = (config) => {
113
201
  attrs: {}
114
202
  }
115
203
  ]);
116
- const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_approval_requests');
117
- const participants = (0, WABinary_1.getBinaryNodeChildren)(node, 'membership_approval_request');
204
+ const node = (0, index_js_4.getBinaryNodeChild)(result, 'membership_approval_requests');
205
+ const participants = (0, index_js_4.getBinaryNodeChildren)(node, 'membership_approval_request');
118
206
  return participants.map(v => v.attrs);
119
207
  },
120
208
  groupRequestParticipantsUpdate: async (jid, participants, action) => {
121
- const result = await groupQuery(jid, 'set', [{
209
+ const result = await groupQuery(jid, 'set', [
210
+ {
122
211
  tag: 'membership_requests_action',
123
212
  attrs: {},
124
213
  content: [
@@ -131,10 +220,11 @@ const makeGroupsSocket = (config) => {
131
220
  }))
132
221
  }
133
222
  ]
134
- }]);
135
- const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_requests_action');
136
- const nodeAction = (0, WABinary_1.getBinaryNodeChild)(node, action);
137
- const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(nodeAction, 'participant');
223
+ }
224
+ ]);
225
+ const node = (0, index_js_4.getBinaryNodeChild)(result, 'membership_requests_action');
226
+ const nodeAction = (0, index_js_4.getBinaryNodeChild)(node, action);
227
+ const participantsAffected = (0, index_js_4.getBinaryNodeChildren)(nodeAction, 'participant');
138
228
  return participantsAffected.map(p => {
139
229
  return { status: p.attrs.error || '200', jid: p.attrs.jid };
140
230
  });
@@ -150,43 +240,40 @@ const makeGroupsSocket = (config) => {
150
240
  }))
151
241
  }
152
242
  ]);
153
- const node = (0, WABinary_1.getBinaryNodeChild)(result, action);
154
- const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(node, 'participant');
243
+ const node = (0, index_js_4.getBinaryNodeChild)(result, action);
244
+ const participantsAffected = (0, index_js_4.getBinaryNodeChildren)(node, 'participant');
155
245
  return participantsAffected.map(p => {
156
246
  return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
157
247
  });
158
248
  },
159
249
  groupUpdateDescription: async (jid, description) => {
160
- var _a;
161
250
  const metadata = await groupMetadata(jid);
162
- const prev = (_a = metadata.descId) !== null && _a !== void 0 ? _a : null;
251
+ const prev = metadata.descId ?? null;
163
252
  await groupQuery(jid, 'set', [
164
253
  {
165
254
  tag: 'description',
166
255
  attrs: {
167
- ...(description ? { id: (0, Utils_1.generateMessageIDV2)() } : { delete: 'true' }),
256
+ ...(description ? { id: (0, index_js_3.generateMessageIDV2)() } : { delete: 'true' }),
168
257
  ...(prev ? { prev } : {})
169
258
  },
170
- content: description ? [
171
- { tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }
172
- ] : undefined
259
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
173
260
  }
174
261
  ]);
175
262
  },
176
263
  groupInviteCode: async (jid) => {
177
264
  const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
178
- const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
179
- return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
265
+ const inviteNode = (0, index_js_4.getBinaryNodeChild)(result, 'invite');
266
+ return inviteNode?.attrs.code;
180
267
  },
181
268
  groupRevokeInvite: async (jid) => {
182
269
  const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
183
- const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
184
- return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
270
+ const inviteNode = (0, index_js_4.getBinaryNodeChild)(result, 'invite');
271
+ return inviteNode?.attrs.code;
185
272
  },
186
273
  groupAcceptInvite: async (code) => {
187
274
  const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
188
- const result = (0, WABinary_1.getBinaryNodeChild)(results, 'group');
189
- return result === null || result === void 0 ? void 0 : result.attrs.jid;
275
+ const result = (0, index_js_4.getBinaryNodeChild)(results, 'group');
276
+ return result?.attrs.jid;
190
277
  },
191
278
  /**
192
279
  * revoke a v4 invite for someone
@@ -195,7 +282,9 @@ const makeGroupsSocket = (config) => {
195
282
  * @returns true if successful
196
283
  */
197
284
  groupRevokeInviteV4: async (groupJid, invitedJid) => {
198
- const result = await groupQuery(groupJid, 'set', [{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }]);
285
+ const result = await groupQuery(groupJid, 'set', [
286
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
287
+ ]);
199
288
  return !!result;
200
289
  },
201
290
  /**
@@ -204,21 +293,22 @@ const makeGroupsSocket = (config) => {
204
293
  * @param inviteMessage the message to accept
205
294
  */
206
295
  groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
207
- var _a;
208
296
  key = typeof key === 'string' ? { remoteJid: key } : key;
209
- const results = await groupQuery(inviteMessage.groupJid, 'set', [{
297
+ const results = await groupQuery(inviteMessage.groupJid, 'set', [
298
+ {
210
299
  tag: 'accept',
211
300
  attrs: {
212
301
  code: inviteMessage.inviteCode,
213
302
  expiration: inviteMessage.inviteExpiration.toString(),
214
303
  admin: key.remoteJid
215
304
  }
216
- }]);
305
+ }
306
+ ]);
217
307
  // if we have the full message key
218
308
  // update the invite message to be expired
219
309
  if (key.id) {
220
310
  // create new invite message that is expired
221
- inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
311
+ inviteMessage = index_js_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
222
312
  inviteMessage.inviteExpiration = 0;
223
313
  inviteMessage.inviteCode = '';
224
314
  ev.emit('messages.update', [
@@ -236,16 +326,14 @@ const makeGroupsSocket = (config) => {
236
326
  await upsertMessage({
237
327
  key: {
238
328
  remoteJid: inviteMessage.groupJid,
239
- id: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
329
+ id: (0, index_js_3.generateMessageIDV2)(sock.user?.id),
240
330
  fromMe: false,
241
- participant: key.remoteJid,
331
+ participant: key.remoteJid
242
332
  },
243
- messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
244
- messageStubParameters: [
245
- authState.creds.me.id
246
- ],
333
+ messageStubType: index_js_2.WAMessageStubType.GROUP_PARTICIPANT_ADD,
334
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
247
335
  participant: key.remoteJid,
248
- messageTimestamp: (0, Utils_1.unixTimestampSeconds)()
336
+ messageTimestamp: (0, index_js_3.unixTimestampSeconds)()
249
337
  }, 'notify');
250
338
  return results.attrs.from;
251
339
  }),
@@ -254,9 +342,9 @@ const makeGroupsSocket = (config) => {
254
342
  return (0, exports.extractGroupMetadata)(results);
255
343
  },
256
344
  groupToggleEphemeral: async (jid, ephemeralExpiration) => {
257
- const content = ephemeralExpiration ?
258
- { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } } :
259
- { tag: 'not_ephemeral', attrs: {} };
345
+ const content = ephemeralExpiration
346
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
347
+ : { tag: 'not_ephemeral', attrs: {} };
260
348
  await groupQuery(jid, 'set', [content]);
261
349
  },
262
350
  groupSettingUpdate: async (jid, setting) => {
@@ -266,63 +354,113 @@ const makeGroupsSocket = (config) => {
266
354
  await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
267
355
  },
268
356
  groupJoinApprovalMode: async (jid, mode) => {
269
- await groupQuery(jid, 'set', [{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }]);
357
+ await groupQuery(jid, 'set', [
358
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
359
+ ]);
270
360
  },
271
- groupFetchAllParticipating
361
+ groupFetchAllParticipating,
362
+ /**
363
+ * Auto detect isAdmin & isBotAdmin dari groupMetadata
364
+ * @param {string} groupJid - JID grup
365
+ * @param {string} senderJid - JID pengirim pesan
366
+ * @returns {Promise<{isAdmin: boolean, isBotAdmin: boolean}>}
367
+ */
368
+ getAdminStatus: async (groupJid, senderJid) => {
369
+ const normalizeJid = (jid) => {
370
+ if (!jid)
371
+ return null;
372
+ try {
373
+ return (0, index_js_4.jidNormalizedUser)(jid).split('@')[0];
374
+ }
375
+ catch {
376
+ return String(jid).split('@')[0];
377
+ }
378
+ };
379
+ const botJid = sock.authState?.creds?.me?.id;
380
+ const meta = await sock.groupMetadata(groupJid).catch(() => null);
381
+ if (!meta || !Array.isArray(meta.participants)) {
382
+ return { isAdmin: false, isBotAdmin: false };
383
+ }
384
+ const senderNorm = normalizeJid(senderJid);
385
+ const botNorm = normalizeJid(botJid);
386
+ const isAdmin = meta.participants.some(p => {
387
+ const pid = normalizeJid(p.jid || p.id || p.lid);
388
+ return pid === senderNorm && (p.admin === 'admin' || p.admin === 'superadmin');
389
+ });
390
+ // Cek isBotAdmin: via participants
391
+ let isBotAdmin = meta.participants.some(p => {
392
+ const pid = normalizeJid(p.jid || p.id || p.lid);
393
+ return pid === botNorm && (p.admin === 'admin' || p.admin === 'superadmin');
394
+ });
395
+ // Fallback: cek via owner/subjectOwner
396
+ if (!isBotAdmin) {
397
+ const owners = [meta.owner, meta.subjectOwner, meta.ownerPn]
398
+ .filter(Boolean)
399
+ .map(normalizeJid);
400
+ if (owners.includes(botNorm))
401
+ isBotAdmin = true;
402
+ }
403
+ return { isAdmin, isBotAdmin };
404
+ }
272
405
  };
273
406
  };
274
407
  exports.makeGroupsSocket = makeGroupsSocket;
275
408
  const extractGroupMetadata = (result) => {
276
- var _a, _b;
277
- const group = (0, WABinary_1.getBinaryNodeChild)(result, 'group');
278
- const descChild = (0, WABinary_1.getBinaryNodeChild)(group, 'description');
409
+ const group = (0, index_js_4.getBinaryNodeChild)(result, 'group');
410
+ const descChild = (0, index_js_4.getBinaryNodeChild)(group, 'description');
279
411
  let desc;
280
412
  let descId;
281
413
  let descOwner;
282
- let descOwnerLid;
414
+ let descOwnerPn;
283
415
  let descTime;
284
416
  if (descChild) {
285
- desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body');
286
- descOwner = (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant_pn || descChild.attrs.participant);
287
- if (group.attrs.addressing_mode === 'lid') {
288
- descOwnerLid = (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant);
289
- }
417
+ desc = (0, index_js_4.getBinaryNodeChildString)(descChild, 'body');
418
+ descOwner = descChild.attrs.participant ? (0, index_js_4.jidNormalizedUser)(descChild.attrs.participant) : undefined;
419
+ descOwnerPn = descChild.attrs.participant_pn ? (0, index_js_4.jidNormalizedUser)(descChild.attrs.participant_pn) : undefined;
420
+ descTime = +descChild.attrs.t;
290
421
  descId = descChild.attrs.id;
291
- descTime = descChild.attrs.t ? +descChild.attrs.t : undefined;
292
422
  }
293
- const groupSize = group.attrs.size ? Number(group.attrs.size) : undefined;
294
- const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, WABinary_1.jidEncode)(group.attrs.id, 'g.us');
295
- const eph = (_a = (0, WABinary_1.getBinaryNodeChild)(group, 'ephemeral')) === null || _a === void 0 ? void 0 : _a.attrs.expiration;
296
- const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add';
423
+ const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, index_js_4.jidEncode)(group.attrs.id, 'g.us');
424
+ const eph = (0, index_js_4.getBinaryNodeChild)(group, 'ephemeral')?.attrs.expiration;
425
+ const memberAddMode = (0, index_js_4.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add';
297
426
  const metadata = {
298
427
  id: groupId,
299
- addressingMode: group.attrs.addressing_mode,
428
+ notify: group.attrs.notify,
429
+ addressingMode: group.attrs.addressing_mode === 'lid' ? index_js_2.WAMessageAddressingMode.LID : index_js_2.WAMessageAddressingMode.PN,
300
430
  subject: group.attrs.subject,
301
- subjectOwner: (0, WABinary_1.jidNormalizedUser)(group.attrs.s_o_pn || group.attrs.s_o),
302
- ...(group.attrs.addressing_mode === 'lid' ? { subjectOwnerLid: (0, WABinary_1.jidNormalizedUser)(group.attrs.s_o) } : {}),
303
- subjectTime: group.attrs.s_t ? +group.attrs.s_t : undefined,
304
- size: groupSize || (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').length,
305
- creation: group.attrs.creation ? +group.attrs.creation : undefined,
306
- owner: (0, WABinary_1.jidNormalizedUser)(group.attrs.creator_pn || group.attrs.creator),
307
- ...(group.attrs.addressing_mode === 'lid' ? { ownerLid: (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) } : {}),
431
+ subjectOwner: group.attrs.s_o,
432
+ subjectOwnerPn: group.attrs.s_o_pn,
433
+ subjectTime: +group.attrs.s_t,
434
+ size: group.attrs.size ? +group.attrs.size : (0, index_js_4.getBinaryNodeChildren)(group, 'participant').length,
435
+ creation: +group.attrs.creation,
436
+ owner: group.attrs.creator ? (0, index_js_4.jidNormalizedUser)(group.attrs.creator) : undefined,
437
+ ownerPn: group.attrs.creator_pn ? (0, index_js_4.jidNormalizedUser)(group.attrs.creator_pn) : undefined,
438
+ owner_country_code: group.attrs.creator_country_code,
308
439
  desc,
309
440
  descId,
310
441
  descOwner,
311
- descOwnerLid,
442
+ descOwnerPn,
312
443
  descTime,
313
- linkedParent: ((_b = (0, WABinary_1.getBinaryNodeChild)(group, 'linked_parent')) === null || _b === void 0 ? void 0 : _b.attrs.jid) || undefined,
314
- restrict: !!(0, WABinary_1.getBinaryNodeChild)(group, 'locked'),
315
- announce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'announcement'),
316
- isCommunity: !!(0, WABinary_1.getBinaryNodeChild)(group, 'parent'),
317
- isCommunityAnnounce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'default_sub_group'),
318
- joinApprovalMode: !!(0, WABinary_1.getBinaryNodeChild)(group, 'membership_approval_mode'),
444
+ linkedParent: (0, index_js_4.getBinaryNodeChild)(group, 'linked_parent')?.attrs.jid || undefined,
445
+ restrict: !!(0, index_js_4.getBinaryNodeChild)(group, 'locked'),
446
+ announce: !!(0, index_js_4.getBinaryNodeChild)(group, 'announcement'),
447
+ isCommunity: !!(0, index_js_4.getBinaryNodeChild)(group, 'parent'),
448
+ isCommunityAnnounce: !!(0, index_js_4.getBinaryNodeChild)(group, 'default_sub_group'),
449
+ joinApprovalMode: !!(0, index_js_4.getBinaryNodeChild)(group, 'membership_approval_mode'),
319
450
  memberAddMode,
320
- participants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
451
+ participants: (0, index_js_4.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
452
+ const isLid = (0, index_js_4.isLidUser)(attrs.jid);
453
+ const pn = attrs.phone_number;
454
+ const hasPn = (0, index_js_4.isPnUser)(pn);
455
+ // Jika grup pakai LID addressing:
456
+ // - id → pakai phoneNumber (PN) agar bisa dicompare dengan m.sender
457
+ // - lid → simpan LID asli
458
+ // Jika grup pakai PN addressing: id tetap PN
321
459
  return {
322
- id: attrs.jid,
323
- jid: attrs.phone_number || attrs.jid,
324
- lid: attrs.lid || attrs.jid,
325
- admin: (attrs.type || null),
460
+ id: isLid && hasPn ? pn : attrs.jid,
461
+ phoneNumber: isLid && hasPn ? pn : undefined,
462
+ lid: isLid ? attrs.jid : ((0, index_js_4.isPnUser)(attrs.jid) && (0, index_js_4.isLidUser)(attrs.lid) ? attrs.lid : undefined),
463
+ admin: (attrs.type || null)
326
464
  };
327
465
  }),
328
466
  ephemeralDuration: eph ? +eph : undefined