@alannxd/baileys 6.0.5 → 6.0.6

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 (234) hide show
  1. package/WAProto/fix-import.js +29 -0
  2. package/WAProto/index.js +160 -201
  3. package/engine-requirements.js +1 -1
  4. package/lib/Defaults/baileys-version.json +3 -0
  5. package/lib/Defaults/index.d.ts +15 -37
  6. package/lib/Defaults/index.js +136 -119
  7. package/lib/Defaults/phonenumber-mcc.json +223 -0
  8. package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
  9. package/lib/Signal/Group/ciphertext-message.js +5 -2
  10. package/lib/Signal/Group/group-session-builder.d.ts +3 -4
  11. package/lib/Signal/Group/group-session-builder.js +41 -7
  12. package/lib/Signal/Group/group_cipher.d.ts +4 -4
  13. package/lib/Signal/Group/group_cipher.js +51 -37
  14. package/lib/Signal/Group/index.d.ts +11 -12
  15. package/lib/Signal/Group/index.js +57 -12
  16. package/lib/Signal/Group/keyhelper.d.ts +1 -2
  17. package/lib/Signal/Group/keyhelper.js +44 -7
  18. package/lib/Signal/Group/queue-job.d.ts +1 -0
  19. package/lib/Signal/Group/queue-job.js +57 -0
  20. package/lib/Signal/Group/sender-chain-key.d.ts +2 -3
  21. package/lib/Signal/Group/sender-chain-key.js +15 -7
  22. package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
  23. package/lib/Signal/Group/sender-key-distribution-message.js +11 -8
  24. package/lib/Signal/Group/sender-key-message.d.ts +1 -2
  25. package/lib/Signal/Group/sender-key-message.js +12 -9
  26. package/lib/Signal/Group/sender-key-name.d.ts +0 -1
  27. package/lib/Signal/Group/sender-key-name.js +5 -2
  28. package/lib/Signal/Group/sender-key-record.d.ts +2 -3
  29. package/lib/Signal/Group/sender-key-record.js +21 -9
  30. package/lib/Signal/Group/sender-key-state.d.ts +6 -7
  31. package/lib/Signal/Group/sender-key-state.js +42 -27
  32. package/lib/Signal/Group/sender-message-key.d.ts +0 -1
  33. package/lib/Signal/Group/sender-message-key.js +7 -4
  34. package/lib/Signal/libsignal.d.ts +3 -5
  35. package/lib/Signal/libsignal.js +90 -347
  36. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +5 -4
  37. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  38. package/lib/Socket/Client/index.d.ts +3 -3
  39. package/lib/Socket/Client/index.js +19 -3
  40. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  41. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  42. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +2 -3
  43. package/lib/Socket/Client/web-socket-client.js +62 -0
  44. package/lib/Socket/business.d.ts +108 -154
  45. package/lib/Socket/business.js +43 -162
  46. package/lib/Socket/chats.d.ts +239 -96
  47. package/lib/Socket/chats.js +427 -627
  48. package/lib/Socket/communities.d.ts +146 -239
  49. package/lib/Socket/communities.js +80 -90
  50. package/lib/Socket/groups.d.ts +57 -104
  51. package/lib/Socket/groups.js +161 -154
  52. package/lib/Socket/index.d.ts +115 -202
  53. package/lib/Socket/index.js +10 -11
  54. package/lib/Socket/luxu.d.ts +266 -22
  55. package/lib/Socket/luxu.js +465 -422
  56. package/lib/Socket/messages-recv.d.ts +84 -136
  57. package/lib/Socket/messages-recv.js +615 -1421
  58. package/lib/Socket/messages-send.d.ts +126 -142
  59. package/lib/Socket/messages-send.js +671 -878
  60. package/lib/Socket/newsletter.d.ts +85 -121
  61. package/lib/Socket/newsletter.js +272 -147
  62. package/lib/Socket/registration.d.ts +267 -0
  63. package/lib/Socket/registration.js +166 -0
  64. package/lib/Socket/socket.d.ts +19 -34
  65. package/lib/Socket/socket.js +313 -544
  66. package/lib/Socket/usync.d.ts +36 -0
  67. package/lib/Socket/usync.js +70 -0
  68. package/lib/Store/index.d.ts +3 -10
  69. package/lib/Store/index.js +10 -10
  70. package/lib/Store/make-cache-manager-store.d.ts +11 -17
  71. package/lib/Store/make-cache-manager-store.js +41 -43
  72. package/lib/Store/make-in-memory-store.d.ts +118 -39
  73. package/lib/Store/make-in-memory-store.js +341 -112
  74. package/lib/Store/make-ordered-dictionary.d.ts +10 -11
  75. package/lib/Store/make-ordered-dictionary.js +20 -14
  76. package/lib/Store/object-repository.d.ts +9 -10
  77. package/lib/Store/object-repository.js +6 -11
  78. package/lib/Types/Auth.d.ts +12 -19
  79. package/lib/Types/Auth.js +2 -2
  80. package/lib/Types/Call.d.ts +1 -3
  81. package/lib/Types/Call.js +2 -2
  82. package/lib/Types/Chat.d.ts +13 -35
  83. package/lib/Types/Chat.js +4 -8
  84. package/lib/Types/Contact.d.ts +1 -8
  85. package/lib/Types/Contact.js +2 -2
  86. package/lib/Types/Events.d.ts +17 -116
  87. package/lib/Types/Events.js +2 -2
  88. package/lib/Types/GroupMetadata.d.ts +5 -21
  89. package/lib/Types/GroupMetadata.js +2 -2
  90. package/lib/Types/Label.d.ts +0 -12
  91. package/lib/Types/Label.js +5 -3
  92. package/lib/Types/LabelAssociation.d.ts +0 -1
  93. package/lib/Types/LabelAssociation.js +5 -3
  94. package/lib/Types/Message.d.ts +58 -105
  95. package/lib/Types/Message.js +9 -11
  96. package/lib/Types/Newsletter.d.ts +103 -0
  97. package/lib/Types/Newsletter.js +38 -0
  98. package/lib/Types/Product.d.ts +1 -2
  99. package/lib/Types/Product.js +2 -2
  100. package/lib/Types/Signal.d.ts +2 -32
  101. package/lib/Types/Signal.js +2 -2
  102. package/lib/Types/Socket.d.ts +25 -50
  103. package/lib/Types/Socket.js +2 -3
  104. package/lib/Types/State.d.ts +2 -72
  105. package/lib/Types/State.js +2 -56
  106. package/lib/Types/USync.d.ts +2 -3
  107. package/lib/Types/USync.js +2 -2
  108. package/lib/Types/index.d.ts +14 -22
  109. package/lib/Types/index.js +31 -15
  110. package/lib/Utils/auth-utils.d.ts +6 -12
  111. package/lib/Utils/auth-utils.js +143 -239
  112. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  113. package/lib/Utils/baileys-event-stream.js +63 -0
  114. package/lib/Utils/business.d.ts +2 -3
  115. package/lib/Utils/business.js +69 -66
  116. package/lib/Utils/chat-utils.d.ts +23 -52
  117. package/lib/Utils/chat-utils.js +253 -396
  118. package/lib/Utils/crypto.d.ts +22 -18
  119. package/lib/Utils/crypto.js +90 -57
  120. package/lib/Utils/decode-wa-message.d.ts +8 -55
  121. package/lib/Utils/decode-wa-message.js +84 -203
  122. package/lib/Utils/event-buffer.d.ts +8 -9
  123. package/lib/Utils/event-buffer.js +77 -185
  124. package/lib/Utils/generics.d.ts +29 -28
  125. package/lib/Utils/generics.js +210 -180
  126. package/lib/Utils/history.d.ts +9 -18
  127. package/lib/Utils/history.js +55 -93
  128. package/lib/Utils/index.d.ts +17 -22
  129. package/lib/Utils/index.js +33 -22
  130. package/lib/Utils/link-preview.d.ts +5 -5
  131. package/lib/Utils/link-preview.js +24 -16
  132. package/lib/Utils/logger.d.ts +3 -11
  133. package/lib/Utils/logger.js +7 -3
  134. package/lib/Utils/lt-hash.d.ts +12 -8
  135. package/lib/Utils/lt-hash.js +46 -3
  136. package/lib/Utils/make-mutex.d.ts +2 -4
  137. package/lib/Utils/make-mutex.js +34 -24
  138. package/lib/Utils/messages-media.d.ts +44 -61
  139. package/lib/Utils/messages-media.js +482 -451
  140. package/lib/Utils/messages.d.ts +18 -32
  141. package/lib/Utils/messages.js +369 -458
  142. package/lib/Utils/noise-handler.d.ts +14 -13
  143. package/lib/Utils/noise-handler.js +99 -145
  144. package/lib/Utils/process-message.d.ts +12 -31
  145. package/lib/Utils/process-message.js +150 -459
  146. package/lib/Utils/signal.d.ts +5 -20
  147. package/lib/Utils/signal.js +72 -120
  148. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -2
  149. package/lib/Utils/use-multi-file-auth-state.js +27 -29
  150. package/lib/Utils/validate-connection.d.ts +7 -7
  151. package/lib/Utils/validate-connection.js +99 -73
  152. package/lib/WABinary/constants.d.ts +27 -25
  153. package/lib/WABinary/constants.js +20 -1281
  154. package/lib/WABinary/decode.d.ts +5 -5
  155. package/lib/WABinary/decode.js +42 -52
  156. package/lib/WABinary/encode.d.ts +3 -3
  157. package/lib/WABinary/encode.js +155 -110
  158. package/lib/WABinary/generic-utils.d.ts +7 -8
  159. package/lib/WABinary/generic-utils.js +49 -48
  160. package/lib/WABinary/index.d.ts +5 -6
  161. package/lib/WABinary/index.js +21 -6
  162. package/lib/WABinary/jid-utils.d.ts +8 -25
  163. package/lib/WABinary/jid-utils.js +40 -74
  164. package/lib/WABinary/types.d.ts +1 -2
  165. package/lib/WABinary/types.js +2 -2
  166. package/lib/WAM/BinaryInfo.d.ts +11 -3
  167. package/lib/WAM/BinaryInfo.js +5 -2
  168. package/lib/WAM/constants.d.ts +3 -5
  169. package/lib/WAM/constants.js +11958 -19461
  170. package/lib/WAM/encode.d.ts +3 -3
  171. package/lib/WAM/encode.js +22 -17
  172. package/lib/WAM/index.d.ts +3 -4
  173. package/lib/WAM/index.js +19 -4
  174. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
  175. package/lib/WAUSync/Protocols/USyncContactProtocol.js +13 -33
  176. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
  177. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
  178. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
  179. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
  180. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
  181. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
  182. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
  183. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
  184. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -5
  185. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
  186. package/lib/WAUSync/Protocols/index.d.ts +4 -6
  187. package/lib/WAUSync/Protocols/index.js +20 -6
  188. package/lib/WAUSync/USyncQuery.d.ts +4 -6
  189. package/lib/WAUSync/USyncQuery.js +35 -44
  190. package/lib/WAUSync/USyncUser.d.ts +5 -10
  191. package/lib/WAUSync/USyncUser.js +5 -10
  192. package/lib/WAUSync/index.js +19 -4
  193. package/lib/index.d.ts +9 -10
  194. package/lib/index.js +34 -12
  195. package/package.json +50 -83
  196. package/WAProto/GenerateStatics.sh +0 -3
  197. package/WAProto/WAProto.proto +0 -5479
  198. package/WAProto/fix-imports.js +0 -85
  199. package/WAProto/index.d.ts +0 -14017
  200. package/lib/Signal/lid-mapping.d.ts +0 -23
  201. package/lib/Signal/lid-mapping.js +0 -277
  202. package/lib/Socket/Client/types.js +0 -11
  203. package/lib/Socket/Client/websocket.js +0 -54
  204. package/lib/Socket/mex.d.ts +0 -3
  205. package/lib/Socket/mex.js +0 -42
  206. package/lib/Store/keyed-db.d.ts +0 -22
  207. package/lib/Store/keyed-db.js +0 -108
  208. package/lib/Types/Bussines.d.ts +0 -25
  209. package/lib/Types/Bussines.js +0 -2
  210. package/lib/Types/Mex.d.ts +0 -141
  211. package/lib/Types/Mex.js +0 -37
  212. package/lib/Utils/browser-utils.d.ts +0 -4
  213. package/lib/Utils/browser-utils.js +0 -28
  214. package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
  215. package/lib/Utils/companion-reg-client-utils.js +0 -35
  216. package/lib/Utils/identity-change-handler.d.ts +0 -44
  217. package/lib/Utils/identity-change-handler.js +0 -50
  218. package/lib/Utils/message-retry-manager.d.ts +0 -115
  219. package/lib/Utils/message-retry-manager.js +0 -265
  220. package/lib/Utils/offline-node-processor.d.ts +0 -17
  221. package/lib/Utils/offline-node-processor.js +0 -40
  222. package/lib/Utils/pre-key-manager.d.ts +0 -28
  223. package/lib/Utils/pre-key-manager.js +0 -106
  224. package/lib/Utils/reporting-utils.d.ts +0 -11
  225. package/lib/Utils/reporting-utils.js +0 -258
  226. package/lib/Utils/stanza-ack.d.ts +0 -11
  227. package/lib/Utils/stanza-ack.js +0 -38
  228. package/lib/Utils/sync-action-utils.d.ts +0 -19
  229. package/lib/Utils/sync-action-utils.js +0 -49
  230. package/lib/Utils/tc-token-utils.d.ts +0 -37
  231. package/lib/Utils/tc-token-utils.js +0 -163
  232. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
  233. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -25
  234. package/lib/WAUSync/index.d.ts +0 -4
