@pontalabs/baileys 1.0.6 → 1.0.7

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 (185) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +839 -267
  3. package/WAProto/GenerateStatics.sh +4 -3
  4. package/WAProto/WAProto.proto +511 -1215
  5. package/WAProto/index.d.ts +55 -14017
  6. package/WAProto/index.js +29 -97689
  7. package/lib/Defaults/index.d.ts +74 -72
  8. package/lib/Defaults/index.js +108 -94
  9. package/lib/Signal/Group/ciphertext-message.d.ts +7 -8
  10. package/lib/Signal/Group/ciphertext-message.js +16 -9
  11. package/lib/Signal/Group/group-session-builder.d.ts +13 -11
  12. package/lib/Signal/Group/group-session-builder.js +61 -19
  13. package/lib/Signal/Group/group_cipher.d.ts +16 -14
  14. package/lib/Signal/Group/group_cipher.js +70 -41
  15. package/lib/Signal/Group/index.d.ts +11 -12
  16. package/lib/Signal/Group/index.js +61 -12
  17. package/lib/Signal/Group/keyhelper.d.ts +14 -9
  18. package/lib/Signal/Group/keyhelper.js +58 -10
  19. package/lib/Signal/Group/sender-chain-key.d.ts +13 -13
  20. package/lib/Signal/Group/sender-chain-key.js +34 -13
  21. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -16
  22. package/lib/Signal/Group/sender-key-distribution-message.js +36 -28
  23. package/lib/Signal/Group/sender-key-message.d.ts +18 -18
  24. package/lib/Signal/Group/sender-key-message.js +45 -38
  25. package/lib/Signal/Group/sender-key-name.d.ts +15 -14
  26. package/lib/Signal/Group/sender-key-name.js +31 -20
  27. package/lib/Signal/Group/sender-key-record.d.ts +25 -24
  28. package/lib/Signal/Group/sender-key-record.js +35 -18
  29. package/lib/Signal/Group/sender-key-state.d.ts +34 -29
  30. package/lib/Signal/Group/sender-key-state.js +100 -37
  31. package/lib/Signal/Group/sender-message-key.d.ts +10 -11
  32. package/lib/Signal/Group/sender-message-key.js +22 -15
  33. package/lib/Signal/libsignal.d.ts +8 -5
  34. package/lib/Signal/libsignal.js +142 -288
  35. package/lib/Signal/lid-mapping.d.ts +28 -23
  36. package/lib/Signal/lid-mapping.js +184 -277
  37. package/lib/Socket/Client/index.d.ts +2 -3
  38. package/lib/Socket/Client/index.js +22 -3
  39. package/lib/Socket/Client/types.d.ts +15 -15
  40. package/lib/Socket/Client/types.js +15 -8
  41. package/lib/Socket/Client/websocket.d.ts +12 -12
  42. package/lib/Socket/Client/websocket.js +37 -29
  43. package/lib/Socket/business.d.ts +178 -208
  44. package/lib/Socket/business.js +127 -91
  45. package/lib/Socket/chats.d.ts +93 -120
  46. package/lib/Socket/chats.js +652 -727
  47. package/lib/Socket/community.js +10 -2
  48. package/lib/Socket/groups.d.ts +111 -143
  49. package/lib/Socket/groups.js +186 -165
  50. package/lib/Socket/index.d.ts +183 -252
  51. package/lib/Socket/index.js +18 -38
  52. package/lib/Socket/messages-recv.d.ts +167 -196
  53. package/lib/Socket/messages-recv.js +1567 -1443
  54. package/lib/Socket/messages-send.d.ts +158 -192
  55. package/lib/Socket/messages-send.js +1208 -1102
  56. package/lib/Socket/newsletter.d.ts +138 -163
  57. package/lib/Socket/newsletter.js +249 -153
  58. package/lib/Socket/socket.d.ts +36 -50
  59. package/lib/Socket/socket.js +820 -749
  60. package/lib/Store/index.d.ts +4 -4
  61. package/lib/Store/index.js +24 -4
  62. package/lib/Store/make-in-memory-store.d.ts +104 -44
  63. package/lib/Store/make-in-memory-store.js +213 -199
  64. package/lib/Store/make-ordered-dictionary.d.ts +12 -13
  65. package/lib/Store/make-ordered-dictionary.js +45 -38
  66. package/lib/Store/object-repository.d.ts +10 -11
  67. package/lib/Store/object-repository.js +16 -9
  68. package/lib/Types/Auth.d.ts +97 -93
  69. package/lib/Types/Auth.js +3 -2
  70. package/lib/Types/Bussines.js +3 -2
  71. package/lib/Types/Call.d.ts +13 -14
  72. package/lib/Types/Call.js +3 -2
  73. package/lib/Types/Chat.d.ts +97 -78
  74. package/lib/Types/Chat.js +9 -8
  75. package/lib/Types/Contact.d.ts +9 -12
  76. package/lib/Types/Contact.js +3 -2
  77. package/lib/Types/Events.d.ts +176 -206
  78. package/lib/Types/Events.js +3 -2
  79. package/lib/Types/GroupMetadata.d.ts +48 -53
  80. package/lib/Types/GroupMetadata.js +3 -2
  81. package/lib/Types/Label.d.ts +14 -13
  82. package/lib/Types/Label.js +30 -24
  83. package/lib/Types/LabelAssociation.d.ts +20 -15
  84. package/lib/Types/LabelAssociation.js +12 -6
  85. package/lib/Types/Message.d.ts +412 -248
  86. package/lib/Types/Message.js +19 -17
  87. package/lib/Types/Product.d.ts +71 -58
  88. package/lib/Types/Product.js +3 -2
  89. package/lib/Types/Signal.d.ts +82 -71
  90. package/lib/Types/Signal.js +3 -2
  91. package/lib/Types/Socket.d.ts +81 -76
  92. package/lib/Types/Socket.js +3 -3
  93. package/lib/Types/State.d.ts +19 -75
  94. package/lib/Types/State.js +14 -56
  95. package/lib/Types/USync.d.ts +8 -8
  96. package/lib/Types/USync.js +3 -2
  97. package/lib/Types/index.d.ts +62 -47
  98. package/lib/Types/index.js +50 -26
  99. package/lib/Utils/auth-utils.d.ts +10 -13
  100. package/lib/Utils/auth-utils.js +472 -213
  101. package/lib/Utils/business.d.ts +20 -14
  102. package/lib/Utils/business.js +134 -110
  103. package/lib/Utils/chat-utils.d.ts +70 -88
  104. package/lib/Utils/chat-utils.js +403 -466
  105. package/lib/Utils/crypto.d.ts +46 -27
  106. package/lib/Utils/crypto.js +188 -117
  107. package/lib/Utils/decode-wa-message.d.ts +45 -58
  108. package/lib/Utils/decode-wa-message.js +311 -212
  109. package/lib/Utils/event-buffer.d.ts +17 -14
  110. package/lib/Utils/event-buffer.js +296 -321
  111. package/lib/Utils/generics.d.ts +92 -66
  112. package/lib/Utils/generics.js +436 -270
  113. package/lib/Utils/history.d.ts +23 -24
  114. package/lib/Utils/history.js +76 -106
  115. package/lib/Utils/index.d.ts +21 -24
  116. package/lib/Utils/index.js +41 -24
  117. package/lib/Utils/link-preview.d.ts +14 -12
  118. package/lib/Utils/link-preview.js +75 -40
  119. package/lib/Utils/logger.d.ts +11 -10
  120. package/lib/Utils/logger.js +7 -3
  121. package/lib/Utils/lt-hash.d.ts +14 -8
  122. package/lib/Utils/lt-hash.js +53 -3
  123. package/lib/Utils/make-mutex.d.ts +7 -7
  124. package/lib/Utils/make-mutex.js +44 -28
  125. package/lib/Utils/message-retry-manager.d.ts +88 -115
  126. package/lib/Utils/message-retry-manager.js +160 -265
  127. package/lib/Utils/messages-media.d.ts +107 -105
  128. package/lib/Utils/messages-media.js +619 -548
  129. package/lib/Utils/messages.d.ts +66 -52
  130. package/lib/Utils/messages.js +1558 -1730
  131. package/lib/Utils/noise-handler.d.ts +18 -18
  132. package/lib/Utils/noise-handler.js +130 -176
  133. package/lib/Utils/process-message.d.ts +32 -43
  134. package/lib/Utils/process-message.js +282 -484
  135. package/lib/Utils/rich-message-utils.js +724 -1220
  136. package/lib/Utils/signal.d.ts +32 -37
  137. package/lib/Utils/signal.js +105 -140
  138. package/lib/Utils/use-multi-file-auth-state.d.ts +5 -5
  139. package/lib/Utils/use-multi-file-auth-state.js +120 -70
  140. package/lib/Utils/use-single-file-auth-state.d.ts +13 -11
  141. package/lib/Utils/use-single-file-auth-state.js +66 -92
  142. package/lib/Utils/validate-connection.d.ts +13 -11
  143. package/lib/Utils/validate-connection.js +113 -128
  144. package/lib/WABinary/constants.d.ts +27 -25
  145. package/lib/WABinary/constants.js +1292 -1451
  146. package/lib/WABinary/decode.d.ts +9 -7
  147. package/lib/WABinary/decode.js +189 -163
  148. package/lib/WABinary/encode.d.ts +3 -3
  149. package/lib/WABinary/encode.js +155 -110
  150. package/lib/WABinary/generic-utils.d.ts +27 -14
  151. package/lib/WABinary/generic-utils.js +105 -177
  152. package/lib/WABinary/index.d.ts +5 -6
  153. package/lib/WABinary/index.js +25 -6
  154. package/lib/WABinary/jid-utils.d.ts +54 -41
  155. package/lib/WABinary/jid-utils.js +152 -83
  156. package/lib/WABinary/types.d.ts +13 -10
  157. package/lib/WABinary/types.js +3 -2
  158. package/lib/WAM/BinaryInfo.d.ts +15 -8
  159. package/lib/WAM/BinaryInfo.js +14 -7
  160. package/lib/WAM/constants.d.ts +37 -30
  161. package/lib/WAM/constants.js +11983 -19465
  162. package/lib/WAM/encode.d.ts +3 -3
  163. package/lib/WAM/encode.js +109 -95
  164. package/lib/WAM/index.d.ts +3 -4
  165. package/lib/WAM/index.js +23 -4
  166. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
  167. package/lib/WAUSync/Protocols/USyncContactProtocol.js +21 -37
  168. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -19
  169. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +26 -18
  170. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -11
  171. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +20 -12
  172. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -11
  173. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +24 -16
  174. package/lib/WAUSync/Protocols/index.d.ts +6 -6
  175. package/lib/WAUSync/Protocols/index.js +26 -6
  176. package/lib/WAUSync/USyncQuery.d.ts +28 -27
  177. package/lib/WAUSync/USyncQuery.js +62 -68
  178. package/lib/WAUSync/USyncUser.d.ts +10 -15
  179. package/lib/WAUSync/USyncUser.js +19 -20
  180. package/lib/WAUSync/index.d.ts +3 -4
  181. package/lib/WAUSync/index.js +23 -4
  182. package/lib/index.d.ts +12 -11
  183. package/lib/index.js +39 -12
  184. package/package.json +42 -86
  185. package/engine-requirements.js +0 -10
