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