@pontalabs/baileys 1.0.10 → 1.1.0

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 (119) hide show
  1. package/README.md +96 -85
  2. package/lib/Defaults/connection.js +39 -0
  3. package/lib/Defaults/constants.js +50 -0
  4. package/lib/Defaults/history.js +13 -0
  5. package/lib/Defaults/index.js +36 -151
  6. package/lib/Defaults/media.js +43 -0
  7. package/lib/Defaults/phonenumber-mcc.json +221 -221
  8. package/lib/Defaults/prefix.js +12 -0
  9. package/lib/Defaults/vialeys-version.json +7 -0
  10. package/lib/Signal/Group/ciphertext-message.js +10 -15
  11. package/lib/Signal/Group/group-session-builder.js +34 -60
  12. package/lib/Signal/Group/group_cipher.js +69 -76
  13. package/lib/Signal/Group/index.js +41 -60
  14. package/lib/Signal/Group/keyhelper.js +12 -57
  15. package/lib/Signal/Group/sender-chain-key.js +20 -33
  16. package/lib/Signal/Group/sender-key-distribution-message.js +43 -48
  17. package/lib/Signal/Group/sender-key-message.js +58 -53
  18. package/lib/Signal/Group/sender-key-name.js +21 -31
  19. package/lib/Signal/Group/sender-key-record.js +21 -34
  20. package/lib/Signal/Group/sender-key-state.js +59 -106
  21. package/lib/Signal/Group/sender-message-key.js +16 -21
  22. package/lib/Signal/libsignal.js +282 -203
  23. package/lib/Signal/lid-mapping.js +164 -184
  24. package/lib/Socket/Client/index.js +31 -22
  25. package/lib/Socket/Client/types.js +9 -15
  26. package/lib/Socket/Client/websocket.js +42 -37
  27. package/lib/Socket/business.js +212 -336
  28. package/lib/Socket/chats.js +696 -940
  29. package/lib/Socket/community.js +454 -369
  30. package/lib/Socket/groups.js +278 -280
  31. package/lib/Socket/index.js +9 -21
  32. package/lib/Socket/messages-recv.js +1027 -1570
  33. package/lib/Socket/messages-send.js +1180 -1136
  34. package/lib/Socket/mex.js +59 -0
  35. package/lib/Socket/newsletter.js +193 -251
  36. package/lib/Socket/socket.js +758 -898
  37. package/lib/Store/index.js +35 -24
  38. package/lib/Store/make-cache-manager-store.js +53 -66
  39. package/lib/Store/make-in-memory-store.js +319 -325
  40. package/lib/Store/make-ordered-dictionary.js +49 -57
  41. package/lib/Store/object-repository.js +10 -15
  42. package/lib/Types/Auth.js +2 -3
  43. package/lib/Types/Bussines.js +2 -3
  44. package/lib/Types/Call.js +2 -3
  45. package/lib/Types/Chat.js +10 -9
  46. package/lib/Types/Contact.js +2 -3
  47. package/lib/Types/Events.js +2 -3
  48. package/lib/Types/GroupMetadata.js +2 -3
  49. package/lib/Types/Label.js +6 -12
  50. package/lib/Types/LabelAssociation.js +4 -13
  51. package/lib/Types/Message.js +10 -18
  52. package/lib/Types/MexUpdates.js +15 -18
  53. package/lib/Types/Newsletter.js +26 -34
  54. package/lib/Types/Product.js +2 -3
  55. package/lib/Types/Signal.js +2 -3
  56. package/lib/Types/Socket.js +2 -3
  57. package/lib/Types/State.js +8 -13
  58. package/lib/Types/USync.js +2 -3
  59. package/lib/Types/index.js +49 -40
  60. package/lib/Utils/auth-utils.js +190 -495
  61. package/lib/Utils/browser-utils.js +29 -0
  62. package/lib/Utils/business.js +177 -199
  63. package/lib/Utils/chat-utils.js +711 -624
  64. package/lib/Utils/crypto.js +116 -161
  65. package/lib/Utils/decode-wa-message.js +225 -321
  66. package/lib/Utils/event-buffer.js +363 -405
  67. package/lib/Utils/generics.js +318 -472
  68. package/lib/Utils/history.js +72 -76
  69. package/lib/Utils/index.js +49 -41
  70. package/lib/Utils/link-preview.js +59 -103
  71. package/lib/Utils/logger.js +4 -7
  72. package/lib/Utils/lt-hash.js +29 -42
  73. package/lib/Utils/make-mutex.js +26 -42
  74. package/lib/Utils/message-retry-manager.js +134 -160
  75. package/lib/Utils/messages-media.js +665 -731
  76. package/lib/Utils/messages.js +518 -1
  77. package/lib/Utils/noise-handler.js +127 -125
  78. package/lib/Utils/pre-key-manager.js +86 -0
  79. package/lib/Utils/process-message.js +739 -351
  80. package/lib/Utils/signal.js +146 -129
  81. package/lib/Utils/use-multi-file-auth-state.js +68 -135
  82. package/lib/Utils/validate-connection.js +183 -142
  83. package/lib/Utils/vialeys-event-stream.js +41 -0
  84. package/lib/WABinary/constants.js +1281 -1289
  85. package/lib/WABinary/decode.js +145 -200
  86. package/lib/WABinary/encode.js +149 -202
  87. package/lib/WABinary/generic-utils.js +79 -97
  88. package/lib/WABinary/index.js +36 -25
  89. package/lib/WABinary/jid-utils.js +91 -123
  90. package/lib/WABinary/types.js +2 -3
  91. package/lib/WAM/BinaryInfo.js +8 -13
  92. package/lib/WAM/constants.js +16584 -11464
  93. package/lib/WAM/encode.js +117 -133
  94. package/lib/WAM/index.js +34 -23
  95. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -69
  96. package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -25
  97. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +32 -44
  98. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +13 -23
  99. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -38
  100. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +17 -31
  101. package/lib/WAUSync/Protocols/index.js +37 -26
  102. package/lib/WAUSync/USyncQuery.js +66 -66
  103. package/lib/WAUSync/USyncUser.js +13 -18
  104. package/lib/WAUSync/index.js +34 -23
  105. package/lib/index.js +95 -28
  106. package/package.json +4 -3
  107. package/lib/Defaults/baileys-version.json +0 -3
  108. package/lib/Signal/Group/queue-job.d.ts +0 -1
  109. package/lib/Signal/Group/queue-job.js +0 -57
  110. package/lib/Socket/usync.d.ts +0 -37
  111. package/lib/Socket/usync.js +0 -83
  112. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  113. package/lib/Utils/baileys-event-stream.js +0 -70
  114. package/lib/Utils/signal-housekeeping.d.ts +0 -19
  115. package/lib/Utils/signal-housekeeping.js +0 -73
  116. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  117. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  118. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  119. package/lib/Utils/use-single-file-auth-state.js +0 -80