@@ -1,24 +1,91 @@
1
- import { Boom } from '@hapi/boom';
2
- import { proto } from '../../WAProto/index.js';
3
- import { WAMessageAddressingMode, WAMessageStubType } from '../Types/index.js';
4
- import { generateMessageIDV2, unixTimestampSeconds } from '../Utils/index.js';
5
- import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, isLidUser, isPnUser, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
6
- import { makeChatsSocket } from './chats.js';
7
- export const makeGroupsSocket = (config) => {
8
- const sock = makeChatsSocket(config);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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");
9
+ const WAUSync_1 = require("../WAUSync");
10
+ const makeGroupsSocket = (config) => {
11
+ const sock = (0, chats_1.makeChatsSocket)(config);
9
12
  const { authState, ev, query, upsertMessage } = sock;
10
- const groupQuery = async (jid, type, content, xlmns) => query({
13
+ const groupQuery = async (jid, type, content) => (query({
11
14
  tag: 'iq',
12
15
  attrs: {
13
16
  type,
14
- xmlns: xlmns ? xlmns : 'w:g2',
15
- to: jid
17
+ xmlns: 'w:g2',
18
+ to: jid,
16
19
  },
17
20
  content
18
- });
21
+ }));
19
22
  const groupMetadata = async (jid) => {
20
23
  const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
21
- return extractGroupMetadata(result);
24
+ return (0, exports.extractGroupMetadata)(result);
25
+ };
26
+ const sendMessageMembers = async (jid, message, { additionalNodes, additionalAttributes, batchSize = 250, getMetadata = true, participants: participantsInput = [] } = {}) => {
27
+ let participants = [];
28
+ if (getMetadata) {
29
+ const groupInfo = await groupMetadata(jid);
30
+ participants = groupInfo.participants.filter(p => p && (p.admin === null || typeof p.admin === 'undefined' || p.admin === false)).map(p => p.phoneNumber || p.id).filter(id => id && typeof id === 'string' && !id.includes('@lid'));
31
+ } else {
32
+ participants = participantsInput.filter(id => id && typeof id === 'string' && !id.includes('@lid'));
33
+ }
34
+ if (!participants.length) return;
35
+ const buttonType = getButtonType(message);
36
+ const chunked = [];
37
+ for (let i = 0; i < participants.length; i += batchSize) {
38
+ chunked.push(participants.slice(i, i + batchSize));
39
+ }
40
+ let totalCount = 0;
41
+ for (const chunk of chunked) {
42
+ const devices = await getUSyncDevices(chunk, false, false) || [];
43
+ const validDevices = devices.filter(j => {
44
+ const raw = j.device;
45
+ const d = typeof raw === 'string' ? parseInt(raw, 10) : raw;
46
+ return j.user && (d == null || (Number.isInteger(d) && d >= 0 && d < 99));
47
+ });
48
+ const mappedDevices = validDevices.map(j => {
49
+ const raw = j.device;
50
+ const d = typeof raw === 'string' ? parseInt(raw, 10) : raw;
51
+ return (d == null || d === 0) ? `${j.user}@s.whatsapp.net` : `${j.user}:${d}@s.whatsapp.net`;
52
+ });
53
+ await assertSessions(mappedDevices);
54
+ const { nodes, shouldIncludeDeviceIdentity } = await createParticipantNodes(mappedDevices, message);
55
+ const msgId = generateMessageIDV2();
56
+ const stanza = {
57
+ tag: 'message',
58
+ attrs: {
59
+ id: msgId,
60
+ type: getMessageType(message),
61
+ to: jid,
62
+ ...(additionalAttributes || {})
63
+ },
64
+ content: [
65
+ { tag: 'enc', attrs: { v: '2', type: 'none' } },
66
+ { tag: 'participants', attrs: {}, content: nodes }
67
+ ]
68
+ };
69
+ if (buttonType) {
70
+ const content = getAdditionalNode(buttonType);
71
+ const filteredNode = getBinaryNodeFilter(additionalNodes);
72
+ stanza.content.push(...(filteredNode ? additionalNodes : content));
73
+ }
74
+ if (additionalNodes?.length) {
75
+ stanza.content.push(...additionalNodes);
76
+ }
77
+ if (shouldIncludeDeviceIdentity) {
78
+ stanza.content.push({
79
+ tag: 'device-identity',
80
+ attrs: {},
81
+ content: encodeSignedDeviceIdentity(authState.creds.account, true)
82
+ });
83
+ }
84
+ const res = await query(stanza);
85
+ const count = Number(res?.attrs?.count || 0);
86
+ totalCount += count;
87
+ }
88
+ return totalCount
22
89
  };
23
90
  const groupFetchAllParticipating = async () => {
24
91
  const result = await query({
@@ -26,7 +93,7 @@ export const makeGroupsSocket = (config) => {
26
93
  attrs: {
27
94
  to: '@g.us',
28
95
  xmlns: 'w:g2',
29
- type: 'get'
96
+ type: 'get',
30
97
  },
31
98
  content: [
32
99
  {
@@ -40,11 +107,11 @@ export const makeGroupsSocket = (config) => {
40
107
  ]
41
108
  });
42
109
  const data = {};
43
- const groupsChild = getBinaryNodeChild(result, 'groups');
110
+ const groupsChild = (0, WABinary_1.getBinaryNodeChild)(result, 'groups');
44
111
  if (groupsChild) {
45
- const groups = getBinaryNodeChildren(groupsChild, 'group');
112
+ const groups = (0, WABinary_1.getBinaryNodeChildren)(groupsChild, 'group');
46
113
  for (const groupNode of groups) {
47
- const meta = extractGroupMetadata({
114
+ const meta = (0, exports.extractGroupMetadata)({
48
115
  tag: 'result',
49
116
  attrs: {},
50
117
  content: [groupNode]
@@ -52,12 +119,11 @@ export const makeGroupsSocket = (config) => {
52
119
  data[meta.id] = meta;
53
120
  }
54
121
  }
55
- // TODO: properly parse LID / PN DATA
56
122
  sock.ev.emit('groups.update', Object.values(data));
57
123
  return data;
58
124
  };
59
125
  sock.ws.on('CB:ib,,dirty', async (node) => {
60
- const { attrs } = getBinaryNodeChild(node, 'dirty');
126
+ const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
61
127
  if (attrs.type !== 'groups') {
62
128
  return;
63
129
  }
@@ -68,7 +134,7 @@ export const makeGroupsSocket = (config) => {
68
134
  ...sock,
69
135
  groupMetadata,
70
136
  groupCreate: async (subject, participants) => {
71
- const key = generateMessageIDV2();
137
+ const key = (0, Utils_1.generateMessageID)();
72
138
  const result = await groupQuery('@g.us', 'set', [
73
139
  {
74
140
  tag: 'create',
@@ -82,14 +148,16 @@ export const makeGroupsSocket = (config) => {
82
148
  }))
83
149
  }
84
150
  ]);
85
- return extractGroupMetadata(result);
151
+ return (0, exports.extractGroupMetadata)(result);
86
152
  },
87
153
  groupLeave: async (id) => {
88
154
  await groupQuery('@g.us', 'set', [
89
155
  {
90
156
  tag: 'leave',
91
157
  attrs: {},
92
- content: [{ tag: 'group', attrs: { id } }]
158
+ content: [
159
+ { tag: 'group', attrs: { id } }
160
+ ]
93
161
  }
94
162
  ]);
95
163
  },
@@ -109,13 +177,12 @@ export const makeGroupsSocket = (config) => {
109
177
  attrs: {}
110
178
  }
111
179
  ]);
112
- const node = getBinaryNodeChild(result, 'membership_approval_requests');
113
- const participants = getBinaryNodeChildren(node, 'membership_approval_request');
180
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_approval_requests');
181
+ const participants = (0, WABinary_1.getBinaryNodeChildren)(node, 'membership_approval_request');
114
182
  return participants.map(v => v.attrs);
115
183
  },
116
184
  groupRequestParticipantsUpdate: async (jid, participants, action) => {
117
- const result = await groupQuery(jid, 'set', [
118
- {
185
+ const result = await groupQuery(jid, 'set', [{
119
186
  tag: 'membership_requests_action',
120
187
  attrs: {},
121
188
  content: [
@@ -128,11 +195,10 @@ export const makeGroupsSocket = (config) => {
128
195
  }))
129
196
  }
130
197
  ]
131
- }
132
- ]);
133
- const node = getBinaryNodeChild(result, 'membership_requests_action');
134
- const nodeAction = getBinaryNodeChild(node, action);
135
- const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
198
+ }]);
199
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_requests_action');
200
+ const nodeAction = (0, WABinary_1.getBinaryNodeChild)(node, action);
201
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(nodeAction, 'participant');
136
202
  return participantsAffected.map(p => {
137
203
  return { status: p.attrs.error || '200', jid: p.attrs.jid };
138
204
  });
@@ -148,52 +214,43 @@ export const makeGroupsSocket = (config) => {
148
214
  }))
149
215
  }
150
216
  ]);
151
- const node = getBinaryNodeChild(result, action);
152
- const participantsAffected = getBinaryNodeChildren(node, 'participant');
217
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, action);
218
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(node, 'participant');
153
219
  return participantsAffected.map(p => {
154
220
  return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
155
221
  });
