@mrlegendbot/baileys 1.2.1 → 1.2.4

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 (212) hide show
  1. package/README.upstream.md +1312 -0
  2. package/WAProto/WAProto.json +1 -0
  3. package/WAProto/WAProto.proto +6275 -0
  4. package/WAProto/compiler.js +550 -0
  5. package/WAProto/index.js +2 -97691
  6. package/lib/Defaults/index.js +89 -92
  7. package/lib/Signal/Group/ciphertext-message.js +9 -10
  8. package/lib/Signal/Group/group-session-builder.js +21 -22
  9. package/lib/Signal/Group/group_cipher.js +75 -69
  10. package/lib/Signal/Group/index.js +0 -1
  11. package/lib/Signal/Group/keyhelper.js +9 -10
  12. package/lib/Signal/Group/sender-chain-key.js +21 -22
  13. package/lib/Signal/Group/sender-key-distribution-message.js +51 -60
  14. package/lib/Signal/Group/sender-key-message.js +56 -62
  15. package/lib/Signal/Group/sender-key-name.js +38 -40
  16. package/lib/Signal/Group/sender-key-record.js +33 -34
  17. package/lib/Signal/Group/sender-key-state.js +72 -76
  18. package/lib/Signal/Group/sender-message-key.js +22 -23
  19. package/lib/Signal/libsignal.js +506 -405
  20. package/lib/Signal/lid-mapping.js +276 -258
  21. package/lib/Socket/Client/index.js +0 -1
  22. package/lib/Socket/Client/types.js +6 -7
  23. package/lib/Socket/Client/websocket.js +48 -49
  24. package/lib/Socket/business.js +349 -369
  25. package/lib/Socket/chats.js +1172 -1148
  26. package/lib/Socket/communities.js +473 -413
  27. package/lib/Socket/groups.js +387 -331
  28. package/lib/Socket/index.js +6 -8
  29. package/lib/Socket/messages-recv.js +1782 -1719
  30. package/lib/Socket/messages-send.js +1503 -2450
  31. package/lib/Socket/mex.js +40 -35
  32. package/lib/Socket/newsletter.js +239 -191
  33. package/lib/Socket/socket.js +992 -923
  34. package/lib/Store/index.js +8 -0
  35. package/lib/Store/keyed-db.js +108 -0
  36. package/lib/Store/make-cache-manager-store.js +70 -0
  37. package/lib/Store/make-in-memory-store.js +417 -0
  38. package/lib/Store/make-ordered-dictionary.js +69 -0
  39. package/lib/Store/object-repository.js +27 -0
  40. package/lib/Types/Auth.js +0 -1
  41. package/lib/Types/Bussines.js +0 -1
  42. package/lib/Types/Call.js +0 -1
  43. package/lib/Types/Chat.js +1 -8
  44. package/lib/Types/Contact.js +0 -1
  45. package/lib/Types/Events.js +1 -2
  46. package/lib/Types/GroupMetadata.js +0 -1
  47. package/lib/Types/Label.js +20 -22
  48. package/lib/Types/LabelAssociation.js +2 -4
  49. package/lib/Types/Message.js +3 -5
  50. package/lib/Types/Mex.js +26 -31
  51. package/lib/Types/Product.js +0 -1
  52. package/lib/Types/Signal.js +1 -2
  53. package/lib/Types/Socket.js +2 -3
  54. package/lib/Types/State.js +4 -52
  55. package/lib/Types/USync.js +0 -1
  56. package/lib/Types/index.js +10 -11
  57. package/lib/Utils/auth-utils.js +240 -277
  58. package/lib/Utils/browser-utils.js +20 -23
  59. package/lib/Utils/business.js +200 -204
  60. package/lib/Utils/chat-utils.js +836 -810
  61. package/lib/Utils/companion-reg-client-utils.js +23 -25
  62. package/lib/Utils/crypto.js +70 -86
  63. package/lib/Utils/decode-wa-message.js +277 -284
  64. package/lib/Utils/event-buffer.js +592 -595
  65. package/lib/Utils/generics.js +312 -335
  66. package/lib/Utils/history.js +123 -115
  67. package/lib/Utils/index.js +1 -2
  68. package/lib/Utils/link-preview.js +74 -73
  69. package/lib/Utils/logger.js +3 -2
  70. package/lib/Utils/lt-hash.js +0 -6
  71. package/lib/Utils/make-mutex.js +27 -27
  72. package/lib/Utils/message-retry-manager.js +213 -254
  73. package/lib/Utils/messages-media.js +741 -715
  74. package/lib/Utils/messages.js +791 -827
  75. package/lib/Utils/noise-handler.js +215 -187
  76. package/lib/Utils/pre-key-manager.js +69 -98
  77. package/lib/Utils/process-message.js +617 -586
  78. package/lib/Utils/reporting-utils.js +553 -234
  79. package/lib/Utils/signal.js +217 -170
  80. package/lib/Utils/stanza-ack.js +27 -35
  81. package/lib/Utils/sync-action-utils.js +37 -41
  82. package/lib/Utils/tc-token-utils.js +120 -141
  83. package/lib/Utils/use-multi-file-auth-state.js +87 -105
  84. package/lib/Utils/use-sqlite-auth-state.js +162 -0
  85. package/lib/Utils/validate-connection.js +190 -188
  86. package/lib/WABinary/constants.js +28 -1294
  87. package/lib/WABinary/decode.js +245 -249
  88. package/lib/WABinary/encode.js +201 -206
  89. package/lib/WABinary/generic-utils.js +86 -89
  90. package/lib/WABinary/index.js +0 -1
  91. package/lib/WABinary/jid-utils.js +68 -77
  92. package/lib/WABinary/types.js +0 -1
  93. package/lib/WAM/BinaryInfo.js +7 -8
  94. package/lib/WAM/constants.js +19892 -22853
  95. package/lib/WAM/encode.js +121 -132
  96. package/lib/WAM/index.js +0 -1
  97. package/lib/WAUSync/Protocols/USyncContactProtocol.js +46 -43
  98. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +47 -48
  99. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -23
  100. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -33
  101. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -20
  102. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -44
  103. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
  104. package/lib/WAUSync/Protocols/index.js +0 -1
  105. package/lib/WAUSync/USyncQuery.js +79 -88
  106. package/lib/WAUSync/USyncUser.js +28 -29
  107. package/lib/WAUSync/index.js +0 -1
  108. package/lib/index.js +2 -2
  109. package/package.json +22 -86
  110. package/WAProto/GenerateStatics.sh +0 -3
  111. package/WAProto/fix-imports.js +0 -85
  112. package/WAProto/index.d.ts +0 -14017
  113. package/lib/Defaults/index.d.ts +0 -75
  114. package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
  115. package/lib/Signal/Group/group-session-builder.d.ts +0 -15
  116. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  117. package/lib/Signal/Group/index.d.ts +0 -12
  118. package/lib/Signal/Group/keyhelper.d.ts +0 -11
  119. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  120. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  121. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  122. package/lib/Signal/Group/sender-key-name.d.ts +0 -18
  123. package/lib/Signal/Group/sender-key-record.d.ts +0 -31
  124. package/lib/Signal/Group/sender-key-state.d.ts +0 -39
  125. package/lib/Signal/Group/sender-message-key.d.ts +0 -12
  126. package/lib/Signal/libsignal.d.ts +0 -5
  127. package/lib/Signal/lid-mapping.d.ts +0 -23
  128. package/lib/Socket/Client/index.d.ts +0 -3
  129. package/lib/Socket/Client/types.d.ts +0 -16
  130. package/lib/Socket/Client/websocket.d.ts +0 -13
  131. package/lib/Socket/business.d.ts +0 -217
  132. package/lib/Socket/chats.d.ts +0 -125
  133. package/lib/Socket/communities.d.ts +0 -273
  134. package/lib/Socket/groups.d.ts +0 -161
  135. package/lib/Socket/index.d.ts +0 -260
  136. package/lib/Socket/messages-recv.d.ts +0 -203
  137. package/lib/Socket/messages-send.d.ts +0 -199
  138. package/lib/Socket/mex.d.ts +0 -3
  139. package/lib/Socket/newsletter.d.ts +0 -170
  140. package/lib/Socket/socket.d.ts +0 -59
  141. package/lib/Types/Auth.d.ts +0 -117
  142. package/lib/Types/Bussines.d.ts +0 -25
  143. package/lib/Types/Call.d.ts +0 -15
  144. package/lib/Types/Chat.d.ts +0 -124
  145. package/lib/Types/Contact.d.ts +0 -26
  146. package/lib/Types/Events.d.ts +0 -256
  147. package/lib/Types/GroupMetadata.d.ts +0 -71
  148. package/lib/Types/Label.d.ts +0 -47
  149. package/lib/Types/LabelAssociation.d.ts +0 -30
  150. package/lib/Types/Message.d.ts +0 -320
  151. package/lib/Types/Mex.d.ts +0 -141
  152. package/lib/Types/Product.d.ts +0 -79
  153. package/lib/Types/Signal.d.ts +0 -87
  154. package/lib/Types/Socket.d.ts +0 -136
  155. package/lib/Types/State.d.ts +0 -97
  156. package/lib/Types/USync.d.ts +0 -26
  157. package/lib/Types/index.d.ts +0 -66
  158. package/lib/Utils/auth-utils.d.ts +0 -24
  159. package/lib/Utils/browser-utils.d.ts +0 -4
  160. package/lib/Utils/business.d.ts +0 -23
  161. package/lib/Utils/chat-utils.d.ts +0 -100
  162. package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
  163. package/lib/Utils/crypto.d.ts +0 -37
  164. package/lib/Utils/decode-wa-message.d.ts +0 -66
  165. package/lib/Utils/event-buffer.d.ts +0 -36
  166. package/lib/Utils/generics.d.ts +0 -92
  167. package/lib/Utils/history.d.ts +0 -24
  168. package/lib/Utils/identity-change-handler.d.ts +0 -44
  169. package/lib/Utils/identity-change-handler.js +0 -50
  170. package/lib/Utils/index.d.ts +0 -22
  171. package/lib/Utils/link-preview.d.ts +0 -21
  172. package/lib/Utils/logger.d.ts +0 -12
  173. package/lib/Utils/lt-hash.d.ts +0 -8
  174. package/lib/Utils/make-mutex.d.ts +0 -9
  175. package/lib/Utils/message-retry-manager.d.ts +0 -115
  176. package/lib/Utils/messages-media.d.ts +0 -133
  177. package/lib/Utils/messages.d.ts +0 -91
  178. package/lib/Utils/noise-handler.d.ts +0 -20
  179. package/lib/Utils/offline-node-processor.d.ts +0 -17
  180. package/lib/Utils/offline-node-processor.js +0 -40
  181. package/lib/Utils/pre-key-manager.d.ts +0 -28
  182. package/lib/Utils/process-message.d.ts +0 -60
  183. package/lib/Utils/reporting-utils.d.ts +0 -11
  184. package/lib/Utils/signal.d.ts +0 -47
  185. package/lib/Utils/stanza-ack.d.ts +0 -11
  186. package/lib/Utils/sync-action-utils.d.ts +0 -19
  187. package/lib/Utils/tc-token-utils.d.ts +0 -37
  188. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  189. package/lib/Utils/validate-connection.d.ts +0 -11
  190. package/lib/WABinary/constants.d.ts +0 -28
  191. package/lib/WABinary/decode.d.ts +0 -7
  192. package/lib/WABinary/encode.d.ts +0 -3
  193. package/lib/WABinary/generic-utils.d.ts +0 -15
  194. package/lib/WABinary/index.d.ts +0 -6
  195. package/lib/WABinary/jid-utils.d.ts +0 -48
  196. package/lib/WABinary/types.d.ts +0 -19
  197. package/lib/WAM/BinaryInfo.d.ts +0 -9
  198. package/lib/WAM/constants.d.ts +0 -40
  199. package/lib/WAM/encode.d.ts +0 -3
  200. package/lib/WAM/index.d.ts +0 -4
  201. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  202. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -23
  203. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -13
  204. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -13
  205. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
  206. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
  207. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
  208. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  209. package/lib/WAUSync/USyncQuery.d.ts +0 -30
  210. package/lib/WAUSync/USyncUser.d.ts +0 -17
  211. package/lib/WAUSync/index.d.ts +0 -4
  212. package/lib/index.d.ts +0 -12