@@ -1,359 +1,357 @@
1
- "use strict"
2
- Object.defineProperty(exports, "__esModule", { value: true })
3
-
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
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { proto: proto } = require("../../WAProto");
4
+ const {
5
+ WAMessageStubType: WAMessageStubType,
6
+ WAMessageAddressingMode: WAMessageAddressingMode,
7
+ } = require("../Types");
8
+ const {
9
+ generateMessageID: generateMessageID,
10
+ unixTimestampSeconds: unixTimestampSeconds,
11
+ } = require("../Utils");
12
+ const {
13
+ getBinaryNodeChild: getBinaryNodeChild,
14
+ getBinaryNodeChildren: getBinaryNodeChildren,
15
+ getBinaryNodeChildString: getBinaryNodeChildString,
16
+ jidEncode: jidEncode,
17
+ jidNormalizedUser: jidNormalizedUser,
18
+ } = require("../WABinary");
19
+ const { makeChatsSocket: makeChatsSocket } = require("./chats");
10
20
  const makeGroupsSocket = (config) => {
11
- const sock = chats_1.makeChatsSocket(config)
12
- const { authState, ev, query, upsertMessage } = sock
13
-
14
- const groupQuery = async (jid, type, content) => (query({
15
- tag: 'iq',
16
- attrs: {
17
- type,
18
- xmlns: 'w:g2',
19
- to: jid,
20
- },
21
- content
22
- }))
23
-
21
+ const conn = makeChatsSocket(config);
22
+ const {
23
+ authState: authState,
24
+ ev: ev,
25
+ query: query,
26
+ cleanDirtyBits: cleanDirtyBits,
27
+ upsertMessage: upsertMessage,
28
+ } = conn;
29
+ const groupQuery = async (jid, type, content) =>
30
+ query({
31
+ tag: "iq",
32
+ attrs: { type: type, xmlns: "w:g2", to: jid },
33
+ content: content,
34
+ });
24
35
  const groupMetadata = async (jid) => {
25
- const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }])
26
- return extractGroupMetadata(result)
27
- }
28
-
36
+ const result = await groupQuery(jid, "get", [
37
+ { tag: "query", attrs: { request: "interactive" } },
38
+ ]);
39
+ return extractGroupMetadata(result);
40
+ };
29
41
  const groupFetchAllParticipating = async () => {
30
42
  const result = await query({
31
- tag: 'iq',
32
- attrs: {
33
- to: '@g.us',
34
- xmlns: 'w:g2',
35
- type: 'get',
36
- },
43
+ tag: "iq",
44
+ attrs: { to: "@g.us", xmlns: "w:g2", type: "get" },
37
45
  content: [
38
46
  {
39
- tag: 'participating',
47
+ tag: "participating",
40
48
  attrs: {},
41
49
  content: [
42
- { tag: 'participants', attrs: {} },
43
- { tag: 'description', attrs: {} }
44
- ]
45
- }
46
- ]
47
- })
48
-
49
- const data = {}
50
- const groupsChild = WABinary_1.getBinaryNodeChild(result, 'groups')
51
-
50
+ { tag: "participants", attrs: {} },
51
+ { tag: "description", attrs: {} },
52
+ ],
53
+ },
54
+ ],
55
+ });
56
+ const data = {};
57
+ const groupsChild = getBinaryNodeChild(result, "groups");
52
58
  if (groupsChild) {
53
- const groups = WABinary_1.getBinaryNodeChildren(groupsChild, 'group')
59
+ const groups = getBinaryNodeChildren(groupsChild, "group");
54
60
  for (const groupNode of groups) {
55
61
  const meta = extractGroupMetadata({
56
- tag: 'result',
62
+ tag: "result",
57
63
  attrs: {},
58
- content: [groupNode]
59
- })
60
- data[meta.id] = meta
64
+ content: [groupNode],
65
+ });
66
+ data[meta.id] = meta;
61
67
  }