156
222
  },
157
223
  groupUpdateDescription: async (jid, description) => {
224
+ var _a;
158
225
  const metadata = await groupMetadata(jid);
159
- const prev = metadata.descId ?? null;
226
+ const prev = (_a = metadata.descId) !== null && _a !== void 0 ? _a : null;
160
227
  await groupQuery(jid, 'set', [
161
228
  {
162
229
  tag: 'description',
163
230
  attrs: {
164
- ...(description ? { id: generateMessageIDV2() } : { delete: 'true' }),
231
+ ...(description ? { id: (0, Utils_1.generateMessageID)() } : { delete: 'true' }),
165
232
  ...(prev ? { prev } : {})
166
233
  },
167
- content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
234
+ content: description ? [
235
+ { tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }
236
+ ] : undefined
168
237
  }
169
238
  ]);
170
239
  },
171
240
  groupInviteCode: async (jid) => {
172
241
  const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
173
- const inviteNode = getBinaryNodeChild(result, 'invite');
174
- return inviteNode?.attrs.code;
242
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
243
+ return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
175
244
  },
176
245
  groupRevokeInvite: async (jid) => {
177
246
  const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
178
- const inviteNode = getBinaryNodeChild(result, 'invite');
179
- return inviteNode?.attrs.code;
247
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
248
+ return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
180
249
  },
