@badzz88/baileys 8.5.7 → 8.5.8

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 (142) hide show
  1. package/README.md +337 -1055
  2. package/WAProto/WAProto.proto +284 -264
  3. package/WAProto/index.js +5 -5
  4. package/engine-requirements.js +7 -15
  5. package/lib/Defaults/index.js +130 -187
  6. package/lib/Signal/Group/ciphertext-message.js +11 -14
  7. package/lib/Signal/Group/group-session-builder.js +29 -91
  8. package/lib/Signal/Group/group_cipher.js +81 -88
  9. package/lib/Signal/Group/index.js +12 -136
  10. package/lib/Signal/Group/keyhelper.js +15 -70
  11. package/lib/Signal/Group/sender-chain-key.js +25 -31
  12. package/lib/Signal/Group/sender-key-distribution-message.js +62 -65
  13. package/lib/Signal/Group/sender-key-message.js +65 -68
  14. package/lib/Signal/Group/sender-key-name.js +41 -43
  15. package/lib/Signal/Group/sender-key-record.js +40 -43
  16. package/lib/Signal/Group/sender-key-state.js +83 -96
  17. package/lib/Signal/Group/sender-message-key.js +25 -29
  18. package/lib/Signal/libsignal.js +425 -453
  19. package/lib/Signal/lid-mapping.js +276 -259
  20. package/lib/Socket/Client/index.js +3 -30
  21. package/lib/Socket/Client/types.js +10 -12
  22. package/lib/Socket/Client/websocket.js +53 -61
  23. package/lib/Socket/business.js +379 -422
  24. package/lib/Socket/chats.js +1193 -1816
  25. package/lib/Socket/communities.js +431 -549
  26. package/lib/Socket/graphql.js +672 -612
  27. package/lib/Socket/groups.js +374 -764
  28. package/lib/Socket/index.js +17 -38
  29. package/lib/Socket/interop.js +417 -503
  30. package/lib/Socket/messages-recv.js +1915 -2441
  31. package/lib/Socket/messages-send.js +1213 -1630
  32. package/lib/Socket/mex.js +9 -15
  33. package/lib/Socket/newsletter.js +747 -808
  34. package/lib/Socket/privacy.js +310 -441
  35. package/lib/Socket/socket.js +1025 -1022
  36. package/lib/Socket/username.js +8 -15
  37. package/lib/Store/index.js +10 -36
  38. package/lib/Store/make-cache-manager-store.js +80 -85
  39. package/lib/Store/make-in-memory-store.js +231 -591
  40. package/lib/Store/make-ordered-dictionary.js +72 -78
  41. package/lib/Store/object-repository.js +28 -25
  42. package/lib/Types/Auth.js +2 -38
  43. package/lib/Types/Bussines.js +2 -2
  44. package/lib/Types/Call.js +2 -2
  45. package/lib/Types/Chat.js +8 -4
  46. package/lib/Types/Contact.js +2 -2
  47. package/lib/Types/Events.js +2 -2
  48. package/lib/Types/GroupMetadata.js +2 -2
  49. package/lib/Types/Label.js +24 -26
  50. package/lib/Types/LabelAssociation.js +6 -8
  51. package/lib/Types/Message.js +11 -95
  52. package/lib/Types/Mex.js +111 -112
  53. package/lib/Types/Product.js +2 -2
  54. package/lib/Types/Signal.js +2 -2
  55. package/lib/Types/Socket.js +3 -2
  56. package/lib/Types/State.js +56 -70
  57. package/lib/Types/USync.js +2 -2
  58. package/lib/Types/index.js +26 -55
  59. package/lib/Utils/auth-utils.js +288 -292
  60. package/lib/Utils/browser-utils.js +47 -113
  61. package/lib/Utils/business.js +224 -240
  62. package/lib/Utils/chat-utils.js +869 -1205
  63. package/lib/Utils/companion-reg-client-utils.js +34 -41
  64. package/lib/Utils/crypto.js +107 -144
  65. package/lib/Utils/decode-wa-message.js +308 -518
  66. package/lib/Utils/event-buffer.js +611 -596
  67. package/lib/Utils/generics.js +355 -515
  68. package/lib/Utils/history.js +134 -244
  69. package/lib/Utils/identity-change-handler.js +49 -51
  70. package/lib/Utils/index.js +23 -57
  71. package/lib/Utils/link-preview.js +77 -135
  72. package/lib/Utils/logger.js +3 -9
  73. package/lib/Utils/lt-hash.js +6 -37
  74. package/lib/Utils/make-mutex.js +33 -36
  75. package/lib/Utils/message-composer.js +233 -439
  76. package/lib/Utils/message-retry-manager.js +260 -265
  77. package/lib/Utils/messages-media.js +829 -855
  78. package/lib/Utils/messages.js +961 -2528
  79. package/lib/Utils/noise-handler.js +200 -195
  80. package/lib/Utils/offline-node-processor.js +33 -35
  81. package/lib/Utils/pre-key-manager.js +102 -103
  82. package/lib/Utils/process-message.js +560 -978
  83. package/lib/Utils/reporting-utils.js +253 -257
  84. package/lib/Utils/signal.js +195 -218
  85. package/lib/Utils/stanza-ack.js +29 -31
  86. package/lib/Utils/sticker.js +109 -144
  87. package/lib/Utils/sync-action-utils.js +45 -50
  88. package/lib/Utils/tc-token-utils.js +139 -137
  89. package/lib/Utils/use-multi-file-auth-state.js +109 -109
  90. package/lib/Utils/validate-connection.js +202 -218
  91. package/lib/WABinary/constants.js +1299 -1302
  92. package/lib/WABinary/decode.js +262 -343
  93. package/lib/WABinary/encode.js +4 -12
  94. package/lib/WABinary/generic-utils.js +187 -223
  95. package/lib/WABinary/index.js +6 -33
  96. package/lib/WABinary/jid-utils.js +88 -351
  97. package/lib/WABinary/types.js +2 -2
  98. package/lib/WAM/BinaryInfo.js +9 -12
  99. package/lib/WAM/constants.js +22853 -39486
  100. package/lib/WAM/encode.js +140 -132
  101. package/lib/WAM/index.js +4 -31
  102. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +21 -23
  103. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +9 -9
  104. package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -7
  105. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -10
  106. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +7 -7
  107. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +11 -12
  108. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +4 -5
  109. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +7 -7
  110. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +7 -8
  111. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -7
  112. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +8 -8
  113. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +7 -7
  114. package/lib/WAUSync/Protocols/index.js +12 -39
  115. package/lib/WAUSync/USyncQuery.js +67 -49
  116. package/lib/WAUSync/USyncUser.js +11 -5
  117. package/lib/WAUSync/index.js +3 -31
  118. package/lib/index.js +15 -48
  119. package/package.json +129 -99
  120. package/LICENSE +0 -21
  121. package/lib/Defaults/phonenumber-mcc.json +0 -223
  122. package/lib/Socket/aigroups.js +0 -240
  123. package/lib/Socket/interactive-handler.js +0 -522
  124. package/lib/Socket/managed-account.js +0 -183
  125. package/lib/Socket/registration.js +0 -427
  126. package/lib/Socket/text-router.js +0 -83
  127. package/lib/Types/Newsletter.js +0 -121
  128. package/lib/Utils/command-loader.d.ts +0 -31
  129. package/lib/Utils/command-loader.js +0 -100
  130. package/lib/Utils/consumer-application.js +0 -107
  131. package/lib/Utils/curve25519-js.js +0 -275
  132. package/lib/Utils/group-history.js +0 -60
  133. package/lib/Utils/jid-display-normalization.js +0 -218
  134. package/lib/Utils/meta-ai-msmsg.js +0 -262
  135. package/lib/Utils/native-bridge.js +0 -82
  136. package/lib/Utils/session-pool.d.ts +0 -16
  137. package/lib/Utils/session-pool.js +0 -94
  138. package/lib/Utils/sticker.d.ts +0 -17
  139. package/lib/Utils/view-once-cache.d.ts +0 -9
  140. package/lib/Utils/view-once-cache.js +0 -79
  141. package/lib/Utils/voip-rekey.js +0 -22
  142. package/lib/antiban.js +0 -4637
@@ -1,422 +1,379 @@
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
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