62
68
  }
63
-
64
- sock.ev.emit('groups.update', Object.values(data))
65
- return data
66
- }
67
-
68
- sock.ws.on('CB:ib,,dirty', async (node) => {
69
- const { attrs } = WABinary_1.getBinaryNodeChild(node, 'dirty')
70
- if (attrs.type !== 'groups') {
71
- return
69
+ conn.ev.emit("groups.update", Object.values(data));
70
+ return data;
71
+ };
72
+ conn.ws.on("CB:ib,,dirty", async (node) => {
73
+ const { attrs: attrs } = getBinaryNodeChild(node, "dirty");
74
+ if (attrs.type !== "groups") {
75
+ return;
72
76
  }
73
-
74
- await groupFetchAllParticipating()
75
- await sock.cleanDirtyBits('groups')
76
- })
77
-
77
+ await groupFetchAllParticipating();
78
+ await cleanDirtyBits("groups");
79
+ });
78
80
  return {
79
- ...sock,
80
- groupQuery,
81
- groupMetadata,
81
+ ...conn,
82
+ groupQuery: groupQuery,
83
+ groupMetadata: groupMetadata,
82
84
  groupCreate: async (subject, participants) => {
83
- const key = Utils_1.generateMessageID()
84
-
85
- const result = await groupQuery('@g.us', 'set', [
85
+ const key = generateMessageID();
86
+ const result = await groupQuery("@g.us", "set", [
86
87
  {
87
- tag: 'create',
88
- attrs: {
89
- subject,
90
- key
91
- },
92
- content: participants.map(jid => ({
93
- tag: 'participant',
94
- attrs: { jid }
95
- }))
96
- }
97
- ])
98
-
99
- return extractGroupMetadata(result)
88
+ tag: "create",
89
+ attrs: { subject: subject, key: key },
90
+ content: participants.map((jid) => ({
91
+ tag: "participant",
92
+ attrs: { jid: jid },
93
+ })),
94
+ },
95
+ ]);
96
+ return extractGroupMetadata(result);
100
97
  },