@@ -1,32 +1,38 @@
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);
9
- const { authState, ev, query, upsertMessage } = sock;
10
- const groupQuery = async (jid, type, content) => query({
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
+
10
+ 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({
11
15
  tag: 'iq',
12
16
  attrs: {
13
17
  type,
14
18
  xmlns: 'w:g2',
15
- to: jid
19
+ to: jid,
16
20
  },
17
21
  content
18
- });
22
+ }))
23
+
19
24
  const groupMetadata = async (jid) => {
20
- const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
21
- return extractGroupMetadata(result);
22
- };
25
+ const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }])
26
+ return extractGroupMetadata(result)
27
+ }
28
+
23
29
  const groupFetchAllParticipating = async () => {
24
30
  const result = await query({
25
31
  tag: 'iq',
26
32
  attrs: {
27
33
  to: '@g.us',
28
34
  xmlns: 'w:g2',
29
- type: 'get'
35
+ type: 'get',
30
36
  },
31
37
  content: [
32
38
  {
@@ -38,37 +44,44 @@ export const makeGroupsSocket = (config) => {
38
44
  ]
39
45
  }
40
46
  ]
41
- });
42
- const data = {};
43
- const groupsChild = getBinaryNodeChild(result, 'groups');
47
+ })
48
+
49
+ const data = {}
50
+ const groupsChild = WABinary_1.getBinaryNodeChild(result, 'groups')
51
+
44
52
  if (groupsChild) {
45
- const groups = getBinaryNodeChildren(groupsChild, 'group');
53
+ const groups = WABinary_1.getBinaryNodeChildren(groupsChild, 'group')
46
54
  for (const groupNode of groups) {
47
55
  const meta = extractGroupMetadata({
48
56
  tag: 'result',
49
57
  attrs: {},
50
58
  content: [groupNode]
51
- });
52
- data[meta.id] = meta;
59
+ })
60
+ data[meta.id] = meta
53
61
  }