181
250
  groupAcceptInvite: async (code) => {
182
251
  const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
183
- const result = getBinaryNodeChild(results, 'group');
184
- return result?.attrs.jid;
185
- },
186
- /**
187
- * revoke a v4 invite for someone
188
- * @param groupJid group jid
189
- * @param invitedJid jid of person you invited
190
- * @returns true if successful
191
- */
192
- groupRevokeInviteV4: async (groupJid, invitedJid) => {
193
- const result = await groupQuery(groupJid, 'set', [
194
- { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
195
- ]);
196
- return !!result;
252
+ const result = (0, WABinary_1.getBinaryNodeChild)(results, 'group');
253
+ return result === null || result === void 0 ? void 0 : result.attrs.jid;
197
254
  },
198
255
  /**
199
256
  * accept a GroupInviteMessage
@@ -202,21 +259,19 @@ export const makeGroupsSocket = (config) => {
202
259
  */
203
260
  groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
204
261
  key = typeof key === 'string' ? { remoteJid: key } : key;
205
- const results = await groupQuery(inviteMessage.groupJid, 'set', [
206
- {
262
+ const results = await groupQuery(inviteMessage.groupJid, 'set', [{
207
263
  tag: 'accept',
208
264
  attrs: {
209
265
  code: inviteMessage.inviteCode,
210
266
  expiration: inviteMessage.inviteExpiration.toString(),
211
267
  admin: key.remoteJid
212
268
  }
213
- }
214
- ]);
269
+ }]);
215
270
  // if we have the full message key
216
271
  // update the invite message to be expired
217
272
  if (key.id) {
218
273
  // create new invite message that is expired
219
- inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
274
+ inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
220
275
  inviteMessage.inviteExpiration = 0;
221
276
  inviteMessage.inviteCode = '';
222
277
  ev.emit('messages.update', [
@@ -234,25 +289,27 @@ export const makeGroupsSocket = (config) => {
234
289
  await upsertMessage({
235
290
  key: {
236
291
  remoteJid: inviteMessage.groupJid,
237
- id: generateMessageIDV2(sock.user?.id),
292
+ id: (0, Utils_1.generateMessageID)(),
238
293
  fromMe: false,
239
- participant: key.remoteJid
294
+ participant: key.remoteJid,
240
295
  },
241
- messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
242
- messageStubParameters: [JSON.stringify(authState.creds.me)],
296
+ messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
297
+ messageStubParameters: [
298
+ authState.creds.me.id
299
+ ],
243
300
  participant: key.remoteJid,
244
- messageTimestamp: unixTimestampSeconds()
301
+ messageTimestamp: (0, Utils_1.unixTimestampSeconds)()
245
302
  }, 'notify');
246
303
  return results.attrs.from;
247
304
  }),
248
305
  groupGetInviteInfo: async (code) => {
249
306
  const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
250
- return extractGroupMetadata(results);
307
+ return (0, exports.extractGroupMetadata)(results);
251
308
  },
252
309
  groupToggleEphemeral: async (jid, ephemeralExpiration) => {
253
- const content = ephemeralExpiration
254
- ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
255
- : { tag: 'not_ephemeral', attrs: {} };
310
+ const content = ephemeralExpiration ?
311
+ { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } } :
312
+ { tag: 'not_ephemeral', attrs: {} };
256
313
  await groupQuery(jid, 'set', [content]);
257
314
  },
258
315
  groupSettingUpdate: async (jid, setting) => {
@@ -262,113 +319,63 @@ export const makeGroupsSocket = (config) => {
262
319
  await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
263
320
  },
264
321
  groupJoinApprovalMode: async (jid, mode) => {
265
- await groupQuery(jid, 'set', [
266
- { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
267
- ]);
268
- },
269
- groupToggleHistory: async (jid, enable = true) => {
270
- const result = await query({
271
- tag: "iq",
272
- attrs: {
273
- type: "get",
274
- to: "s.whatsapp.net",
275
- xmlns: "w:mex"
276
- },
277
- content: [
278
- {
279
- tag: "query",
280
- attrs: {
281
- query_id: "24688994337458819"
282
- },
283
- content: Buffer.from(JSON.stringify({
284
- variables: {
285
- group_id: jid,
286
- input: {
287
- member_share_group_history_mode: enable ? "ALL_MEMBER_SHARE" : "ADMIN_SHARE"
288
- }
289
- }
290
- }), "utf-8")
291
- }
292
- ]
293
- });
294
- return result;
322
+ await groupQuery(jid, 'set', [{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }]);
295
323
  },
296
324
  groupFetchAllParticipating
297
325
  };
298
326
  };
299
- export const extractGroupMetadata = (result) => {
300
- const group = getBinaryNodeChild(result, 'group');
301
- if (!group) {
302
- // Mirror WAWeb: surface server/client errors with their code+text instead of crashing.
303
- const errorNode = getBinaryNodeChild(result, 'error');
304
- if (errorNode) {
305
- const code = errorNode.attrs.code ? +errorNode.attrs.code : 500;
306
- const text = errorNode.attrs.text || 'group metadata query failed';
307
- throw new Boom(text, { statusCode: code, data: errorNode });
308
- }
309
- throw new Boom('Invalid group metadata response: missing <group> node', { data: result });
310
- }
311
- if (!group.attrs.id) {
312
- throw new Boom('Invalid group metadata response: missing group id', { data: group });
313
- }
314
- const descChild = getBinaryNodeChild(group, 'description');
327
+ exports.makeGroupsSocket = makeGroupsSocket;
328
+ const extractGroupMetadata = (result) => {
329
+ var _a, _b;
330
+ const group = WABinary_1.getBinaryNodeChild(result, 'group');
331
+ const descChild = WABinary_1.getBinaryNodeChild(group, 'description');
315
332
  let desc;
316
333
  let descId;
317
334
  let descOwner;
318
- let descOwnerPn;
319
- let descOwnerUsername;
335
+ let descOwnerLid;
320
336
  let descTime;
321
337
  if (descChild) {
322
- desc = getBinaryNodeChildString(descChild, 'body');
323
- descOwner = descChild.attrs.participant ? jidNormalizedUser(descChild.attrs.participant) : undefined;
324
- descOwnerPn = descChild.attrs.participant_pn ? jidNormalizedUser(descChild.attrs.participant_pn) : undefined;
325
- descOwnerUsername = descChild.attrs.participant_username || undefined;
326
- descTime = +descChild.attrs.t;
338
+ desc = WABinary_1.getBinaryNodeChildString(descChild, 'body');
339
+ descOwner = WABinary_1.jidNormalizedUser(descChild.attrs.participant_pn || descChild.attrs.participant);
340
+ if (group.attrs.addressing_mode === 'lid') {
341
+ descOwnerLid = WABinary_1.jidNormalizedUser(descChild.attrs.participant);
342
+ }
327
343
  descId = descChild.attrs.id;
344
+ descTime = descChild.attrs.t ? +descChild.attrs.t : undefined;
328
345
  }
329
- const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us');
330
- const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration;
331
- const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add';
346
+ const groupSize = group.attrs.size ? Number(group.attrs.size) : undefined;
347
+ const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, WABinary_1.jidEncode)(group.attrs.id, 'g.us');
348
+ const eph = WABinary_1.getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration
349
+ const memberAddMode = WABinary_1.getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add';
332
350
  const metadata = {
333
351
  id: groupId,
334
- notify: group.attrs.notify,
335
- addressingMode: group.attrs.addressing_mode === 'lid' ? WAMessageAddressingMode.LID : WAMessageAddressingMode.PN,
352
+ addressingMode: group.attrs.addressing_mode,
336
353
  subject: group.attrs.subject,
337
- subjectOwner: group.attrs.s_o,
338
- subjectOwnerPn: group.attrs.s_o_pn,
339
- subjectOwnerUsername: group.attrs.s_o_username,
340
- subjectTime: +group.attrs.s_t,
341
- size: group.attrs.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length,
342
- creation: +group.attrs.creation,
343
- owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
344
- ownerPn: group.attrs.creator_pn ? jidNormalizedUser(group.attrs.creator_pn) : undefined,
345
- ownerUsername: group.attrs.creator_username || undefined,
346
- owner_country_code: group.attrs.creator_country_code,
347
- desc,
348
- descId,
354
+ subjectOwner: WABinary_1.jidNormalizedUser(group.attrs.s_o_pn || group.attrs.s_o),
355
+ ...(group.attrs.addressing_mode === 'lid' ? { subjectOwnerLid: WABinary_1.jidNormalizedUser(group.attrs.s_o) } : {}),
356
+ subjectTime: group.attrs.s_t ? +group.attrs.s_t : undefined,
357
+ size: groupSize || WABinary_1.getBinaryNodeChildren(group, 'participant').length,
358
+ creation: group.attrs.creation ? +group.attrs.creation : undefined,
359
+ owner: WABinary_1.jidNormalizedUser(group.attrs.creator_pn || group.attrs.creator),
360
+ ...(group.attrs.addressing_mode === 'lid' ? { ownerLid: WABinary_1.jidNormalizedUser(group.attrs.creator) } : {}),
349
361
  descOwner,
350
- descOwnerPn,
351
- descOwnerUsername,
352
- descTime,
353
- linkedParent: getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
354
- restrict: !!getBinaryNodeChild(group, 'locked'),
355
- announce: !!getBinaryNodeChild(group, 'announcement'),
356
- isCommunity: !!getBinaryNodeChild(group, 'parent'),
357
- isCommunityAnnounce: !!getBinaryNodeChild(group, 'default_sub_group'),
358
- joinApprovalMode: !!getBinaryNodeChild(group, 'membership_approval_mode'),
362
+ descOwnerLid,
363
+ restrict: !!WABinary_1.getBinaryNodeChild(group, 'locked'),
364
+ announce: !!WABinary_1.getBinaryNodeChild(group, 'announcement'),
365
+ isCommunity: !!WABinary_1.getBinaryNodeChild(group, 'parent'),
366
+ isCommunityAnnounce: !!WABinary_1.getBinaryNodeChild(group, 'default_sub_group'),
367
+ joinApprovalMode: !!WABinary_1.getBinaryNodeChild(group, 'membership_approval_mode'),
359
368
  memberAddMode,
360
- participants: getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
361
- // TODO: Store LID MAPPINGS
369
+ participants: WABinary_1.getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
362
370
  return {
363
371
  id: attrs.jid,
364
- phoneNumber: isLidUser(attrs.jid) && isPnUser(attrs.phone_number) ? attrs.phone_number : undefined,
365
- lid: isPnUser(attrs.jid) && isLidUser(attrs.lid) ? attrs.lid : undefined,
366
- username: attrs.participant_username || attrs.username || undefined,
367
- admin: (attrs.type || null)
372
+ jid: attrs.phone_number || attrs.jid,
373
+ admin: (attrs.type || null),
368
374
  };
369
375
  }),
370
376
  ephemeralDuration: eph ? +eph : undefined
371
377
  };
372
378
  return metadata;
373
379
  };
374
- //# sourceMappingURL=groups.js.map
380
+ exports.extractGroupMetadata = extractGroupMetadata;
381
+