101
98
  groupLeave: async (id) => {
102
- await groupQuery('@g.us', 'set', [
99
+ await groupQuery("@g.us", "set", [
103
100
  {
104
- tag: 'leave',
101
+ tag: "leave",
105
102
  attrs: {},
106
- content: [
107
- { tag: 'group', attrs: { id } }
108
- ]
109
- }
110
- ])
103
+ content: [{ tag: "group", attrs: { id: id } }],
104
+ },
105
+ ]);
111
106
  },
112
107
  groupUpdateSubject: async (jid, subject) => {
113
- await groupQuery(jid, 'set', [
114
- {
115
- tag: 'subject',
116
- attrs: {},
117
- content: Buffer.from(subject, 'utf-8')
118
- }
119
- ])
108
+ await groupQuery(jid, "set", [
109
+ { tag: "subject", attrs: {}, content: Buffer.from(subject, "utf-8") },
110
+ ]);
120
111
  },
121
112
  groupRequestParticipantsList: async (jid) => {
122
- const result = await groupQuery(jid, 'get', [
123
- {
124
- tag: 'membership_approval_requests',
125
- attrs: {}
126
- }
127
- ])
128
-
129
- const node = WABinary_1.getBinaryNodeChild(result, 'membership_approval_requests')
130
- const participants = WABinary_1.getBinaryNodeChildren(node, 'membership_approval_request')
131
-
132
- return participants.map(v => v.attrs)
113
+ const result = await groupQuery(jid, "get", [
114
+ { tag: "membership_approval_requests", attrs: {} },
115
+ ]);
116
+ const node = getBinaryNodeChild(result, "membership_approval_requests");
117
+ const participants = getBinaryNodeChildren(node, "membership_approval_request");
118
+ return participants.map((v) => v.attrs);
133
119
  },
134
120
  groupRequestParticipantsUpdate: async (jid, participants, action) => {
135
- const result = await groupQuery(jid, 'set', [{
136
- tag: 'membership_requests_action',
121
+ const result = await groupQuery(jid, "set", [
122
+ {
123
+ tag: "membership_requests_action",
137
124
  attrs: {},
138
125
  content: [
139
126
  {
140
127
  tag: action,
141
128
  attrs: {},
142
- content: participants.map(jid => ({
143
- tag: 'participant',
144
- attrs: { jid }
145
- }))
146
- }
147
- ]
148
- }])
149
-
150
- const node = WABinary_1.getBinaryNodeChild(result, 'membership_requests_action')
151
- const nodeAction = WABinary_1.getBinaryNodeChild(node, action)
152
- const participantsAffected = WABinary_1.getBinaryNodeChildren(nodeAction, 'participant')
153
-
154
- return participantsAffected.map(p => {
155
- return { status: p.attrs.error || '200', jid: p.attrs.jid }
156
- })
129
+ content: participants.map((jid) => ({
130
+ tag: "participant",
131
+ attrs: { jid: jid },
132
+ })),
133
+ },
134
+ ],
135
+ },
136
+ ]);
137
+ const node = getBinaryNodeChild(result, "membership_requests_action");
138
+ const nodeAction = getBinaryNodeChild(node, action);
139
+ const participantsAffected = getBinaryNodeChildren(nodeAction, "participant");
140
+ return participantsAffected.map((p) => ({
141
+ status: p.attrs.error || "200",
142
+ jid: p.attrs.jid,
143
+ }));
157
144
  },