54
62
  }
55
- // TODO: properly parse LID / PN DATA
56
- sock.ev.emit('groups.update', Object.values(data));
57
- return data;
58
- };
63
+
64
+ sock.ev.emit('groups.update', Object.values(data))
65
+ return data
66
+ }
67
+
59
68
  sock.ws.on('CB:ib,,dirty', async (node) => {
60
- const { attrs } = getBinaryNodeChild(node, 'dirty');
69
+ const { attrs } = WABinary_1.getBinaryNodeChild(node, 'dirty')
61
70
  if (attrs.type !== 'groups') {
62
- return;
71
+ return
63
72
  }
64
- await groupFetchAllParticipating();
65
- await sock.cleanDirtyBits('groups');
66
- });
73
+
74
+ await groupFetchAllParticipating()
75
+ await sock.cleanDirtyBits('groups')
76
+ })
77
+
67
78
  return {
68
79
  ...sock,
80
+ groupQuery,
69
81
  groupMetadata,
70
82
  groupCreate: async (subject, participants) => {
71
- const key = generateMessageIDV2();
83
+ const key = Utils_1.generateMessageID()
84
+
72
85
  const result = await groupQuery('@g.us', 'set', [
73
86
  {
74
87
  tag: 'create',
@@ -81,17 +94,20 @@ export const makeGroupsSocket = (config) => {
81
94
  attrs: { jid }
82
95
  }))
83
96
  }
84
- ]);
85
- return extractGroupMetadata(result);
97
+ ])
98
+
99
+ return extractGroupMetadata(result)
86
100
  },