@@ -3,377 +3,357 @@ import { parseCatalogNode, parseCollectionsNode, parseOrderDetailsNode, parsePro
3
3
  import { jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
4
4
  import { getBinaryNodeChild } from '../WABinary/generic-utils.js';
5
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',
6
+ export const makeBusinessSocket = config => {
7
+ const sock = makeMessagesRecvSocket(config);
8
+ const {
9
+ authState,
10
+ query,
11
+ waUploadToServer
12
+ } = sock;
13
+ const updateBussinesProfile = async args => {
14
+ const node = [];
15
+ const simpleFields = ['address', 'email', 'description'];
16
+ node.push(...simpleFields.filter(key => args[key] !== undefined && args[key] !== null).map(key => ({
17
+ tag: key,
18
+ attrs: {},
19
+ content: args[key]
20
+ })));
21
+ if (args.websites !== undefined) {
22
+ node.push(...args.websites.map(website => ({
23
+ tag: 'website',
24
+ attrs: {},
25
+ content: website
26
+ })));
27
+ }
28
+ if (args.hours !== undefined) {
29
+ node.push({
30
+ tag: 'business_hours',
31
+ attrs: {
32
+ timezone: args.hours.timezone
33
+ },
34
+ content: args.hours.days.map(dayConfig => {
35
+ const base = {
36
+ tag: 'business_hours_config',
81
37
  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')
38
+ day_of_week: dayConfig.day,
39
+ mode: dayConfig.mode
147
40
  }
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
- };
41
+ };
42
+ if (dayConfig.mode === 'specific_hours') {
43
+ return {
44
+ ...base,
45
+ attrs: {
46
+ ...base.attrs,
47
+ open_time: dayConfig.openTimeInMinutes,
48
+ close_time: dayConfig.closeTimeInMinutes
49
+ }
50
+ };
51
+ }
52
+ return base;
53
+ })
54
+ });
55
+ }
56
+ const result = await query({
57
+ tag: 'iq',
58
+ attrs: {
59
+ to: S_WHATSAPP_NET,
60
+ type: 'set',
61
+ xmlns: 'w:biz'
62
+ },
63
+ content: [{
64
+ tag: 'business_profile',
65
+ attrs: {
66
+ v: '3',
67
+ mutation_type: 'delta'
68
+ },
69
+ content: node
70
+ }]
71
+ });
72
+ return result;
73
+ };
74
+ const updateCoverPhoto = async photo => {
75
+ const {
76
+ fileSha256,
77
+ filePath
78
+ } = await getRawMediaUploadData(photo, 'biz-cover-photo');
79
+ const fileSha256B64 = fileSha256.toString('base64');
80
+ const {
81
+ meta_hmac,
82
+ fbid,
83
+ ts
84
+ } = await waUploadToServer(filePath, {
85
+ fileEncSha256B64: fileSha256B64,
86
+ mediaType: 'biz-cover-photo'
87
+ });
88
+ await query({
89
+ tag: 'iq',
90
+ attrs: {
91
+ to: S_WHATSAPP_NET,
92
+ type: 'set',
93
+ xmlns: 'w:biz'
94
+ },
95
+ content: [{
96
+ tag: 'business_profile',
97
+ attrs: {
98
+ v: '3',
99
+ mutation_type: 'delta'
100
+ },
101
+ content: [{
102
+ tag: 'cover_photo',
103
+ attrs: {
104
+ id: String(fbid),
105
+ op: 'update',
106
+ token: meta_hmac,
107
+ ts: String(ts)
108
+ }
109
+ }]
110
+ }]
111
+ });
112
+ return fbid;
113
+ };
114
+ const removeCoverPhoto = async id => {
115
+ return await query({
116
+ tag: 'iq',
117
+ attrs: {
118
+ to: S_WHATSAPP_NET,
119
+ type: 'set',
120
+ xmlns: 'w:biz'
121
+ },
122
+ content: [{
123
+ tag: 'business_profile',
124
+ attrs: {
125
+ v: '3',
126
+ mutation_type: 'delta'
127
+ },
128
+ content: [{
129
+ tag: 'cover_photo',
130
+ attrs: {
131
+ op: 'delete',
132
+ id
133
+ }
134
+ }]
135
+ }]
136
+ });
137
+ };
138
+ const getCatalog = async ({
139
+ jid,
140
+ limit,
141
+ cursor
142
+ }) => {
143
+ jid = jid || authState.creds.me?.id;
144
+ jid = jidNormalizedUser(jid);
145
+ const queryParamNodes = [{
146
+ tag: 'limit',
147
+ attrs: {},
148
+ content: Buffer.from((limit || 10).toString())
149
+ }, {
150
+ tag: 'width',
151
+ attrs: {},
152
+ content: Buffer.from('100')
153
+ }, {
154
+ tag: 'height',
155
+ attrs: {},
156
+ content: Buffer.from('100')
157
+ }];
158
+ if (cursor) {
159
+ queryParamNodes.push({
160
+ tag: 'after',
161
+ attrs: {},
162
+ content: cursor
163
+ });
164
+ }
165
+ const result = await query({
166
+ tag: 'iq',
167
+ attrs: {
168
+ to: S_WHATSAPP_NET,
169
+ type: 'get',
170
+ xmlns: 'w:biz:catalog'
171
+ },
172
+ content: [{
173
+ tag: 'product_catalog',
174
+ attrs: {
175
+ jid,
176
+ allow_shop_source: 'true'
177
+ },
178
+ content: queryParamNodes
179
+ }]
180
+ });
181
+ return parseCatalogNode(result);
182
+ };
183
+ const getCollections = async (jid, limit = 51) => {
184
+ jid = jid || authState.creds.me?.id;
185
+ jid = jidNormalizedUser(jid);
186
+ const result = await query({
187
+ tag: 'iq',
188
+ attrs: {
189
+ to: S_WHATSAPP_NET,
190
+ type: 'get',
191
+ xmlns: 'w:biz:catalog',
192
+ smax_id: '35'
193
+ },
194
+ content: [{
195
+ tag: 'collections',
196
+ attrs: {
197
+ biz_jid: jid
198
+ },
199
+ content: [{
200
+ tag: 'collection_limit',
201
+ attrs: {},
202
+ content: Buffer.from(limit.toString())
203
+ }, {
204
+ tag: 'item_limit',
205
+ attrs: {},
206
+ content: Buffer.from(limit.toString())
207
+ }, {
208
+ tag: 'width',
209
+ attrs: {},
210
+ content: Buffer.from('100')
211
+ }, {
212
+ tag: 'height',
213
+ attrs: {},
214
+ content: Buffer.from('100')
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
+ tag: 'order',
231
+ attrs: {
232
+ op: 'get',
233
+ id: orderId
234
+ },
235
+ content: [{
236
+ tag: 'image_dimensions',
237
+ attrs: {},
238
+ content: [{
239
+ tag: 'width',
240
+ attrs: {},
241
+ content: Buffer.from('100')
242
+ }, {
243
+ tag: 'height',
244
+ attrs: {},
245
+ content: Buffer.from('100')
246
+ }]
247
+ }, {
248
+ tag: 'token',
249
+ attrs: {},
250
+ content: Buffer.from(tokenBase64)
251
+ }]
252
+ }]
253
+ });
254
+ return parseOrderDetailsNode(result);
255
+ };
256
+ const productUpdate = async (productId, update) => {
257
+ update = await uploadingNecessaryImagesOfProduct(update, waUploadToServer);
258
+ const editNode = toProductNode(productId, update);
259
+ const result = await query({
260
+ tag: 'iq',
261
+ attrs: {
262
+ to: S_WHATSAPP_NET,
263
+ type: 'set',
264
+ xmlns: 'w:biz:catalog'
265
+ },
266
+ content: [{
267
+ tag: 'product_catalog_edit',
268
+ attrs: {
269
+ v: '1'
270
+ },
271
+ content: [editNode, {
272
+ tag: 'width',
273
+ attrs: {},
274
+ content: '100'
275
+ }, {
276
+ tag: 'height',
277
+ attrs: {},
278
+ content: '100'
279
+ }]
280
+ }]
281
+ });
282
+ const productCatalogEditNode = getBinaryNodeChild(result, 'product_catalog_edit');
283
+ const productNode = getBinaryNodeChild(productCatalogEditNode, 'product');
284
+ return parseProductNode(productNode);
285
+ };
286
+ const productCreate = async create => {
287
+ create.isHidden = !!create.isHidden;
288
+ create = await uploadingNecessaryImagesOfProduct(create, waUploadToServer);
289
+ const createNode = toProductNode(undefined, create);
290
+ const result = await query({
291
+ tag: 'iq',
292
+ attrs: {
293
+ to: S_WHATSAPP_NET,
294
+ type: 'set',
295
+ xmlns: 'w:biz:catalog'
296
+ },
297
+ content: [{
298
+ tag: 'product_catalog_add',
299
+ attrs: {
300
+ v: '1'
301
+ },
302
+ content: [createNode, {
303
+ tag: 'width',
304
+ attrs: {},
305
+ content: '100'
306
+ }, {
307
+ tag: 'height',
308
+ attrs: {},
309
+ content: '100'
310
+ }]
311
+ }]
312
+ });
313
+ const productCatalogAddNode = getBinaryNodeChild(result, 'product_catalog_add');
314
+ const productNode = getBinaryNodeChild(productCatalogAddNode, 'product');
315
+ return parseProductNode(productNode);
316
+ };
317
+ const productDelete = async productIds => {
318
+ const result = await query({
319
+ tag: 'iq',
320
+ attrs: {
321
+ to: S_WHATSAPP_NET,
322
+ type: 'set',
323
+ xmlns: 'w:biz:catalog'
324
+ },
325
+ content: [{
326
+ tag: 'product_catalog_delete',
327
+ attrs: {
328
+ v: '1'
329
+ },
330
+ content: productIds.map(id => ({
331
+ tag: 'product',
332
+ attrs: {},
333
+ content: [{
334
+ tag: 'id',
335
+ attrs: {},
336
+ content: Buffer.from(id)
337
+ }]
338
+ }))
339
+ }]
340
+ });
341
+ const productCatalogDelNode = getBinaryNodeChild(result, 'product_catalog_delete');
365
342
  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
343
+ deleted: +(productCatalogDelNode?.attrs.deleted_count || 0)
377
344
  };
345
+ };
346
+ return {
347
+ ...sock,
348
+ logger: config.logger,
349
+ getOrderDetails,
350
+ getCatalog,
351
+ getCollections,
352
+ productCreate,
353
+ productDelete,
354
+ productUpdate,
355
+ updateBussinesProfile,
356
+ updateCoverPhoto,
357
+ removeCoverPhoto
358
+ };
378
359
  };
379
- //# sourceMappingURL=business.js.map