158
145
  groupParticipantsUpdate: async (jid, participants, action) => {
159
- const result = await groupQuery(jid, 'set', [
146
+ const result = await groupQuery(jid, "set", [
160
147
  {
161
148
  tag: action,
162
149
  attrs: {},
163
- content: participants.map(jid => ({
164
- tag: 'participant',
165
- attrs: { jid }
166
- }))
167
- }
168
- ])
169
- const node = WABinary_1.getBinaryNodeChild(result, action)
170
- const participantsAffected = WABinary_1.getBinaryNodeChildren(node, 'participant')
171
-
172
- return participantsAffected.map(p => {
173
- return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p }
174
- })
150
+ content: participants.map((jid) => ({
151
+ tag: "participant",
152
+ attrs: { jid: jid },
153
+ })),
154
+ },
155
+ ]);
156
+ const node = getBinaryNodeChild(result, action);
157
+ const participantsAffected = getBinaryNodeChildren(node, "participant");
158
+ return participantsAffected.map((p) => ({
159
+ status: p.attrs.error || "200",
160
+ jid: p.attrs.jid,
161
+ content: p,
162
+ }));
175
163
  },
176
164
  groupUpdateDescription: async (jid, description) => {
177
- const metadata = await groupMetadata(jid)
178
- const prev = metadata.descId ? metadata.descId : null
179
-
180
- await groupQuery(jid, 'set', [
165
+ const metadata = await groupMetadata(jid);
166
+ const prev = metadata.descId ? metadata.descId : null;
167
+ await groupQuery(jid, "set", [
181
168
  {
182
- tag: 'description',
169
+ tag: "description",
183
170
  attrs: {
184
- ...(description ? { id: Utils_1.generateMessageID() } : { delete: 'true' }),
185
- ...(prev ? { prev } : {})
171
+ ...(description ? { id: generateMessageID() } : { delete: "true" }),
172
+ ...(prev ? { prev: prev } : {}),
186
173
  },
187
- content: description ? [
188
- { tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }
189
- ] : undefined
190
- }
191
- ])
174
+ content: description
175
+ ? [
176
+ {
177
+ tag: "body",
178
+ attrs: {},
179
+ content: Buffer.from(description, "utf-8"),
180
+ },
181
+ ]
182
+ : undefined,
183
+ },
184
+ ]);
192
185
  },
193
186
  groupInviteCode: async (jid) => {
194
- const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }])
195
- const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite')
196
-
197
- return inviteNode?.attrs?.code
187
+ const result = await groupQuery(jid, "get", [{ tag: "invite", attrs: {} }]);
188
+ const inviteNode = getBinaryNodeChild(result, "invite");
189
+ return inviteNode?.attrs?.code;
198
190
  },
199
191
  groupRevokeInvite: async (jid) => {
200
- const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }])
201
- const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite')
202
-
203
- return inviteNode?.attrs?.code
192
+ const result = await groupQuery(jid, "set", [{ tag: "invite", attrs: {} }]);
193
+ const inviteNode = getBinaryNodeChild(result, "invite");
194
+ return inviteNode?.attrs?.code;
204
195
  },
205
196
  groupAcceptInvite: async (code) => {
206
- const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }])
207
- const result = WABinary_1.getBinaryNodeChild(results, 'group')
208
-
209
- return result?.attrs?.jid
197
+ const results = await groupQuery("@g.us", "set", [
198
+ { tag: "invite", attrs: { code: code } },
199
+ ]);
200
+ const result = getBinaryNodeChild(results, "group");
201
+ return result?.attrs?.jid;
210
202
  },