87
101
  groupLeave: async (id) => {
88
102
  await groupQuery('@g.us', 'set', [
89
103
  {
90
104
  tag: 'leave',
91
105
  attrs: {},
92
- content: [{ tag: 'group', attrs: { id } }]
106
+ content: [
107
+ { tag: 'group', attrs: { id } }
108
+ ]
93
109
  }
94
- ]);
110
+ ])
95
111
  },
96
112
  groupUpdateSubject: async (jid, subject) => {
97
113
  await groupQuery(jid, 'set', [
@@ -100,7 +116,7 @@ export const makeGroupsSocket = (config) => {
100
116
  attrs: {},
101
117
  content: Buffer.from(subject, 'utf-8')
102
118
  }
103
- ]);
119
+ ])
104
120
  },
105
121
  groupRequestParticipantsList: async (jid) => {
106
122
  const result = await groupQuery(jid, 'get', [
@@ -108,14 +124,15 @@ export const makeGroupsSocket = (config) => {
108
124
  tag: 'membership_approval_requests',
109
125
  attrs: {}
110
126
  }
111
- ]);
112
- const node = getBinaryNodeChild(result, 'membership_approval_requests');
113
- const participants = getBinaryNodeChildren(node, 'membership_approval_request');
114
- return participants.map(v => v.attrs);
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)
115
133
  },
