lordceaser-baileys 3.3.8 → 3.4.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.
- package/WAProto/index.js +1 -2
- package/index.js +4 -16
- package/lib/Socket/Client/index.js +0 -1
- package/lib/Socket/Client/types.js +1 -2
- package/lib/Socket/Client/websocket.js +1 -2
- package/lib/Socket/business.js +70 -42
- package/lib/Socket/chats.js +731 -21
- package/lib/Socket/communities.js +1 -1
- package/lib/Socket/groups.js +207 -5
- package/lib/Socket/index.js +28 -3
- package/lib/Socket/messages-recv.js +381 -9
- package/lib/Socket/messages-send.js +2189 -157
- package/lib/Socket/mex.js +1 -2
- package/lib/Socket/newsletter.js +98 -19
- package/lib/Socket/socket.js +64 -17
- package/lib/Utils/crypto.js +6 -5
- package/lib/Utils/lt-hash.js +3 -8
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +1 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +1 -2
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +2 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -2
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -2
- package/lib/WAUSync/Protocols/index.js +7 -1
- package/lib/WAUSync/USyncQuery.js +126 -23
- package/lib/WAUSync/USyncUser.js +24 -1
- package/lib/WAUSync/index.js +1 -2
- package/package.json +2 -6
- package/lib/Socket/Socket/Client/index.js +0 -2
- package/lib/Socket/Socket/Client/types.js +0 -10
- package/lib/Socket/Socket/Client/websocket.js +0 -53
- package/lib/Socket/Socket/business.js +0 -407
- package/lib/Socket/Socket/chats.js +0 -1908
- package/lib/Socket/Socket/communities.js +0 -431
- package/lib/Socket/Socket/groups.js +0 -549
- package/lib/Socket/Socket/index.js +0 -37
- package/lib/Socket/Socket/messages-recv.js +0 -2144
- package/lib/Socket/Socket/messages-send.js +0 -3177
- package/lib/Socket/Socket/mex.js +0 -41
- package/lib/Socket/Socket/newsletter.js +0 -260
- package/lib/Socket/Socket/socket.js +0 -1017
- package/lib/Utils/_crypto_orig.js +0 -118
- package/lib/WAUSync/WAUSync/Protocols/USyncContactProtocol.js +0 -56
- package/lib/WAUSync/WAUSync/Protocols/USyncDeviceProtocol.js +0 -53
- package/lib/WAUSync/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -26
- package/lib/WAUSync/WAUSync/Protocols/USyncStatusProtocol.js +0 -37
- package/lib/WAUSync/WAUSync/Protocols/USyncUsernameProtocol.js +0 -24
- package/lib/WAUSync/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -50
- package/lib/WAUSync/WAUSync/Protocols/UsyncLIDProtocol.js +0 -28
- package/lib/WAUSync/WAUSync/Protocols/index.js +0 -12
- package/lib/WAUSync/WAUSync/USyncQuery.js +0 -201
- package/lib/WAUSync/WAUSync/USyncUser.js +0 -54
- package/lib/WAUSync/WAUSync/index.js +0 -3
- /package/lib/Socket/{Socket/aigroups.js → aigroups.js} +0 -0
- /package/lib/Socket/{Socket/ban-checker.js → ban-checker.js} +0 -0
- /package/lib/Socket/{Socket/chats.js[old] → chats.js[old]} +0 -0
- /package/lib/Socket/{Socket/graphql.js → graphql.js} +0 -0
- /package/lib/Socket/{Socket/groups.js[old] → groups.js[old]} +0 -0
- /package/lib/Socket/{Socket/interactive-handler.js → interactive-handler.js} +0 -0
- /package/lib/Socket/{Socket/interop.js → interop.js} +0 -0
- /package/lib/Socket/{Socket/managed-account.js → managed-account.js} +0 -0
- /package/lib/Socket/{Socket/privacy.js → privacy.js} +0 -0
- /package/lib/Socket/{Socket/registration.js → registration.js} +0 -0
- /package/lib/Socket/{Socket/username.js → username.js} +0 -0
- /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncBusinessProtocol.js +0 -0
- /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncFeatureProtocol.js +0 -0
- /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncPictureProtocol.js +0 -0
- /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncSidelistProtocol.js +0 -0
- /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncTextStatusProtocol.js +0 -0
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
import { unlink } from 'node:fs/promises';
|
|
2
|
-
import { getRawMediaUploadData } from '../Utils/index.js';
|
|
3
|
-
import { parseCatalogNode, parseCollectionsNode, parseOrderDetailsNode, parseProductNode, toProductNode, uploadingNecessaryImagesOfProduct } from '../Utils/business.js';
|
|
4
|
-
import { jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
5
|
-
import { getBinaryNodeChild } from '../WABinary/generic-utils.js';
|
|
6
|
-
import { makeMessagesRecvSocket } from './messages-recv.js';
|
|
7
|
-
export const makeBusinessSocket = (config) => {
|
|
8
|
-
const sock = makeMessagesRecvSocket(config);
|
|
9
|
-
const { authState, query, waUploadToServer } = sock;
|
|
10
|
-
const updateBusinessProfile = async (args = {}) => {
|
|
11
|
-
const node = [];
|
|
12
|
-
const simpleFields = ['address', 'email', 'description'];
|
|
13
|
-
node.push(...simpleFields
|
|
14
|
-
.filter(key => args[key] !== undefined)
|
|
15
|
-
.map(key => {
|
|
16
|
-
if (args[key] !== null && typeof args[key] !== 'string') {
|
|
17
|
-
throw new TypeError(`${key} must be a string or null`);
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
tag: key,
|
|
21
|
-
attrs: {},
|
|
22
|
-
content: args[key] ?? ''
|
|
23
|
-
};
|
|
24
|
-
}));
|
|
25
|
-
if (args.websites !== undefined) {
|
|
26
|
-
if (!Array.isArray(args.websites) || args.websites.some(website => typeof website !== 'string')) {
|
|
27
|
-
throw new TypeError('websites must be an array of strings');
|
|
28
|
-
}
|
|
29
|
-
node.push(...(args.websites.length ? args.websites : ['']).map(website => ({
|
|
30
|
-
tag: 'website',
|
|
31
|
-
attrs: {},
|
|
32
|
-
content: website
|
|
33
|
-
})));
|
|
34
|
-
}
|
|
35
|
-
if (args.hours !== undefined) {
|
|
36
|
-
if (!args.hours || typeof args.hours.timezone !== 'string' || !Array.isArray(args.hours.days)) {
|
|
37
|
-
throw new TypeError('hours must contain a timezone string and days array');
|
|
38
|
-
}
|
|
39
|
-
node.push({
|
|
40
|
-
tag: 'business_hours',
|
|
41
|
-
attrs: { timezone: args.hours.timezone },
|
|
42
|
-
content: args.hours.days.map(dayConfig => {
|
|
43
|
-
if (!dayConfig || typeof dayConfig.day !== 'string' || typeof dayConfig.mode !== 'string') {
|
|
44
|
-
throw new TypeError('each business-hours day requires string day and mode values');
|
|
45
|
-
}
|
|
46
|
-
const base = {
|
|
47
|
-
tag: 'business_hours_config',
|
|
48
|
-
attrs: {
|
|
49
|
-
day_of_week: dayConfig.day,
|
|
50
|
-
mode: dayConfig.mode
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
if (dayConfig.mode === 'specific_hours') {
|
|
54
|
-
const { openTimeInMinutes, closeTimeInMinutes } = dayConfig;
|
|
55
|
-
if (!Number.isInteger(openTimeInMinutes) || !Number.isInteger(closeTimeInMinutes)) {
|
|
56
|
-
throw new TypeError('specific_hours requires integer openTimeInMinutes and closeTimeInMinutes');
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
...base,
|
|
60
|
-
attrs: {
|
|
61
|
-
...base.attrs,
|
|
62
|
-
open_time: String(openTimeInMinutes),
|
|
63
|
-
close_time: String(closeTimeInMinutes)
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return base;
|
|
68
|
-
})
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
const result = await query({
|
|
72
|
-
tag: 'iq',
|
|
73
|
-
attrs: {
|
|
74
|
-
to: S_WHATSAPP_NET,
|
|
75
|
-
type: 'set',
|
|
76
|
-
xmlns: 'w:biz'
|
|
77
|
-
},
|
|
78
|
-
content: [
|
|
79
|
-
{
|
|
80
|
-
tag: 'business_profile',
|
|
81
|
-
attrs: {
|
|
82
|
-
v: '3',
|
|
83
|
-
mutation_type: 'delta'
|
|
84
|
-
},
|
|
85
|
-
content: node
|
|
86
|
-
}
|
|
87
|
-
]
|
|
88
|
-
});
|
|
89
|
-
return result;
|
|
90
|
-
};
|
|
91
|
-
const updateCoverPhoto = async (photo) => {
|
|
92
|
-
const { fileSha256, filePath } = await getRawMediaUploadData(photo, 'biz-cover-photo', config.logger);
|
|
93
|
-
try {
|
|
94
|
-
const fileSha256B64 = fileSha256.toString('base64');
|
|
95
|
-
const upload = await waUploadToServer(filePath, {
|
|
96
|
-
fileEncSha256B64: fileSha256B64,
|
|
97
|
-
mediaType: 'biz-cover-photo'
|
|
98
|
-
});
|
|
99
|
-
const { meta_hmac, fbid, ts } = upload || {};
|
|
100
|
-
if (fbid === undefined || fbid === null || !meta_hmac || ts === undefined || ts === null) {
|
|
101
|
-
throw new Error('Business cover photo upload returned incomplete metadata');
|
|
102
|
-
}
|
|
103
|
-
await query({
|
|
104
|
-
tag: 'iq',
|
|
105
|
-
attrs: {
|
|
106
|
-
to: S_WHATSAPP_NET,
|
|
107
|
-
type: 'set',
|
|
108
|
-
xmlns: 'w:biz'
|
|
109
|
-
},
|
|
110
|
-
content: [
|
|
111
|
-
{
|
|
112
|
-
tag: 'business_profile',
|
|
113
|
-
attrs: {
|
|
114
|
-
v: '3',
|
|
115
|
-
mutation_type: 'delta'
|
|
116
|
-
},
|
|
117
|
-
content: [
|
|
118
|
-
{
|
|
119
|
-
tag: 'cover_photo',
|
|
120
|
-
attrs: { id: String(fbid), op: 'update', token: String(meta_hmac), ts: String(ts) }
|
|
121
|
-
}
|
|
122
|
-
]
|
|
123
|
-
}
|
|
124
|
-
]
|
|
125
|
-
});
|
|
126
|
-
return fbid;
|
|
127
|
-
}
|
|
128
|
-
finally {
|
|
129
|
-
await unlink(filePath).catch(() => undefined);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
const removeCoverPhoto = async (id) => {
|
|
133
|
-
return await query({
|
|
134
|
-
tag: 'iq',
|
|
135
|
-
attrs: {
|
|
136
|
-
to: S_WHATSAPP_NET,
|
|
137
|
-
type: 'set',
|
|
138
|
-
xmlns: 'w:biz'
|
|
139
|
-
},
|
|
140
|
-
content: [
|
|
141
|
-
{
|
|
142
|
-
tag: 'business_profile',
|
|
143
|
-
attrs: {
|
|
144
|
-
v: '3',
|
|
145
|
-
mutation_type: 'delta'
|
|
146
|
-
},
|
|
147
|
-
content: [
|
|
148
|
-
{
|
|
149
|
-
tag: 'cover_photo',
|
|
150
|
-
attrs: { op: 'delete', id }
|
|
151
|
-
}
|
|
152
|
-
]
|
|
153
|
-
}
|
|
154
|
-
]
|
|
155
|
-
});
|
|
156
|
-
};
|
|
157
|
-
const getCatalog = async ({ jid, limit, cursor }) => {
|
|
158
|
-
jid = jid || authState.creds.me?.id;
|
|
159
|
-
jid = jidNormalizedUser(jid);
|
|
160
|
-
const queryParamNodes = [
|
|
161
|
-
{
|
|
162
|
-
tag: 'limit',
|
|
163
|
-
attrs: {},
|
|
164
|
-
content: Buffer.from((limit || 10).toString())
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
tag: 'width',
|
|
168
|
-
attrs: {},
|
|
169
|
-
content: Buffer.from('100')
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
tag: 'height',
|
|
173
|
-
attrs: {},
|
|
174
|
-
content: Buffer.from('100')
|
|
175
|
-
}
|
|
176
|
-
];
|
|
177
|
-
if (cursor) {
|
|
178
|
-
queryParamNodes.push({
|
|
179
|
-
tag: 'after',
|
|
180
|
-
attrs: {},
|
|
181
|
-
content: cursor
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
const result = await query({
|
|
185
|
-
tag: 'iq',
|
|
186
|
-
attrs: {
|
|
187
|
-
to: S_WHATSAPP_NET,
|
|
188
|
-
type: 'get',
|
|
189
|
-
xmlns: 'w:biz:catalog'
|
|
190
|
-
},
|
|
191
|
-
content: [
|
|
192
|
-
{
|
|
193
|
-
tag: 'product_catalog',
|
|
194
|
-
attrs: {
|
|
195
|
-
jid,
|
|
196
|
-
allow_shop_source: 'true'
|
|
197
|
-
},
|
|
198
|
-
content: queryParamNodes
|
|
199
|
-
}
|
|
200
|
-
]
|
|
201
|
-
});
|
|
202
|
-
return parseCatalogNode(result);
|
|
203
|
-
};
|
|
204
|
-
const getCollections = async (jid, limit = 51) => {
|
|
205
|
-
jid = jid || authState.creds.me?.id;
|
|
206
|
-
jid = jidNormalizedUser(jid);
|
|
207
|
-
const result = await query({
|
|
208
|
-
tag: 'iq',
|
|
209
|
-
attrs: {
|
|
210
|
-
to: S_WHATSAPP_NET,
|
|
211
|
-
type: 'get',
|
|
212
|
-
xmlns: 'w:biz:catalog',
|
|
213
|
-
smax_id: '35'
|
|
214
|
-
},
|
|
215
|
-
content: [
|
|
216
|
-
{
|
|
217
|
-
tag: 'collections',
|
|
218
|
-
attrs: {
|
|
219
|
-
biz_jid: jid
|
|
220
|
-
},
|
|
221
|
-
content: [
|
|
222
|
-
{
|
|
223
|
-
tag: 'collection_limit',
|
|
224
|
-
attrs: {},
|
|
225
|
-
content: Buffer.from(limit.toString())
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
tag: 'item_limit',
|
|
229
|
-
attrs: {},
|
|
230
|
-
content: Buffer.from(limit.toString())
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
tag: 'width',
|
|
234
|
-
attrs: {},
|
|
235
|
-
content: Buffer.from('100')
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
tag: 'height',
|
|
239
|
-
attrs: {},
|
|
240
|
-
content: Buffer.from('100')
|
|
241
|
-
}
|
|
242
|
-
]
|
|
243
|
-
}
|
|
244
|
-
]
|
|
245
|
-
});
|
|
246
|
-
return parseCollectionsNode(result);
|
|
247
|
-
};
|
|
248
|
-
const getOrderDetails = async (orderId, tokenBase64) => {
|
|
249
|
-
const result = await query({
|
|
250
|
-
tag: 'iq',
|
|
251
|
-
attrs: {
|
|
252
|
-
to: S_WHATSAPP_NET,
|
|
253
|
-
type: 'get',
|
|
254
|
-
xmlns: 'fb:thrift_iq',
|
|
255
|
-
smax_id: '5'
|
|
256
|
-
},
|
|
257
|
-
content: [
|
|
258
|
-
{
|
|
259
|
-
tag: 'order',
|
|
260
|
-
attrs: {
|
|
261
|
-
op: 'get',
|
|
262
|
-
id: orderId
|
|
263
|
-
},
|
|
264
|
-
content: [
|
|
265
|
-
{
|
|
266
|
-
tag: 'image_dimensions',
|
|
267
|
-
attrs: {},
|
|
268
|
-
content: [
|
|
269
|
-
{
|
|
270
|
-
tag: 'width',
|
|
271
|
-
attrs: {},
|
|
272
|
-
content: Buffer.from('100')
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
tag: 'height',
|
|
276
|
-
attrs: {},
|
|
277
|
-
content: Buffer.from('100')
|
|
278
|
-
}
|
|
279
|
-
]
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
tag: 'token',
|
|
283
|
-
attrs: {},
|
|
284
|
-
content: Buffer.from(tokenBase64)
|
|
285
|
-
}
|
|
286
|
-
]
|
|
287
|
-
}
|
|
288
|
-
]
|
|
289
|
-
});
|
|
290
|
-
return parseOrderDetailsNode(result);
|
|
291
|
-
};
|
|
292
|
-
const productUpdate = async (productId, update) => {
|
|
293
|
-
update = await uploadingNecessaryImagesOfProduct(update, waUploadToServer);
|
|
294
|
-
const editNode = toProductNode(productId, update);
|
|
295
|
-
const result = await query({
|
|
296
|
-
tag: 'iq',
|
|
297
|
-
attrs: {
|
|
298
|
-
to: S_WHATSAPP_NET,
|
|
299
|
-
type: 'set',
|
|
300
|
-
xmlns: 'w:biz:catalog'
|
|
301
|
-
},
|
|
302
|
-
content: [
|
|
303
|
-
{
|
|
304
|
-
tag: 'product_catalog_edit',
|
|
305
|
-
attrs: { v: '1' },
|
|
306
|
-
content: [
|
|
307
|
-
editNode,
|
|
308
|
-
{
|
|
309
|
-
tag: 'width',
|
|
310
|
-
attrs: {},
|
|
311
|
-
content: '100'
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
tag: 'height',
|
|
315
|
-
attrs: {},
|
|
316
|
-
content: '100'
|
|
317
|
-
}
|
|
318
|
-
]
|
|
319
|
-
}
|
|
320
|
-
]
|
|
321
|
-
});
|
|
322
|
-
const productCatalogEditNode = getBinaryNodeChild(result, 'product_catalog_edit');
|
|
323
|
-
const productNode = getBinaryNodeChild(productCatalogEditNode, 'product');
|
|
324
|
-
return parseProductNode(productNode);
|
|
325
|
-
};
|
|
326
|
-
const productCreate = async (create) => {
|
|
327
|
-
// ensure isHidden is defined
|
|
328
|
-
create.isHidden = !!create.isHidden;
|
|
329
|
-
create = await uploadingNecessaryImagesOfProduct(create, waUploadToServer);
|
|
330
|
-
const createNode = toProductNode(undefined, create);
|
|
331
|
-
const result = await query({
|
|
332
|
-
tag: 'iq',
|
|
333
|
-
attrs: {
|
|
334
|
-
to: S_WHATSAPP_NET,
|
|
335
|
-
type: 'set',
|
|
336
|
-
xmlns: 'w:biz:catalog'
|
|
337
|
-
},
|
|
338
|
-
content: [
|
|
339
|
-
{
|
|
340
|
-
tag: 'product_catalog_add',
|
|
341
|
-
attrs: { v: '1' },
|
|
342
|
-
content: [
|
|
343
|
-
createNode,
|
|
344
|
-
{
|
|
345
|
-
tag: 'width',
|
|
346
|
-
attrs: {},
|
|
347
|
-
content: '100'
|
|
348
|
-
},
|
|
349
|
-
{
|
|
350
|
-
tag: 'height',
|
|
351
|
-
attrs: {},
|
|
352
|
-
content: '100'
|
|
353
|
-
}
|
|
354
|
-
]
|
|
355
|
-
}
|
|
356
|
-
]
|
|
357
|
-
});
|
|
358
|
-
const productCatalogAddNode = getBinaryNodeChild(result, 'product_catalog_add');
|
|
359
|
-
const productNode = getBinaryNodeChild(productCatalogAddNode, 'product');
|
|
360
|
-
return parseProductNode(productNode);
|
|
361
|
-
};
|
|
362
|
-
const productDelete = async (productIds) => {
|
|
363
|
-
const result = await query({
|
|
364
|
-
tag: 'iq',
|
|
365
|
-
attrs: {
|
|
366
|
-
to: S_WHATSAPP_NET,
|
|
367
|
-
type: 'set',
|
|
368
|
-
xmlns: 'w:biz:catalog'
|
|
369
|
-
},
|
|
370
|
-
content: [
|
|
371
|
-
{
|
|
372
|
-
tag: 'product_catalog_delete',
|
|
373
|
-
attrs: { v: '1' },
|
|
374
|
-
content: productIds.map(id => ({
|
|
375
|
-
tag: 'product',
|
|
376
|
-
attrs: {},
|
|
377
|
-
content: [
|
|
378
|
-
{
|
|
379
|
-
tag: 'id',
|
|
380
|
-
attrs: {},
|
|
381
|
-
content: Buffer.from(id)
|
|
382
|
-
}
|
|
383
|
-
]
|
|
384
|
-
}))
|
|
385
|
-
}
|
|
386
|
-
]
|
|
387
|
-
});
|
|
388
|
-
const productCatalogDelNode = getBinaryNodeChild(result, 'product_catalog_delete');
|
|
389
|
-
return {
|
|
390
|
-
deleted: +(productCatalogDelNode?.attrs.deleted_count || 0)
|
|
391
|
-
};
|
|
392
|
-
};
|
|
393
|
-
return {
|
|
394
|
-
...sock,
|
|
395
|
-
logger: config.logger,
|
|
396
|
-
getOrderDetails,
|
|
397
|
-
getCatalog,
|
|
398
|
-
getCollections,
|
|
399
|
-
productCreate,
|
|
400
|
-
productDelete,
|
|
401
|
-
productUpdate,
|
|
402
|
-
updateBussinesProfile: updateBusinessProfile,
|
|
403
|
-
updateBusinessProfile,
|
|
404
|
-
updateCoverPhoto,
|
|
405
|
-
removeCoverPhoto
|
|
406
|
-
};
|
|
407
|
-
};
|