211
- /**
212
- * revoke a v4 invite for someone
213
- * @param groupJid group jid
214
- * @param invitedJid jid of person you invited
215
- * @returns true if successful
216
- */
217
203
  groupRevokeInviteV4: async (groupJid, invitedJid) => {
218
- const result = await groupQuery(groupJid, 'set', [{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }])
219
-
220
- return !!result
204
+ const result = await groupQuery(groupJid, "set", [
205
+ {
206
+ tag: "revoke",
207
+ attrs: {},
208
+ content: [{ tag: "participant", attrs: { jid: invitedJid } }],
209
+ },
210
+ ]);
211
+ return !!result;
221
212
  },
222
- /**
223
- * accept a GroupInviteMessage
224
- * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
225
- * @param inviteMessage the message to accept
226
- */
227
213
  groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
228
- key = typeof key === 'string' ? { remoteJid: key } : key
229
- const results = await groupQuery(inviteMessage.groupJid, 'set', [{
230
- tag: 'accept',
214
+ key = typeof key === "string" ? { remoteJid: key } : key;
215
+ const results = await groupQuery(inviteMessage.groupJid, "set", [
216
+ {
217
+ tag: "accept",
231
218
  attrs: {
232
219
  code: inviteMessage.inviteCode,
233
220
  expiration: inviteMessage.inviteExpiration.toString(),
234
- admin: key.remoteJid
235
- }
236
- }])
237
-
238
- // if we have the full message key
239
- // update the invite message to be expired
221
+ admin: key.remoteJid,
222
+ },
223
+ },
224
+ ]);
240
225
  if (key.id) {
241
- // create new invite message that is expired
242
- inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage)
243
- inviteMessage.inviteExpiration = 0
244
- inviteMessage.inviteCode = ''
245
- ev.emit('messages.update', [
226
+ inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
227
+ inviteMessage.inviteExpiration = 0;
228
+ inviteMessage.inviteCode = "";
229
+ ev.emit("messages.update", [
246
230
  {
247
- key,
248
- update: {
249
- message: {
250
- groupInviteMessage: inviteMessage
251
- }
252
- }
253
- }
254
- ])
231
+ key: key,
232
+ update: { message: { groupInviteMessage: inviteMessage } },
233
+ },
234
+ ]);
255
235
  }
256
-
257
- // generate the group add message
258
- await upsertMessage({
259
- key: {
260
- remoteJid: inviteMessage.groupJid,
261
- id: Utils_1.generateMessageID(authState.creds.me?.id),
262
- fromMe: false,
236
+ await upsertMessage(
237
+ {
238
+ key: {
239
+ remoteJid: inviteMessage.groupJid,
240
+ id: generateMessageID(conn.user?.id),
241
+ fromMe: false,
242
+ participant: key.remoteJid,
243
+ },
244
+ messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
245
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
263
246
  participant: key.remoteJid,
247
+ messageTimestamp: unixTimestampSeconds(),
264
248
  },
265
- messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
266
- messageStubParameters: [
267
- authState.creds.me.id
268
- ],
269
- participant: key.remoteJid,
270
- messageTimestamp: Utils_1.unixTimestampSeconds()
271
- }, 'notify')
272
-
273
- return results.attrs.from
249
+ "notify"
250
+ );
251
+ return results.attrs.from;
274
252
  }),
275
253
  groupGetInviteInfo: async (code) => {
276
- const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }])
277
-
278
- return extractGroupMetadata(results)
254
+ const results = await groupQuery("@g.us", "get", [
255
+ { tag: "invite", attrs: { code: code } },
256
+ ]);
257
+ return extractGroupMetadata(results);
279
258
  },
280
259
  groupToggleEphemeral: async (jid, ephemeralExpiration) => {
281
- const content = ephemeralExpiration ?
282
- { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } } :
283
- { tag: 'not_ephemeral', attrs: {} }
284
- await groupQuery(jid, 'set', [content])
260
+ const content = ephemeralExpiration
261
+ ? {
262
+ tag: "ephemeral",
263
+ attrs: { expiration: ephemeralExpiration.toString() },
264
+ }
265
+ : { tag: "not_ephemeral", attrs: {} };
266
+ await groupQuery(jid, "set", [content]);
285
267
  },
