@badzz88/baileys 8.4.7 → 8.5.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 (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1055 -337
  3. package/WAProto/index.js +5 -5
  4. package/lib/Defaults/index.js +187 -127
  5. package/lib/Defaults/phonenumber-mcc.json +223 -0
  6. package/lib/Signal/Group/ciphertext-message.js +14 -11
  7. package/lib/Signal/Group/group-session-builder.js +91 -29
  8. package/lib/Signal/Group/group_cipher.js +88 -81
  9. package/lib/Signal/Group/index.js +136 -12
  10. package/lib/Signal/Group/keyhelper.js +70 -15
  11. package/lib/Signal/Group/sender-chain-key.js +31 -25
  12. package/lib/Signal/Group/sender-key-distribution-message.js +65 -62
  13. package/lib/Signal/Group/sender-key-message.js +68 -65
  14. package/lib/Signal/Group/sender-key-name.js +43 -41
  15. package/lib/Signal/Group/sender-key-record.js +43 -40
  16. package/lib/Signal/Group/sender-key-state.js +96 -83
  17. package/lib/Signal/Group/sender-message-key.js +29 -25
  18. package/lib/Signal/libsignal.js +483 -424
  19. package/lib/Signal/lid-mapping.js +261 -276
  20. package/lib/Socket/Client/index.js +30 -3
  21. package/lib/Socket/Client/types.js +12 -10
  22. package/lib/Socket/Client/websocket.js +61 -53
  23. package/lib/Socket/aigroups.js +240 -0
  24. package/lib/Socket/business.js +422 -379
  25. package/lib/Socket/chats.js +1816 -1193
  26. package/lib/Socket/communities.js +549 -431
  27. package/lib/Socket/graphql.js +656 -0
  28. package/lib/Socket/groups.js +764 -374
  29. package/lib/Socket/index.js +38 -11
  30. package/lib/Socket/interactive-handler.js +522 -0
  31. package/lib/Socket/interop.js +549 -0
  32. package/lib/Socket/luxu.js +6 -5
  33. package/lib/Socket/managed-account.js +183 -0
  34. package/lib/Socket/messages-recv.js +2439 -1915
  35. package/lib/Socket/messages-send.js +1642 -1242
  36. package/lib/Socket/mex.js +59 -40
  37. package/lib/Socket/newsletter.js +812 -249
  38. package/lib/Socket/privacy.js +449 -0
  39. package/lib/Socket/registration.js +427 -0
  40. package/lib/Socket/socket.js +1077 -965
  41. package/lib/Socket/text-router.js +83 -0
  42. package/lib/Socket/username.js +237 -140
  43. package/lib/Store/index.js +36 -10
  44. package/lib/Store/make-cache-manager-store.js +85 -80
  45. package/lib/Store/make-in-memory-store.js +591 -185
  46. package/lib/Store/make-ordered-dictionary.js +78 -72
  47. package/lib/Store/object-repository.js +25 -28
  48. package/lib/Types/Auth.js +38 -2
  49. package/lib/Types/Bussines.js +2 -2
  50. package/lib/Types/Call.js +2 -2
  51. package/lib/Types/Chat.js +4 -8
  52. package/lib/Types/Contact.js +2 -2
  53. package/lib/Types/Events.js +2 -2
  54. package/lib/Types/GroupMetadata.js +2 -2
  55. package/lib/Types/Label.js +26 -24
  56. package/lib/Types/LabelAssociation.js +8 -6
  57. package/lib/Types/Message.js +95 -11
  58. package/lib/Types/Mex.js +112 -37
  59. package/lib/Types/Newsletter.js +121 -0
  60. package/lib/Types/Product.js +2 -2
  61. package/lib/Types/Signal.js +2 -2
  62. package/lib/Types/Socket.js +2 -3
  63. package/lib/Types/State.js +70 -56
  64. package/lib/Types/USync.js +2 -2
  65. package/lib/Types/index.js +55 -26
  66. package/lib/Utils/auth-utils.js +292 -288
  67. package/lib/Utils/browser-utils.js +113 -48
  68. package/lib/Utils/business.js +240 -224
  69. package/lib/Utils/chat-utils.js +1205 -869
  70. package/lib/Utils/command-loader.d.ts +31 -0
  71. package/lib/Utils/command-loader.js +100 -0
  72. package/lib/Utils/companion-reg-client-utils.js +41 -34
  73. package/lib/Utils/consumer-application.js +107 -0
  74. package/lib/Utils/crypto.js +144 -107
  75. package/lib/Utils/curve25519-js.js +275 -0
  76. package/lib/Utils/decode-wa-message.js +518 -308
  77. package/lib/Utils/event-buffer.js +596 -611
  78. package/lib/Utils/generics.js +514 -354
  79. package/lib/Utils/group-history.js +60 -0
  80. package/lib/Utils/history.js +244 -134
  81. package/lib/Utils/identity-change-handler.js +51 -49
  82. package/lib/Utils/index.js +57 -23
  83. package/lib/Utils/jid-display-normalization.js +218 -0
  84. package/lib/Utils/link-preview.js +135 -77
  85. package/lib/Utils/logger.js +9 -3
  86. package/lib/Utils/lt-hash.js +37 -6
  87. package/lib/Utils/make-mutex.js +36 -33
  88. package/lib/Utils/message-composer.js +439 -233
  89. package/lib/Utils/message-retry-manager.js +265 -260
  90. package/lib/Utils/messages-media.js +855 -747
  91. package/lib/Utils/messages.js +2528 -884
  92. package/lib/Utils/meta-ai-msmsg.js +262 -0
  93. package/lib/Utils/native-bridge.js +82 -0
  94. package/lib/Utils/noise-handler.js +195 -200
  95. package/lib/Utils/offline-node-processor.js +35 -33
  96. package/lib/Utils/pre-key-manager.js +103 -102
  97. package/lib/Utils/process-message.js +978 -560
  98. package/lib/Utils/reporting-utils.js +257 -253
  99. package/lib/Utils/session-pool.d.ts +16 -0
  100. package/lib/Utils/session-pool.js +94 -0
  101. package/lib/Utils/signal.js +218 -195
  102. package/lib/Utils/stanza-ack.js +31 -29
  103. package/lib/Utils/sticker.d.ts +17 -0
  104. package/lib/Utils/sticker.js +145 -0
  105. package/lib/Utils/sync-action-utils.js +50 -45
  106. package/lib/Utils/tc-token-utils.js +137 -139
  107. package/lib/Utils/use-multi-file-auth-state.js +109 -109
  108. package/lib/Utils/validate-connection.js +218 -202
  109. package/lib/Utils/view-once-cache.d.ts +9 -0
  110. package/lib/Utils/view-once-cache.js +79 -0
  111. package/lib/Utils/voip-rekey.js +22 -0
  112. package/lib/WABinary/constants.js +1302 -1299
  113. package/lib/WABinary/decode.js +343 -262
  114. package/lib/WABinary/encode.js +12 -4
  115. package/lib/WABinary/generic-utils.js +223 -187
  116. package/lib/WABinary/index.js +33 -6
  117. package/lib/WABinary/jid-utils.js +351 -88
  118. package/lib/WABinary/types.js +2 -2
  119. package/lib/WAM/BinaryInfo.js +12 -9
  120. package/lib/WAM/constants.js +39486 -22853
  121. package/lib/WAM/encode.js +132 -140
  122. package/lib/WAM/index.js +31 -4
  123. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +55 -0
  124. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
  125. package/lib/WAUSync/Protocols/USyncContactProtocol.js +53 -51
  126. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +56 -53
  127. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +29 -26
  128. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +59 -0
  129. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +31 -0
  130. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
  131. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
  132. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -37
  133. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  134. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +26 -24
  135. package/lib/WAUSync/Protocols/index.js +39 -6
  136. package/lib/WAUSync/USyncQuery.js +132 -97
  137. package/lib/WAUSync/USyncUser.js +49 -30
  138. package/lib/WAUSync/index.js +31 -4
  139. package/lib/antiban.js +4637 -0
  140. package/lib/index.js +48 -15
  141. package/package.json +55 -92
  142. package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -263
  143. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
  144. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
@@ -1,379 +1,422 @@
1
- import { getRawMediaUploadData } from '../Utils/index.js';
2
- import { parseCatalogNode, parseCollectionsNode, parseOrderDetailsNode, parseProductNode, toProductNode, uploadingNecessaryImagesOfProduct } from '../Utils/business.js';
3
- import { jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
4
- import { getBinaryNodeChild } from '../WABinary/generic-utils.js';
5
- import { makeMessagesRecvSocket } from './messages-recv.js';
6
- export const makeBusinessSocket = (config) => {
7
- const sock = makeMessagesRecvSocket(config);
8
- const { authState, query, waUploadToServer } = sock;
9
- const updateBussinesProfile = async (args) => {
10
- const node = [];
11
- const simpleFields = ['address', 'email', 'description'];
12
- node.push(...simpleFields
13
- .filter(key => args[key] !== undefined && args[key] !== null)
14
- .map(key => ({
15
- tag: key,
16
- attrs: {},
17
- content: args[key]
18
- })));
19
- if (args.websites !== undefined) {
20
- node.push(...args.websites.map(website => ({
21
- tag: 'website',
22
- attrs: {},
23
- content: website
24
- })));
25
- }
26
- if (args.hours !== undefined) {
27
- node.push({
28
- tag: 'business_hours',
29
- attrs: { timezone: args.hours.timezone },
30
- content: args.hours.days.map(dayConfig => {
31
- const base = {
32
- tag: 'business_hours_config',
33
- attrs: {
34
- day_of_week: dayConfig.day,
35
- mode: dayConfig.mode
36
- }
37
- };
38
- if (dayConfig.mode === 'specific_hours') {
39
- return {
40
- ...base,
41
- attrs: {
42
- ...base.attrs,
43
- open_time: dayConfig.openTimeInMinutes,
44
- close_time: dayConfig.closeTimeInMinutes
45
- }
46
- };
47
- }
48
- return base;
49
- })
50
- });
51
- }
52
- const result = await query({
53
- tag: 'iq',
54
- attrs: {
55
- to: S_WHATSAPP_NET,
56
- type: 'set',
57
- xmlns: 'w:biz'
58
- },
59
- content: [
60
- {
61
- tag: 'business_profile',
62
- attrs: {
63
- v: '3',
64
- mutation_type: 'delta'
65
- },
66
- content: node
67
- }
68
- ]
69
- });
70
- return result;
71
- };
72
- const updateCoverPhoto = async (photo) => {
73
- const { fileSha256, filePath } = await getRawMediaUploadData(photo, 'biz-cover-photo');
74
- const fileSha256B64 = fileSha256.toString('base64');
75
- const { meta_hmac, fbid, ts } = await waUploadToServer(filePath, {
76
- fileEncSha256B64: fileSha256B64,
77
- mediaType: 'biz-cover-photo'
78
- });
79
- await query({
80
- tag: 'iq',
81
- attrs: {
82
- to: S_WHATSAPP_NET,
83
- type: 'set',
84
- xmlns: 'w:biz'
85
- },
86
- content: [
87
- {
88
- tag: 'business_profile',
89
- attrs: {
90
- v: '3',
91
- mutation_type: 'delta'
92
- },
93
- content: [
94
- {
95
- tag: 'cover_photo',
96
- attrs: { id: String(fbid), op: 'update', token: meta_hmac, ts: String(ts) }
97
- }
98
- ]
99
- }
100
- ]
101
- });
102
- return fbid;
103
- };
104
- const removeCoverPhoto = async (id) => {
105
- return await query({
106
- tag: 'iq',
107
- attrs: {
108
- to: S_WHATSAPP_NET,
109
- type: 'set',
110
- xmlns: 'w:biz'
111
- },
112
- content: [
113
- {
114
- tag: 'business_profile',
115
- attrs: {
116
- v: '3',
117
- mutation_type: 'delta'
118
- },
119
- content: [
120
- {
121
- tag: 'cover_photo',
122
- attrs: { op: 'delete', id }
123
- }
124
- ]
125
- }
126
- ]
127
- });
128
- };
129
- const getCatalog = async ({ jid, limit, cursor }) => {
130
- jid = jid || authState.creds.me?.id;
131
- jid = jidNormalizedUser(jid);
132
- const queryParamNodes = [
133
- {
134
- tag: 'limit',
135
- attrs: {},
136
- content: Buffer.from((limit || 10).toString())
137
- },
138
- {
139
- tag: 'width',
140
- attrs: {},
141
- content: Buffer.from('100')
142
- },
143
- {
144
- tag: 'height',
145
- attrs: {},
146
- content: Buffer.from('100')
147
- }
148
- ];
149
- if (cursor) {
150
- queryParamNodes.push({
151
- tag: 'after',
152
- attrs: {},
153
- content: cursor
154
- });
155
- }
156
- const result = await query({
157
- tag: 'iq',
158
- attrs: {
159
- to: S_WHATSAPP_NET,
160
- type: 'get',
161
- xmlns: 'w:biz:catalog'
162
- },
163
- content: [
164
- {
165
- tag: 'product_catalog',
166
- attrs: {
167
- jid,
168
- allow_shop_source: 'true'
169
- },
170
- content: queryParamNodes
171
- }
172
- ]
173
- });
174
- return parseCatalogNode(result);
175
- };
176
- const getCollections = async (jid, limit = 51) => {
177
- jid = jid || authState.creds.me?.id;
178
- jid = jidNormalizedUser(jid);
179
- const result = await query({
180
- tag: 'iq',
181
- attrs: {
182
- to: S_WHATSAPP_NET,
183
- type: 'get',
184
- xmlns: 'w:biz:catalog',
185
- smax_id: '35'
186
- },
187
- content: [
188
- {
189
- tag: 'collections',
190
- attrs: {
191
- biz_jid: jid
192
- },
193
- content: [
194
- {
195
- tag: 'collection_limit',
196
- attrs: {},
197
- content: Buffer.from(limit.toString())
198
- },
199
- {
200
- tag: 'item_limit',
201
- attrs: {},
202
- content: Buffer.from(limit.toString())
203
- },
204
- {
205
- tag: 'width',
206
- attrs: {},
207
- content: Buffer.from('100')
208
- },
209
- {
210
- tag: 'height',
211
- attrs: {},
212
- content: Buffer.from('100')
213
- }
214
- ]
215
- }
216
- ]
217
- });
218
- return parseCollectionsNode(result);
219
- };
220
- const getOrderDetails = async (orderId, tokenBase64) => {
221
- const result = await query({
222
- tag: 'iq',
223
- attrs: {
224
- to: S_WHATSAPP_NET,
225
- type: 'get',
226
- xmlns: 'fb:thrift_iq',
227
- smax_id: '5'
228
- },
229
- content: [
230
- {
231
- tag: 'order',
232
- attrs: {
233
- op: 'get',
234
- id: orderId
235
- },
236
- content: [
237
- {
238
- tag: 'image_dimensions',
239
- attrs: {},
240
- content: [
241
- {
242
- tag: 'width',
243
- attrs: {},
244
- content: Buffer.from('100')
245
- },
246
- {
247
- tag: 'height',
248
- attrs: {},
249
- content: Buffer.from('100')
250
- }
251
- ]
252
- },
253
- {
254
- tag: 'token',
255
- attrs: {},
256
- content: Buffer.from(tokenBase64)
257
- }
258
- ]
259
- }
260
- ]
261
- });
262
- return parseOrderDetailsNode(result);
263
- };
264
- const productUpdate = async (productId, update) => {
265
- update = await uploadingNecessaryImagesOfProduct(update, waUploadToServer);
266
- const editNode = toProductNode(productId, update);
267
- const result = await query({
268
- tag: 'iq',
269
- attrs: {
270
- to: S_WHATSAPP_NET,
271
- type: 'set',
272
- xmlns: 'w:biz:catalog'
273
- },
274
- content: [
275
- {
276
- tag: 'product_catalog_edit',
277
- attrs: { v: '1' },
278
- content: [
279
- editNode,
280
- {
281
- tag: 'width',
282
- attrs: {},
283
- content: '100'
284
- },
285
- {
286
- tag: 'height',
287
- attrs: {},
288
- content: '100'
289
- }
290
- ]
291
- }
292
- ]
293
- });
294
- const productCatalogEditNode = getBinaryNodeChild(result, 'product_catalog_edit');
295
- const productNode = getBinaryNodeChild(productCatalogEditNode, 'product');
296
- return parseProductNode(productNode);
297
- };
298
- const productCreate = async (create) => {
299
- // ensure isHidden is defined
300
- create.isHidden = !!create.isHidden;
301
- create = await uploadingNecessaryImagesOfProduct(create, waUploadToServer);
302
- const createNode = toProductNode(undefined, create);
303
- const result = await query({
304
- tag: 'iq',
305
- attrs: {
306
- to: S_WHATSAPP_NET,
307
- type: 'set',
308
- xmlns: 'w:biz:catalog'
309
- },
310
- content: [
311
- {
312
- tag: 'product_catalog_add',
313
- attrs: { v: '1' },
314
- content: [
315
- createNode,
316
- {
317
- tag: 'width',
318
- attrs: {},
319
- content: '100'
320
- },
321
- {
322
- tag: 'height',
323
- attrs: {},
324
- content: '100'
325
- }
326
- ]
327
- }
328
- ]
329
- });
330
- const productCatalogAddNode = getBinaryNodeChild(result, 'product_catalog_add');
331
- const productNode = getBinaryNodeChild(productCatalogAddNode, 'product');
332
- return parseProductNode(productNode);
333
- };
334
- const productDelete = async (productIds) => {
335
- const result = await query({
336
- tag: 'iq',
337
- attrs: {
338
- to: S_WHATSAPP_NET,
339
- type: 'set',
340
- xmlns: 'w:biz:catalog'
341
- },
342
- content: [
343
- {
344
- tag: 'product_catalog_delete',
345
- attrs: { v: '1' },
346
- content: productIds.map(id => ({
347
- tag: 'product',
348
- attrs: {},
349
- content: [
350
- {
351
- tag: 'id',
352
- attrs: {},
353
- content: Buffer.from(id)
354
- }
355
- ]
356
- }))
357
- }
358
- ]
359
- });
360
- const productCatalogDelNode = getBinaryNodeChild(result, 'product_catalog_delete');
361
- return {
362
- deleted: +(productCatalogDelNode?.attrs.deleted_count || 0)
363
- };
364
- };
365
- return {
366
- ...sock,
367
- logger: config.logger,
368
- getOrderDetails,
369
- getCatalog,
370
- getCollections,
371
- productCreate,
372
- productDelete,
373
- productUpdate,
374
- updateBussinesProfile,
375
- updateCoverPhoto,
376
- removeCoverPhoto
377
- };
378
- };
379
- //# sourceMappingURL=business.js.map
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.makeBusinessSocket = void 0
4
+ const Utils_1 = require('../Utils')
5
+ const business_1 = require('../Utils/business')
6
+ const WABinary_1 = require('../WABinary')
7
+ const generic_utils_1 = require('../WABinary/generic-utils')
8
+ const messages_recv_1 = require('./messages-recv')
9
+ const makeBusinessSocket = config => {
10
+ const sock = (0, messages_recv_1.makeMessagesRecvSocket)(config)
11
+ const { authState, query, waUploadToServer } = sock
12
+ const updateBussinesProfile = async args => {
13
+ const node = []
14
+ const simpleFields = ['address', 'email', 'description']
15
+ node.push(
16
+ ...simpleFields
17
+ .filter(key => args[key] !== undefined && args[key] !== null)
18
+ .map(key => ({
19
+ tag: key,
20
+ attrs: {},
21
+ content: args[key]
22
+ }))
23
+ )
24
+ if (args.websites !== undefined) {
25
+ node.push(
26
+ ...args.websites.map(website => ({
27
+ tag: 'website',
28
+ attrs: {},
29
+ content: website
30
+ }))
31
+ )
32
+ }
33
+ if (args.hours !== undefined) {
34
+ node.push({
35
+ tag: 'business_hours',
36
+ attrs: { timezone: args.hours.timezone },
37
+ content: args.hours.days.map(dayConfig => {
38
+ const base = {
39
+ tag: 'business_hours_config',
40
+ attrs: {
41
+ day_of_week: dayConfig.day,
42
+ mode: dayConfig.mode
43
+ }
44
+ }
45
+ if (dayConfig.mode === 'specific_hours') {
46
+ return {
47
+ ...base,
48
+ attrs: {
49
+ ...base.attrs,
50
+ open_time: dayConfig.openTimeInMinutes,
51
+ close_time: dayConfig.closeTimeInMinutes
52
+ }
53
+ }
54
+ }
55
+ return base
56
+ })
57
+ })
58
+ }
59
+ const result = await query({
60
+ tag: 'iq',
61
+ attrs: {
62
+ to: WABinary_1.S_WHATSAPP_NET,
63
+ type: 'set',
64
+ xmlns: 'w:biz'
65
+ },
66
+ content: [
67
+ {
68
+ tag: 'business_profile',
69
+ attrs: {
70
+ v: '3',
71
+ mutation_type: 'delta'
72
+ },
73
+ content: node
74
+ }
75
+ ]
76
+ })
77
+ return result
78
+ }
79
+ const updateCoverPhoto = async photo => {
80
+ const { fileSha256, filePath } = await (0, Utils_1.getRawMediaUploadData)(photo, 'biz-cover-photo')
81
+ const fileSha256B64 = fileSha256.toString('base64')
82
+ const { meta_hmac, fbid, ts } = await waUploadToServer(filePath, {
83
+ fileEncSha256B64: fileSha256B64,
84
+ mediaType: 'biz-cover-photo'
85
+ })
86
+ await query({
87
+ tag: 'iq',
88
+ attrs: {
89
+ to: WABinary_1.S_WHATSAPP_NET,
90
+ type: 'set',
91
+ xmlns: 'w:biz'
92
+ },
93
+ content: [
94
+ {
95
+ tag: 'business_profile',
96
+ attrs: {
97
+ v: '3',
98
+ mutation_type: 'delta'
99
+ },
100
+ content: [
101
+ {
102
+ tag: 'cover_photo',
103
+ attrs: { id: String(fbid), op: 'update', token: meta_hmac, ts: String(ts) }
104
+ }
105
+ ]
106
+ }
107
+ ]
108
+ })
109
+ return fbid
110
+ }
111
+ const removeCoverPhoto = async id => {
112
+ return await query({
113
+ tag: 'iq',
114
+ attrs: {
115
+ to: WABinary_1.S_WHATSAPP_NET,
116
+ type: 'set',
117
+ xmlns: 'w:biz'
118
+ },
119
+ content: [
120
+ {
121
+ tag: 'business_profile',
122
+ attrs: {
123
+ v: '3',
124
+ mutation_type: 'delta'
125
+ },
126
+ content: [
127
+ {
128
+ tag: 'cover_photo',
129
+ attrs: { op: 'delete', id }
130
+ }
131
+ ]
132
+ }
133
+ ]
134
+ })
135
+ }
136
+ const getCatalog = async ({ jid, limit, cursor }) => {
137
+ jid = jid || authState.creds.me?.id
138
+ jid = (0, WABinary_1.jidNormalizedUser)(jid)
139
+ const queryParamNodes = [
140
+ {
141
+ tag: 'limit',
142
+ attrs: {},
143
+ content: Buffer.from((limit || 10).toString())
144
+ },
145
+ {
146
+ tag: 'width',
147
+ attrs: {},
148
+ content: Buffer.from('100')
149
+ },
150
+ {
151
+ tag: 'height',
152
+ attrs: {},
153
+ content: Buffer.from('100')
154
+ }
155
+ ]
156
+ if (cursor) {
157
+ queryParamNodes.push({
158
+ tag: 'after',
159
+ attrs: {},
160
+ content: cursor
161
+ })
162
+ }
163
+ const result = await query({
164
+ tag: 'iq',
165
+ attrs: {
166
+ to: WABinary_1.S_WHATSAPP_NET,
167
+ type: 'get',
168
+ xmlns: 'w:biz:catalog'
169
+ },
170
+ content: [
171
+ {
172
+ tag: 'product_catalog',
173
+ attrs: {
174
+ jid,
175
+ allow_shop_source: 'true'
176
+ },
177
+ content: queryParamNodes
178
+ }
179
+ ]
180
+ })
181
+ return (0, business_1.parseCatalogNode)(result)
182
+ }
183
+ const getCollections = async (jid, limit = 51) => {
184
+ jid = jid || authState.creds.me?.id
185
+ jid = (0, WABinary_1.jidNormalizedUser)(jid)
186
+ const result = await query({
187
+ tag: 'iq',
188
+ attrs: {
189
+ to: WABinary_1.S_WHATSAPP_NET,
190
+ type: 'get',
191
+ xmlns: 'w:biz:catalog',
192
+ smax_id: '35'
193
+ },
194
+ content: [
195
+ {
196
+ tag: 'collections',
197
+ attrs: {
198
+ biz_jid: jid
199
+ },
200
+ content: [
201
+ {
202
+ tag: 'collection_limit',
203
+ attrs: {},
204
+ content: Buffer.from(limit.toString())
205
+ },
206
+ {
207
+ tag: 'item_limit',
208
+ attrs: {},
209
+ content: Buffer.from(limit.toString())
210
+ },
211
+ {
212
+ tag: 'width',
213
+ attrs: {},
214
+ content: Buffer.from('100')
215
+ },
216
+ {
217
+ tag: 'height',
218
+ attrs: {},
219
+ content: Buffer.from('100')
220
+ }
221
+ ]
222
+ }
223
+ ]
224
+ })
225
+ return (0, business_1.parseCollectionsNode)(result)
226
+ }
227
+ const getOrderDetails = async (orderId, tokenBase64) => {
228
+ const result = await query({
229
+ tag: 'iq',
230
+ attrs: {
231
+ to: WABinary_1.S_WHATSAPP_NET,
232
+ type: 'get',
233
+ xmlns: 'fb:thrift_iq',
234
+ smax_id: '5'
235
+ },
236
+ content: [
237
+ {
238
+ tag: 'order',
239
+ attrs: {
240
+ op: 'get',
241
+ id: orderId
242
+ },
243
+ content: [
244
+ {
245
+ tag: 'image_dimensions',
246
+ attrs: {},
247
+ content: [
248
+ {
249
+ tag: 'width',
250
+ attrs: {},
251
+ content: Buffer.from('100')
252
+ },
253
+ {
254
+ tag: 'height',
255
+ attrs: {},
256
+ content: Buffer.from('100')
257
+ }
258
+ ]
259
+ },
260
+ {
261
+ tag: 'token',
262
+ attrs: {},
263
+ content: Buffer.from(tokenBase64)
264
+ }
265
+ ]
266
+ }
267
+ ]
268
+ })
269
+ return (0, business_1.parseOrderDetailsNode)(result)
270
+ }
271
+ /**
272
+ * Get linked Facebook/Instagram accounts (WhatsApp-as-a-page linking).
273
+ * Ported from WhatsApp Web's WASmaxBizLinkingGetLinkedAccountsRPC.
274
+ * @returns {Promise<{ pageInfo: object, linkState?: string, node: object } | undefined>}
275
+ */
276
+ const getLinkedAccounts = async () => {
277
+ const result = await query({
278
+ tag: 'iq',
279
+ attrs: { to: WABinary_1.S_WHATSAPP_NET, type: 'get', xmlns: 'fb:thrift_iq', smax_id: '42' },
280
+ content: [{ tag: 'linked_accounts', attrs: {} }]
281
+ })
282
+ const fbPage = (0, WABinary_1.getBinaryNodeChild)(result, 'fb_page')
283
+ if (!fbPage) return undefined
284
+ const button = (0, WABinary_1.getBinaryNodeChild)(fbPage, 'whatsapp_as_page_button')
285
+ return { pageInfo: fbPage.attrs, linkState: button?.attrs?.state, node: fbPage }
286
+ }
287
+ /**
288
+ * Get business eligibility for the given features (meta_verified / marketing_messages / genai).
289
+ * Ported from WhatsApp Web's WASmaxBizMarketingMessageGetBusinessEligibilityRPC.
290
+ * @param {{ metaVerified?: any, marketingMessages?: any, genai?: any }} [features]
291
+ */
292
+ const getBusinessEligibility = async (features = {}) => {
293
+ const attrs = {}
294
+ if (features.metaVerified !== undefined) attrs.meta_verified = String(features.metaVerified)
295
+ if (features.marketingMessages !== undefined) attrs.marketing_messages = String(features.marketingMessages)
296
+ if (features.genai !== undefined) attrs.genai = String(features.genai)
297
+ const result = await query({
298
+ tag: 'iq',
299
+ attrs: { to: WABinary_1.S_WHATSAPP_NET, type: 'get', xmlns: 'w:biz', smax_id: '139' },
300
+ content: [{ tag: 'features', attrs }]
301
+ })
302
+ const mv = (0, WABinary_1.getBinaryNodeChild)(result, 'meta_verified')
303
+ return mv ? { status: mv.attrs?.status, ...mv.attrs } : undefined
304
+ }
305
+ const productUpdate = async (productId, update) => {
306
+ update = await (0, business_1.uploadingNecessaryImagesOfProduct)(update, waUploadToServer)
307
+ const editNode = (0, business_1.toProductNode)(productId, update)
308
+ const result = await query({
309
+ tag: 'iq',
310
+ attrs: {
311
+ to: WABinary_1.S_WHATSAPP_NET,
312
+ type: 'set',
313
+ xmlns: 'w:biz:catalog'
314
+ },
315
+ content: [
316
+ {
317
+ tag: 'product_catalog_edit',
318
+ attrs: { v: '1' },
319
+ content: [
320
+ editNode,
321
+ {
322
+ tag: 'width',
323
+ attrs: {},
324
+ content: '100'
325
+ },
326
+ {
327
+ tag: 'height',
328
+ attrs: {},
329
+ content: '100'
330
+ }
331
+ ]
332
+ }
333
+ ]
334
+ })
335
+ const productCatalogEditNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_edit')
336
+ const productNode = (0, generic_utils_1.getBinaryNodeChild)(productCatalogEditNode, 'product')
337
+ return (0, business_1.parseProductNode)(productNode)
338
+ }
339
+ const productCreate = async create => {
340
+ // ensure isHidden is defined
341
+ create.isHidden = !!create.isHidden
342
+ create = await (0, business_1.uploadingNecessaryImagesOfProduct)(create, waUploadToServer)
343
+ const createNode = (0, business_1.toProductNode)(undefined, create)
344
+ const result = await query({
345
+ tag: 'iq',
346
+ attrs: {
347
+ to: WABinary_1.S_WHATSAPP_NET,
348
+ type: 'set',
349
+ xmlns: 'w:biz:catalog'
350
+ },
351
+ content: [
352
+ {
353
+ tag: 'product_catalog_add',
354
+ attrs: { v: '1' },
355
+ content: [
356
+ createNode,
357
+ {
358
+ tag: 'width',
359
+ attrs: {},
360
+ content: '100'
361
+ },
362
+ {
363
+ tag: 'height',
364
+ attrs: {},
365
+ content: '100'
366
+ }
367
+ ]
368
+ }
369
+ ]
370
+ })
371
+ const productCatalogAddNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_add')
372
+ const productNode = (0, generic_utils_1.getBinaryNodeChild)(productCatalogAddNode, 'product')
373
+ return (0, business_1.parseProductNode)(productNode)
374
+ }
375
+ const productDelete = async productIds => {
376
+ const result = await query({
377
+ tag: 'iq',
378
+ attrs: {
379
+ to: WABinary_1.S_WHATSAPP_NET,
380
+ type: 'set',
381
+ xmlns: 'w:biz:catalog'
382
+ },
383
+ content: [
384
+ {
385
+ tag: 'product_catalog_delete',
386
+ attrs: { v: '1' },
387
+ content: productIds.map(id => ({
388
+ tag: 'product',
389
+ attrs: {},
390
+ content: [
391
+ {
392
+ tag: 'id',
393
+ attrs: {},
394
+ content: Buffer.from(id)
395
+ }
396
+ ]
397
+ }))
398
+ }
399
+ ]
400
+ })
401
+ const productCatalogDelNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_delete')
402
+ return {
403
+ deleted: +(productCatalogDelNode?.attrs.deleted_count || 0)
404
+ }
405
+ }
406
+ return {
407
+ ...sock,
408
+ logger: config.logger,
409
+ getOrderDetails,
410
+ getLinkedAccounts,
411
+ getBusinessEligibility,
412
+ getCatalog,
413
+ getCollections,
414
+ productCreate,
415
+ productDelete,
416
+ productUpdate,
417
+ updateBussinesProfile,
418
+ updateCoverPhoto,
419
+ removeCoverPhoto
420
+ }
421
+ }
422
+ exports.makeBusinessSocket = makeBusinessSocket