@fanzxnothuman/baileys 2.0.17
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/LICENSE +21 -0
- package/README.md +479 -0
- package/WAProto/index.js +204542 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +158 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Function/Download/tiktok.js +19 -0
- package/lib/Function/Tools/bypass.js +19 -0
- package/lib/Function/index.js +13 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.js +99 -0
- package/lib/Signal/Group/group_cipher.js +131 -0
- package/lib/Signal/Group/index.js +141 -0
- package/lib/Signal/Group/keyhelper.js +78 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/sender-chain-key.js +39 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +76 -0
- package/lib/Signal/Group/sender-key-message.js +86 -0
- package/lib/Signal/Group/sender-key-name.js +53 -0
- package/lib/Signal/Group/sender-key-record.js +71 -0
- package/lib/Signal/Group/sender-key-state.js +123 -0
- package/lib/Signal/Group/sender-message-key.js +33 -0
- package/lib/Signal/libsignal.js +223 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +35 -0
- package/lib/Socket/Client/mobile-socket-client.js +96 -0
- package/lib/Socket/Client/web-socket-client.js +96 -0
- package/lib/Socket/business.js +289 -0
- package/lib/Socket/chats.js +1230 -0
- package/lib/Socket/dugong.js +689 -0
- package/lib/Socket/groups.js +401 -0
- package/lib/Socket/index.js +12 -0
- package/lib/Socket/messages-recv.js +1531 -0
- package/lib/Socket/messages-send.js +1011 -0
- package/lib/Socket/newsletter.js +526 -0
- package/lib/Socket/registration.js +212 -0
- package/lib/Socket/socket.js +842 -0
- package/lib/Socket/usync.js +67 -0
- package/lib/Store/index.js +16 -0
- package/lib/Store/make-cache-manager-store.js +90 -0
- package/lib/Store/make-in-memory-store.js +520 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +10 -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 +27 -0
- package/lib/Types/LabelAssociation.js +12 -0
- package/lib/Types/Message.js +14 -0
- package/lib/Types/Newsletter.js +38 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +67 -0
- package/lib/Utils/auth-utils.js +223 -0
- package/lib/Utils/baileys-event-stream.js +67 -0
- package/lib/Utils/business.js +308 -0
- package/lib/Utils/chat-utils.js +1030 -0
- package/lib/Utils/crypto.js +210 -0
- package/lib/Utils/decode-wa-message.js +225 -0
- package/lib/Utils/event-buffer.js +559 -0
- package/lib/Utils/generics.js +599 -0
- package/lib/Utils/history.js +132 -0
- package/lib/Utils/index.js +49 -0
- package/lib/Utils/link-preview.js +112 -0
- package/lib/Utils/logger.js +11 -0
- package/lib/Utils/lt-hash.js +58 -0
- package/lib/Utils/make-mutex.js +41 -0
- package/lib/Utils/messages-media.js +978 -0
- package/lib/Utils/messages.js +1052 -0
- package/lib/Utils/noise-handler.js +185 -0
- package/lib/Utils/process-message.js +466 -0
- package/lib/Utils/signal.js +199 -0
- package/lib/Utils/use-multi-file-auth-state.js +129 -0
- package/lib/Utils/validate-connection.js +285 -0
- package/lib/WABinary/constants.js +1307 -0
- package/lib/WABinary/decode.js +287 -0
- package/lib/WABinary/encode.js +286 -0
- package/lib/WABinary/generic-utils.js +227 -0
- package/lib/WABinary/index.js +37 -0
- package/lib/WABinary/jid-utils.js +92 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +15260 -0
- package/lib/WAM/encode.js +153 -0
- package/lib/WAM/index.js +35 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +78 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +35 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +76 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +36 -0
- package/lib/WAUSync/USyncQuery.js +105 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.js +35 -0
- package/lib/index.js +65 -0
- package/package.json +109 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uploadingNecessaryImages =
|
|
4
|
+
exports.uploadingNecessaryImagesOfProduct =
|
|
5
|
+
exports.parseProductNode =
|
|
6
|
+
exports.toProductNode =
|
|
7
|
+
exports.parseOrderDetailsNode =
|
|
8
|
+
exports.parseCollectionsNode =
|
|
9
|
+
exports.parseCatalogNode =
|
|
10
|
+
void 0;
|
|
11
|
+
const boom_1 = require("@hapi/boom");
|
|
12
|
+
const crypto_1 = require("crypto");
|
|
13
|
+
const WABinary_1 = require("../WABinary");
|
|
14
|
+
const messages_media_1 = require("./messages-media");
|
|
15
|
+
const parseCatalogNode = (node) => {
|
|
16
|
+
const catalogNode = (0, WABinary_1.getBinaryNodeChild)(
|
|
17
|
+
node,
|
|
18
|
+
"product_catalog",
|
|
19
|
+
);
|
|
20
|
+
const products = (0, WABinary_1.getBinaryNodeChildren)(
|
|
21
|
+
catalogNode,
|
|
22
|
+
"product",
|
|
23
|
+
).map(exports.parseProductNode);
|
|
24
|
+
const paging = (0, WABinary_1.getBinaryNodeChild)(catalogNode, "paging");
|
|
25
|
+
return {
|
|
26
|
+
products,
|
|
27
|
+
nextPageCursor: paging
|
|
28
|
+
? (0, WABinary_1.getBinaryNodeChildString)(paging, "after")
|
|
29
|
+
: undefined,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
exports.parseCatalogNode = parseCatalogNode;
|
|
33
|
+
const parseCollectionsNode = (node) => {
|
|
34
|
+
const collectionsNode = (0, WABinary_1.getBinaryNodeChild)(
|
|
35
|
+
node,
|
|
36
|
+
"collections",
|
|
37
|
+
);
|
|
38
|
+
const collections = (0, WABinary_1.getBinaryNodeChildren)(
|
|
39
|
+
collectionsNode,
|
|
40
|
+
"collection",
|
|
41
|
+
).map((collectionNode) => {
|
|
42
|
+
const id = (0, WABinary_1.getBinaryNodeChildString)(collectionNode, "id");
|
|
43
|
+
const name = (0, WABinary_1.getBinaryNodeChildString)(
|
|
44
|
+
collectionNode,
|
|
45
|
+
"name",
|
|
46
|
+
);
|
|
47
|
+
const products = (0, WABinary_1.getBinaryNodeChildren)(
|
|
48
|
+
collectionNode,
|
|
49
|
+
"product",
|
|
50
|
+
).map(exports.parseProductNode);
|
|
51
|
+
return {
|
|
52
|
+
id,
|
|
53
|
+
name,
|
|
54
|
+
products,
|
|
55
|
+
status: parseStatusInfo(collectionNode),
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
collections,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
exports.parseCollectionsNode = parseCollectionsNode;
|
|
63
|
+
const parseOrderDetailsNode = (node) => {
|
|
64
|
+
const orderNode = (0, WABinary_1.getBinaryNodeChild)(node, "order");
|
|
65
|
+
const products = (0, WABinary_1.getBinaryNodeChildren)(
|
|
66
|
+
orderNode,
|
|
67
|
+
"product",
|
|
68
|
+
).map((productNode) => {
|
|
69
|
+
const imageNode = (0, WABinary_1.getBinaryNodeChild)(productNode, "image");
|
|
70
|
+
return {
|
|
71
|
+
id: (0, WABinary_1.getBinaryNodeChildString)(productNode, "id"),
|
|
72
|
+
name: (0, WABinary_1.getBinaryNodeChildString)(productNode, "name"),
|
|
73
|
+
imageUrl: (0, WABinary_1.getBinaryNodeChildString)(imageNode, "url"),
|
|
74
|
+
price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, "price"),
|
|
75
|
+
currency: (0, WABinary_1.getBinaryNodeChildString)(
|
|
76
|
+
productNode,
|
|
77
|
+
"currency",
|
|
78
|
+
),
|
|
79
|
+
quantity: +(0, WABinary_1.getBinaryNodeChildString)(
|
|
80
|
+
productNode,
|
|
81
|
+
"quantity",
|
|
82
|
+
),
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
const priceNode = (0, WABinary_1.getBinaryNodeChild)(orderNode, "price");
|
|
86
|
+
const orderDetails = {
|
|
87
|
+
price: {
|
|
88
|
+
total: +(0, WABinary_1.getBinaryNodeChildString)(priceNode, "total"),
|
|
89
|
+
currency: (0, WABinary_1.getBinaryNodeChildString)(priceNode, "currency"),
|
|
90
|
+
},
|
|
91
|
+
products,
|
|
92
|
+
};
|
|
93
|
+
return orderDetails;
|
|
94
|
+
};
|
|
95
|
+
exports.parseOrderDetailsNode = parseOrderDetailsNode;
|
|
96
|
+
const toProductNode = (productId, product) => {
|
|
97
|
+
const attrs = {};
|
|
98
|
+
const content = [];
|
|
99
|
+
if (typeof productId !== "undefined") {
|
|
100
|
+
content.push({
|
|
101
|
+
tag: "id",
|
|
102
|
+
attrs: {},
|
|
103
|
+
content: Buffer.from(productId),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (typeof product.name !== "undefined") {
|
|
107
|
+
content.push({
|
|
108
|
+
tag: "name",
|
|
109
|
+
attrs: {},
|
|
110
|
+
content: Buffer.from(product.name),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (typeof product.description !== "undefined") {
|
|
114
|
+
content.push({
|
|
115
|
+
tag: "description",
|
|
116
|
+
attrs: {},
|
|
117
|
+
content: Buffer.from(product.description),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (typeof product.retailerId !== "undefined") {
|
|
121
|
+
content.push({
|
|
122
|
+
tag: "retailer_id",
|
|
123
|
+
attrs: {},
|
|
124
|
+
content: Buffer.from(product.retailerId),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
if (product.images.length) {
|
|
128
|
+
content.push({
|
|
129
|
+
tag: "media",
|
|
130
|
+
attrs: {},
|
|
131
|
+
content: product.images.map((img) => {
|
|
132
|
+
if (!("url" in img)) {
|
|
133
|
+
throw new boom_1.Boom(
|
|
134
|
+
"Expected img for product to already be uploaded",
|
|
135
|
+
{ statusCode: 400 },
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
tag: "image",
|
|
140
|
+
attrs: {},
|
|
141
|
+
content: [
|
|
142
|
+
{
|
|
143
|
+
tag: "url",
|
|
144
|
+
attrs: {},
|
|
145
|
+
content: Buffer.from(img.url.toString()),
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
};
|
|
149
|
+
}),
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (typeof product.price !== "undefined") {
|
|
153
|
+
content.push({
|
|
154
|
+
tag: "price",
|
|
155
|
+
attrs: {},
|
|
156
|
+
content: Buffer.from(product.price.toString()),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
if (typeof product.currency !== "undefined") {
|
|
160
|
+
content.push({
|
|
161
|
+
tag: "currency",
|
|
162
|
+
attrs: {},
|
|
163
|
+
content: Buffer.from(product.currency),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if ("originCountryCode" in product) {
|
|
167
|
+
if (typeof product.originCountryCode === "undefined") {
|
|
168
|
+
attrs["compliance_category"] = "COUNTRY_ORIGIN_EXEMPT";
|
|
169
|
+
} else {
|
|
170
|
+
content.push({
|
|
171
|
+
tag: "compliance_info",
|
|
172
|
+
attrs: {},
|
|
173
|
+
content: [
|
|
174
|
+
{
|
|
175
|
+
tag: "country_code_origin",
|
|
176
|
+
attrs: {},
|
|
177
|
+
content: Buffer.from(product.originCountryCode),
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (typeof product.isHidden !== "undefined") {
|
|
184
|
+
attrs["is_hidden"] = product.isHidden.toString();
|
|
185
|
+
}
|
|
186
|
+
const node = {
|
|
187
|
+
tag: "product",
|
|
188
|
+
attrs,
|
|
189
|
+
content,
|
|
190
|
+
};
|
|
191
|
+
return node;
|
|
192
|
+
};
|
|
193
|
+
exports.toProductNode = toProductNode;
|
|
194
|
+
const parseProductNode = (productNode) => {
|
|
195
|
+
const isHidden = productNode.attrs.is_hidden === "true";
|
|
196
|
+
const id = (0, WABinary_1.getBinaryNodeChildString)(productNode, "id");
|
|
197
|
+
const mediaNode = (0, WABinary_1.getBinaryNodeChild)(productNode, "media");
|
|
198
|
+
const statusInfoNode = (0, WABinary_1.getBinaryNodeChild)(
|
|
199
|
+
productNode,
|
|
200
|
+
"status_info",
|
|
201
|
+
);
|
|
202
|
+
const product = {
|
|
203
|
+
id,
|
|
204
|
+
imageUrls: parseImageUrls(mediaNode),
|
|
205
|
+
reviewStatus: {
|
|
206
|
+
whatsapp: (0, WABinary_1.getBinaryNodeChildString)(
|
|
207
|
+
statusInfoNode,
|
|
208
|
+
"status",
|
|
209
|
+
),
|
|
210
|
+
},
|
|
211
|
+
availability: "in stock",
|
|
212
|
+
name: (0, WABinary_1.getBinaryNodeChildString)(productNode, "name"),
|
|
213
|
+
retailerId: (0, WABinary_1.getBinaryNodeChildString)(
|
|
214
|
+
productNode,
|
|
215
|
+
"retailer_id",
|
|
216
|
+
),
|
|
217
|
+
url: (0, WABinary_1.getBinaryNodeChildString)(productNode, "url"),
|
|
218
|
+
description: (0, WABinary_1.getBinaryNodeChildString)(
|
|
219
|
+
productNode,
|
|
220
|
+
"description",
|
|
221
|
+
),
|
|
222
|
+
price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, "price"),
|
|
223
|
+
currency: (0, WABinary_1.getBinaryNodeChildString)(productNode, "currency"),
|
|
224
|
+
isHidden,
|
|
225
|
+
};
|
|
226
|
+
return product;
|
|
227
|
+
};
|
|
228
|
+
exports.parseProductNode = parseProductNode;
|
|
229
|
+
/**
|
|
230
|
+
* Uploads images not already uploaded to WA's servers
|
|
231
|
+
*/
|
|
232
|
+
async function uploadingNecessaryImagesOfProduct(
|
|
233
|
+
product,
|
|
234
|
+
waUploadToServer,
|
|
235
|
+
timeoutMs = 30000,
|
|
236
|
+
) {
|
|
237
|
+
product = {
|
|
238
|
+
...product,
|
|
239
|
+
images: product.images
|
|
240
|
+
? await (0, exports.uploadingNecessaryImages)(
|
|
241
|
+
product.images,
|
|
242
|
+
waUploadToServer,
|
|
243
|
+
timeoutMs,
|
|
244
|
+
)
|
|
245
|
+
: product.images,
|
|
246
|
+
};
|
|
247
|
+
return product;
|
|
248
|
+
}
|
|
249
|
+
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
|
250
|
+
/**
|
|
251
|
+
* Uploads images not already uploaded to WA's servers
|
|
252
|
+
*/
|
|
253
|
+
const uploadingNecessaryImages = async (
|
|
254
|
+
images,
|
|
255
|
+
waUploadToServer,
|
|
256
|
+
timeoutMs = 30000,
|
|
257
|
+
) => {
|
|
258
|
+
const results = await Promise.all(
|
|
259
|
+
images.map(async (img) => {
|
|
260
|
+
if ("url" in img) {
|
|
261
|
+
const url = img.url.toString();
|
|
262
|
+
if (url.includes(".whatsapp.net")) {
|
|
263
|
+
return { url };
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const { stream } = await (0, messages_media_1.getStream)(img);
|
|
267
|
+
const hasher = (0, crypto_1.createHash)("sha256");
|
|
268
|
+
const contentBlocks = [];
|
|
269
|
+
for await (const block of stream) {
|
|
270
|
+
hasher.update(block);
|
|
271
|
+
contentBlocks.push(block);
|
|
272
|
+
}
|
|
273
|
+
const sha = hasher.digest("base64");
|
|
274
|
+
const { directPath } = await waUploadToServer(
|
|
275
|
+
(0, messages_media_1.toReadable)(Buffer.concat(contentBlocks)),
|
|
276
|
+
{
|
|
277
|
+
mediaType: "product-catalog-image",
|
|
278
|
+
fileEncSha256B64: sha,
|
|
279
|
+
timeoutMs,
|
|
280
|
+
},
|
|
281
|
+
);
|
|
282
|
+
return { url: (0, messages_media_1.getUrlFromDirectPath)(directPath) };
|
|
283
|
+
}),
|
|
284
|
+
);
|
|
285
|
+
return results;
|
|
286
|
+
};
|
|
287
|
+
exports.uploadingNecessaryImages = uploadingNecessaryImages;
|
|
288
|
+
const parseImageUrls = (mediaNode) => {
|
|
289
|
+
const imgNode = (0, WABinary_1.getBinaryNodeChild)(mediaNode, "image");
|
|
290
|
+
return {
|
|
291
|
+
requested: (0, WABinary_1.getBinaryNodeChildString)(
|
|
292
|
+
imgNode,
|
|
293
|
+
"request_image_url",
|
|
294
|
+
),
|
|
295
|
+
original: (0, WABinary_1.getBinaryNodeChildString)(
|
|
296
|
+
imgNode,
|
|
297
|
+
"original_image_url",
|
|
298
|
+
),
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
const parseStatusInfo = (mediaNode) => {
|
|
302
|
+
const node = (0, WABinary_1.getBinaryNodeChild)(mediaNode, "status_info");
|
|
303
|
+
return {
|
|
304
|
+
status: (0, WABinary_1.getBinaryNodeChildString)(node, "status"),
|
|
305
|
+
canAppeal:
|
|
306
|
+
(0, WABinary_1.getBinaryNodeChildString)(node, "can_appeal") === "true",
|
|
307
|
+
};
|
|
308
|
+
};
|