286
268
  groupSettingUpdate: async (jid, setting) => {
287
- await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }])
269
+ await groupQuery(jid, "set", [{ tag: setting, attrs: {} }]);
288
270
  },
289
271
  groupMemberAddMode: async (jid, mode) => {
290
- await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }])
272
+ await groupQuery(jid, "set", [{ tag: "member_add_mode", attrs: {}, content: mode }]);
291
273
  },
292
274
  groupJoinApprovalMode: async (jid, mode) => {
293
- await groupQuery(jid, 'set', [{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }])
275
+ await groupQuery(jid, "set", [
276
+ {
277
+ tag: "membership_approval_mode",
278
+ attrs: {},
279
+ content: [{ tag: "group_join", attrs: { state: mode } }],
280
+ },
281
+ ]);
294
282
  },
295
- groupFetchAllParticipating
296
- }
297
- }
298
-
283
+ groupFetchAllParticipating: groupFetchAllParticipating,
284
+ };
285
+ };
299
286
  const extractGroupMetadata = (result) => {
300
- const group = WABinary_1.getBinaryNodeChild(result, 'group')
301
- const descChild = WABinary_1.getBinaryNodeChild(group, 'description')
302
- const mode = group.attrs.addressing_mode === 'lid' ? Types_1.WAMessageAddressingMode.LID : Types_1.WAMessageAddressingMode.PN
303
-
304
- let desc
305
- let descId
306
- let descOwner
307
- let descOwnerLid
308
-
287
+ const group = getBinaryNodeChild(result, "group");
288
+ const descChild = getBinaryNodeChild(group, "description");
289
+ const mode =
290
+ group.attrs.addressing_mode === WAMessageAddressingMode.LID
291
+ ? WAMessageAddressingMode.LID
292
+ : WAMessageAddressingMode.PN;
293
+ let desc;
294
+ let descId;
295
+ let descOwner;
296
+ let descOwnerAlt;
309
297
  if (descChild) {
310
- desc = WABinary_1.getBinaryNodeChildString(descChild, 'body')
311
- descId = descChild.attrs.id
312
- descOwner = mode === Types_1.WAMessageAddressingMode.LID ? WABinary_1.jidNormalizedUser(descChild.attrs.participant_pn) : WABinary_1.jidNormalizedUser(descChild.attrs.participant)
313
- descOwnerLid = mode === Types_1.WAMessageAddressingMode.LID ? WABinary_1.jidNormalizedUser(descChild.attrs.participant) : undefined
298
+ desc = getBinaryNodeChildString(descChild, "body");
299
+ descId = descChild.attrs.id;
300
+ descOwner =
301
+ mode === WAMessageAddressingMode.LID
302
+ ? jidNormalizedUser(descChild.attrs.participant_pn)
303
+ : jidNormalizedUser(descChild.attrs.participant);
304
+ descOwnerAlt =
305
+ mode === WAMessageAddressingMode.LID
306
+ ? jidNormalizedUser(descChild.attrs.participant)
307
+ : undefined;
314
308
  }
315
-
316
- const groupId = group.attrs.id.includes('@') ? group.attrs.id : WABinary_1.jidEncode(group.attrs.id, 'g.us')
317
- const eph = WABinary_1.getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration
318
- const memberAddMode = WABinary_1.getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add'
319
-
309
+ const groupId = group.attrs.id.includes("@")
310
+ ? group.attrs.id
311
+ : jidEncode(group.attrs.id, "g.us");
312
+ const eph = getBinaryNodeChild(group, "ephemeral")?.attrs.expiration;
313
+ const memberAddMode = getBinaryNodeChildString(group, "member_add_mode") === "all_member_add";
320
314
  const metadata = {
321
315
  id: groupId,
322
- addressingMode: mode,
323
316
  subject: group.attrs.subject,
324
- subjectOwner: mode === Types_1.WAMessageAddressingMode.LID ? group.attrs.s_o_pn : group.attrs.s_o,
325
- subjectOwnerLid: group.attrs.s_o,
326
- subjectTime: +group.attrs.s_t,
327
- size: group.attrs?.size ? +group.attrs.size : WABinary_1.getBinaryNodeChildren(group, 'participant').length,
328
- creation: +group.attrs.creation,
329
- owner: group.attrs.creator ? WABinary_1.jidNormalizedUser(mode === Types_1.WAMessageAddressingMode.LID ? group.attrs.creator_pn : group.attrs.creator) : undefined,
330
- ownerLid: group.attrs.creator ? WABinary_1.jidNormalizedUser(group.attrs.creator) : undefined,
331
- ownerCountry: group.attrs.creator_country_code,
332
- desc,
333
- descId,
334
- descOwner,
335
- descOwnerLid,
336
- linkedParent: WABinary_1.getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
337
- restrict: !!WABinary_1.getBinaryNodeChild(group, 'locked'),
338
- announce: !!WABinary_1.getBinaryNodeChild(group, 'announcement'),
339
- isCommunity: !!WABinary_1.getBinaryNodeChild(group, 'parent'),
340
- isCommunityAnnounce: !!WABinary_1.getBinaryNodeChild(group, 'default_sub_group'),
341
- joinApprovalMode: !!WABinary_1.getBinaryNodeChild(group, 'membership_approval_mode'),
342
- memberAddMode,
343
- participants: WABinary_1.getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
344
- return {
345
- id: mode === Types_1.WAMessageAddressingMode.LID ? attrs.phone_number : attrs.jid,
346
- lid: mode === Types_1.WAMessageAddressingMode.LID ? attrs.jid : attrs.lid,
347
- admin: (attrs.type || null),
348
- }
349
- }),
350
- ephemeralDuration: eph ? +eph : undefined,
351
- }
352
-
353
- return metadata
354
- }
355
-
317
+ subjectOwner: group.attrs.s_o,
318
+ subjectOwnerAlt: group.attrs?.s_o_pn ? group.attrs.s_o_pn : group.attrs.s_o,
319
+ subjectTime: Number(group.attrs.s_t),
320
+ size: Number(
321
+ group.attrs?.size
322
+ ? group.attrs.size
323
+ : getBinaryNodeChildren(group, "participant").length
324
+ ),
325
+ creation: Number(group.attrs.creation),
326
+ owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
327
+ ownerAlt: group.attrs.creator
328
+ ? jidNormalizedUser(
329
+ group.attrs?.creator_pn ? group.attrs.creator_pn : group.attrs.creator_pn
330
+ )
331
+ : undefined,
332
+ ownerCountry: group.attrs.creator_country_code,
333
+ desc: desc,
334
+ descId: descId,
335
+ descOwner: descOwner,
336
+ descOwnerAlt: descOwnerAlt,
337
+ linkedParent: getBinaryNodeChild(group, "linked_parent")?.attrs.jid || undefined,
338
+ restrict: !!getBinaryNodeChild(group, "locked"),
339
+ announce: !!getBinaryNodeChild(group, "announcement"),
340
+ isCommunity: !!getBinaryNodeChild(group, "parent"),
341
+ isCommunityAnnounce: !!getBinaryNodeChild(group, "default_sub_group"),
342
+ joinApprovalMode: !!getBinaryNodeChild(group, "membership_approval_mode"),
343
+ memberAddMode: memberAddMode,
344
+ participants: getBinaryNodeChildren(group, "participant").map(({ attrs: attrs }) => ({
345
+ id: mode === WAMessageAddressingMode.LID ? attrs.phone_number : attrs.jid,
346
+ lid: mode === WAMessageAddressingMode.LID ? attrs.jid : attrs.lid,
347
+ admin: attrs.type || null,
348
+ })),
349
+ ephemeralDuration: eph ? Number(eph) : undefined,
350
+ addressingMode: mode,
351
+ };
352
+ return metadata;
353
+ };
356
354
  module.exports = {
357
- makeGroupsSocket,
358
- extractGroupMetadata
359
- }
355
+ makeGroupsSocket: makeGroupsSocket,
356
+ extractGroupMetadata: extractGroupMetadata,
357
+ };