116
134
  groupRequestParticipantsUpdate: async (jid, participants, action) => {
117
- const result = await groupQuery(jid, 'set', [
118
- {
135
+ const result = await groupQuery(jid, 'set', [{
119
136
  tag: 'membership_requests_action',
120
137
  attrs: {},
121
138
  content: [
@@ -128,14 +145,15 @@ export const makeGroupsSocket = (config) => {
128
145
  }))
129
146
  }
130
147
  ]
131
- }
132
- ]);
133
- const node = getBinaryNodeChild(result, 'membership_requests_action');
134
- const nodeAction = getBinaryNodeChild(node, action);
135
- const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
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
+
136
154
  return participantsAffected.map(p => {
137
- return { status: p.attrs.error || '200', jid: p.attrs.jid };
138
- });
155
+ return { status: p.attrs.error || '200', jid: p.attrs.jid }
156
+ })
139
157
  },
140
158
  groupParticipantsUpdate: async (jid, participants, action) => {
141
159
  const result = await groupQuery(jid, 'set', [
@@ -147,41 +165,48 @@ export const makeGroupsSocket = (config) => {
147
165
  attrs: { jid }
148
166
  }))
149
167
  }
150
- ]);
151
- const node = getBinaryNodeChild(result, action);
152
- const participantsAffected = getBinaryNodeChildren(node, 'participant');
168
+ ])
169
+ const node = WABinary_1.getBinaryNodeChild(result, action)
170
+ const participantsAffected = WABinary_1.getBinaryNodeChildren(node, 'participant')
171
+
153
172
  return participantsAffected.map(p => {
154
- return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
155
- });
173
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p }
174
+ })
156
175
  },
157
176
  groupUpdateDescription: async (jid, description) => {
158
- const metadata = await groupMetadata(jid);
159
- const prev = metadata.descId ?? null;
177
+ const metadata = await groupMetadata(jid)
178
+ const prev = metadata.descId ? metadata.descId : null
179
+
160
180
  await groupQuery(jid, 'set', [
161
181
  {
162
182
  tag: 'description',
163
183
  attrs: {
164
- ...(description ? { id: generateMessageIDV2() } : { delete: 'true' }),
184
+ ...(description ? { id: Utils_1.generateMessageID() } : { delete: 'true' }),
165
185
  ...(prev ? { prev } : {})
166
186
  },
167
- content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
187
+ content: description ? [
188
+ { tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }
189
+ ] : undefined
168
190
  }
169
- ]);
191
+ ])
170
192
  },
171
193
  groupInviteCode: async (jid) => {
172
- const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
173
- const inviteNode = getBinaryNodeChild(result, 'invite');
174
- return inviteNode?.attrs.code;
194
+ const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }])
195
+ const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite')
196
+
197
+ return inviteNode?.attrs?.code
175
198
  },
176
199
  groupRevokeInvite: async (jid) => {
177
- const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
178
- const inviteNode = getBinaryNodeChild(result, 'invite');
179
- return inviteNode?.attrs.code;
200
+ const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }])
201
+ const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite')
202
+
203
+ return inviteNode?.attrs?.code
180
204
  },
181
205
  groupAcceptInvite: async (code) => {
182
- const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
183
- const result = getBinaryNodeChild(results, 'group');
184
- return result?.attrs.jid;
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
185
210
  },
186
211
  /**
187
212
  * revoke a v4 invite for someone
@@ -190,10 +215,9 @@ export const makeGroupsSocket = (config) => {
190
215
  * @returns true if successful
191
216
  */
192
217
  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;
218
+ const result = await groupQuery(groupJid, 'set', [{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }])
219
+
220
+ return !!result
197
221
  },
198
222
  /**
199
223
  * accept a GroupInviteMessage
@@ -201,24 +225,23 @@ export const makeGroupsSocket = (config) => {
201
225
  * @param inviteMessage the message to accept
202
226
  */
203
227
  groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
204
- key = typeof key === 'string' ? { remoteJid: key } : key;
205
- const results = await groupQuery(inviteMessage.groupJid, 'set', [
206
- {
228
+ key = typeof key === 'string' ? { remoteJid: key } : key
229
+ const results = await groupQuery(inviteMessage.groupJid, 'set', [{
207
230
  tag: 'accept',
208
231
  attrs: {
209
232
  code: inviteMessage.inviteCode,
210
233
  expiration: inviteMessage.inviteExpiration.toString(),
211
234
  admin: key.remoteJid
212
235
  }
213
- }
214
- ]);
236
+ }])
237
+
215
238
  // if we have the full message key
216
239
  // update the invite message to be expired
217
240
  if (key.id) {
218
241
  // create new invite message that is expired
219
- inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
220
- inviteMessage.inviteExpiration = 0;
221
- inviteMessage.inviteCode = '';
242
+ inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage)
243
+ inviteMessage.inviteExpiration = 0
244
+ inviteMessage.inviteCode = ''
222
245
  ev.emit('messages.update', [
223
246
  {
224
247
  key,
@@ -228,120 +251,118 @@ export const makeGroupsSocket = (config) => {
228
251
  }
229
252
  }
230
253
  }
231
- ]);
254
+ ])
232
255
  }
256
+
233
257
  // generate the group add message
234
258
  await upsertMessage({
235
259
  key: {
236
260
  remoteJid: inviteMessage.groupJid,
237
- id: generateMessageIDV2(sock.user?.id),
261
+ id: Utils_1.generateMessageID(authState.creds.me?.id),
238
262
  fromMe: false,
239
- participant: key.remoteJid
263
+ participant: key.remoteJid,
240
264
  },
241
- messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
242
- messageStubParameters: [JSON.stringify(authState.creds.me)],
265
+ messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
266
+ messageStubParameters: [
267
+ authState.creds.me.id
268
+ ],
243
269
  participant: key.remoteJid,
244
- messageTimestamp: unixTimestampSeconds()
245
- }, 'notify');
246
- return results.attrs.from;
270
+ messageTimestamp: Utils_1.unixTimestampSeconds()
271
+ }, 'notify')
272
+
273
+ return results.attrs.from
247
274
  }),
248
275
  groupGetInviteInfo: async (code) => {
249
- const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
250
- return extractGroupMetadata(results);
276
+ const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }])
277
+
278
+ return extractGroupMetadata(results)
251
279
  },
252
280
  groupToggleEphemeral: async (jid, ephemeralExpiration) => {
253
- const content = ephemeralExpiration
254
- ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
255
- : { tag: 'not_ephemeral', attrs: {} };
256
- await groupQuery(jid, 'set', [content]);
281
+ const content = ephemeralExpiration ?
282
+ { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } } :
283
+ { tag: 'not_ephemeral', attrs: {} }
284
+ await groupQuery(jid, 'set', [content])
257
285
  },
258
286
  groupSettingUpdate: async (jid, setting) => {
259
- await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
287
+ await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }])
260
288
  },
261
289
  groupMemberAddMode: async (jid, mode) => {
262
- await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
290
+ await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }])
263
291
  },
264
292
  groupJoinApprovalMode: async (jid, mode) => {
265
- await groupQuery(jid, 'set', [
266
- { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
267
- ]);
293
+ await groupQuery(jid, 'set', [{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }])
268
294
  },
269
295
  groupFetchAllParticipating
270
- };
271
- };
272
- export const extractGroupMetadata = (result) => {
273
- const group = getBinaryNodeChild(result, 'group');
274
- if (!group) {
275
- // Mirror WAWeb: surface server/client errors with their code+text instead of crashing.
276
- const errorNode = getBinaryNodeChild(result, 'error');
277
- if (errorNode) {
278
- const code = errorNode.attrs.code ? +errorNode.attrs.code : 500;
279
- const text = errorNode.attrs.text || 'group metadata query failed';
280
- throw new Boom(text, { statusCode: code, data: errorNode });
281
- }
282
- throw new Boom('Invalid group metadata response: missing <group> node', { data: result });
283
296
  }
284
- if (!group.attrs.id) {
285
- throw new Boom('Invalid group metadata response: missing group id', { data: group });
286
- }
287
- const descChild = getBinaryNodeChild(group, 'description');
288
- let desc;
289
- let descId;
290
- let descOwner;
291
- let descOwnerPn;
292
- let descOwnerUsername;
293
- let descTime;
297
+ }
298
+
299
+ 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
+
294
309
  if (descChild) {
295
- desc = getBinaryNodeChildString(descChild, 'body');
296
- descOwner = descChild.attrs.participant ? jidNormalizedUser(descChild.attrs.participant) : undefined;
297
- descOwnerPn = descChild.attrs.participant_pn ? jidNormalizedUser(descChild.attrs.participant_pn) : undefined;
298
- descOwnerUsername = descChild.attrs.participant_username || undefined;
299
- descTime = +descChild.attrs.t;
300
- descId = descChild.attrs.id;
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
301
314
  }
302
- const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us');
303
- const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration;
304
- const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add';
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
+
305
320
  const metadata = {
306
321
  id: groupId,
307
- notify: group.attrs.notify,
308
- addressingMode: group.attrs.addressing_mode === 'lid' ? WAMessageAddressingMode.LID : WAMessageAddressingMode.PN,
322
+ addressingMode: mode,
309
323
  subject: group.attrs.subject,
310
- subjectOwner: group.attrs.s_o,
311
- subjectOwnerPn: group.attrs.s_o_pn,
312
- subjectOwnerUsername: group.attrs.s_o_username,
324
+ subjectOwner: mode === Types_1.WAMessageAddressingMode.LID ? group.attrs.s_o_pn : group.attrs.s_o,
325
+ subjectOwnerLid: group.attrs.s_o,
313
326
  subjectTime: +group.attrs.s_t,
314
- size: group.attrs.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length,
327
+ size: group.attrs?.size ? +group.attrs.size : WABinary_1.getBinaryNodeChildren(group, 'participant').length,
315
328
  creation: +group.attrs.creation,
316
- owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
317
- ownerPn: group.attrs.creator_pn ? jidNormalizedUser(group.attrs.creator_pn) : undefined,
318
- ownerUsername: group.attrs.creator_username || undefined,
319
- owner_country_code: group.attrs.creator_country_code,
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,
320
332
  desc,
321
333
  descId,
322
- descOwner,
323
- descOwnerPn,
324
- descOwnerUsername,
325
- descTime,
326
- linkedParent: getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
327
- restrict: !!getBinaryNodeChild(group, 'locked'),
328
- announce: !!getBinaryNodeChild(group, 'announcement'),
329
- isCommunity: !!getBinaryNodeChild(group, 'parent'),
330
- isCommunityAnnounce: !!getBinaryNodeChild(group, 'default_sub_group'),
331
- joinApprovalMode: !!getBinaryNodeChild(group, 'membership_approval_mode'),
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'),
332
342
  memberAddMode,
333
- participants: getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
334
- // TODO: Store LID MAPPINGS
343
+ participants: WABinary_1.getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
344
+ // FIX: sebelumnya id/lid cuma ngandelin `mode` (addressing mode
345
+ // grup secara keseluruhan), padahal atribut per-participant bisa
346
+ // aja beda. splitJidLid milah berdasarkan suffix domain aslinya,
347
+ // jadi hasilnya konsisten. phoneNumber ditambahin biar sejalan
348
+ // sama struktur participant di groups.js.
349
+ const primary = mode === Types_1.WAMessageAddressingMode.LID ? attrs.phone_number : attrs.jid
350
+ const alt = mode === Types_1.WAMessageAddressingMode.LID ? attrs.jid : attrs.lid
351
+ const { jid, lid } = WABinary_1.splitJidLid(primary, alt)
335
352
  return {
336
- id: attrs.jid,
337
- phoneNumber: isLidUser(attrs.jid) && isPnUser(attrs.phone_number) ? attrs.phone_number : undefined,
338
- lid: isPnUser(attrs.jid) && isLidUser(attrs.lid) ? attrs.lid : undefined,
339
- username: attrs.participant_username || attrs.username || undefined,
340
- admin: (attrs.type || null)
341
- };
353
+ id: jid || primary || attrs.jid,
354
+ lid,
355
+ phoneNumber: jid,
356
+ admin: (attrs.type || null),
357
+ }
342
358
  }),
343
- ephemeralDuration: eph ? +eph : undefined
344
- };
345
- return metadata;
346
- };
347
- //# sourceMappingURL=groups.js.map
359
+ ephemeralDuration: eph ? +eph : undefined,
360
+ }
361
+
362
+ return metadata
363
+ }
364
+
365
+ module.exports = {
366
+ makeGroupsSocket,
367
+ extractGroupMetadata
368
+ }