@gara31/void-baileys 7.0.0-rc.14
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/WAProto/index.js +117292 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +116 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.js +42 -0
- package/lib/Signal/Group/group_cipher.js +109 -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 +32 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +67 -0
- package/lib/Signal/Group/sender-key-message.js +80 -0
- package/lib/Signal/Group/sender-key-name.js +50 -0
- package/lib/Signal/Group/sender-key-record.js +47 -0
- package/lib/Signal/Group/sender-key-state.js +105 -0
- package/lib/Signal/Group/sender-message-key.js +30 -0
- package/lib/Signal/libsignal.js +416 -0
- package/lib/Signal/lid-mapping.js +189 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +61 -0
- package/lib/Socket/business.js +404 -0
- package/lib/Socket/chats.js +1146 -0
- package/lib/Socket/communities.js +505 -0
- package/lib/Socket/groups.js +404 -0
- package/lib/Socket/index.js +18 -0
- package/lib/Socket/messages-recv.js +1600 -0
- package/lib/Socket/messages-send.js +1203 -0
- package/lib/Socket/mex.js +56 -0
- package/lib/Socket/newsletter.js +240 -0
- package/lib/Socket/socket.js +1060 -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 +32 -0
- package/lib/Utils/auth-utils.js +276 -0
- package/lib/Utils/browser-utils.js +32 -0
- package/lib/Utils/business.js +262 -0
- package/lib/Utils/chat-utils.js +941 -0
- package/lib/Utils/crypto.js +179 -0
- package/lib/Utils/decode-wa-message.js +333 -0
- package/lib/Utils/event-buffer.js +580 -0
- package/lib/Utils/generics.js +436 -0
- package/lib/Utils/history.js +103 -0
- package/lib/Utils/index.js +19 -0
- package/lib/Utils/link-preview.js +99 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/lt-hash.js +56 -0
- package/lib/Utils/make-mutex.js +38 -0
- package/lib/Utils/message-retry-manager.js +181 -0
- package/lib/Utils/messages-media.js +727 -0
- package/lib/Utils/messages.js +1309 -0
- package/lib/Utils/noise-handler.js +162 -0
- package/lib/Utils/pre-key-manager.js +125 -0
- package/lib/Utils/process-message.js +594 -0
- package/lib/Utils/signal.js +194 -0
- package/lib/Utils/use-multi-file-auth-state.js +118 -0
- package/lib/Utils/validate-connection.js +240 -0
- package/lib/WABinary/constants.js +1301 -0
- package/lib/WABinary/decode.js +240 -0
- package/lib/WABinary/encode.js +216 -0
- package/lib/WABinary/generic-utils.js +104 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/constants.js +22863 -0
- package/lib/WAM/encode.js +152 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +29 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +59 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +36 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +60 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/index.js +5 -0
- package/lib/WAUSync/USyncQuery.js +104 -0
- package/lib/WAUSync/USyncUser.js +23 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/index.js +11 -0
- package/package.json +32 -0
- package/readme.md +1452 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { Boom } from "@hapi/boom";
|
|
2
|
+
import { createHash } from "crypto";
|
|
3
|
+
import { createWriteStream, promises as fs } from "fs";
|
|
4
|
+
import { tmpdir } from "os";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
import {
|
|
7
|
+
getBinaryNodeChild,
|
|
8
|
+
getBinaryNodeChildren,
|
|
9
|
+
getBinaryNodeChildString,
|
|
10
|
+
} from "../WABinary/index.js";
|
|
11
|
+
import { generateMessageIDV2 } from "./generics.js";
|
|
12
|
+
import { getStream, getUrlFromDirectPath } from "./messages-media.js";
|
|
13
|
+
export const parseCatalogNode = (node) => {
|
|
14
|
+
const catalogNode = getBinaryNodeChild(node, "product_catalog");
|
|
15
|
+
const products = getBinaryNodeChildren(catalogNode, "product").map(
|
|
16
|
+
parseProductNode,
|
|
17
|
+
);
|
|
18
|
+
const paging = getBinaryNodeChild(catalogNode, "paging");
|
|
19
|
+
return {
|
|
20
|
+
products,
|
|
21
|
+
nextPageCursor: paging
|
|
22
|
+
? getBinaryNodeChildString(paging, "after")
|
|
23
|
+
: undefined,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export const parseCollectionsNode = (node) => {
|
|
27
|
+
const collectionsNode = getBinaryNodeChild(node, "collections");
|
|
28
|
+
const collections = getBinaryNodeChildren(collectionsNode, "collection").map(
|
|
29
|
+
(collectionNode) => {
|
|
30
|
+
const id = getBinaryNodeChildString(collectionNode, "id");
|
|
31
|
+
const name = getBinaryNodeChildString(collectionNode, "name");
|
|
32
|
+
const products = getBinaryNodeChildren(collectionNode, "product").map(
|
|
33
|
+
parseProductNode,
|
|
34
|
+
);
|
|
35
|
+
return {
|
|
36
|
+
id,
|
|
37
|
+
name,
|
|
38
|
+
products,
|
|
39
|
+
status: parseStatusInfo(collectionNode),
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
return {
|
|
44
|
+
collections,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export const parseOrderDetailsNode = (node) => {
|
|
48
|
+
const orderNode = getBinaryNodeChild(node, "order");
|
|
49
|
+
const products = getBinaryNodeChildren(orderNode, "product").map(
|
|
50
|
+
(productNode) => {
|
|
51
|
+
const imageNode = getBinaryNodeChild(productNode, "image");
|
|
52
|
+
return {
|
|
53
|
+
id: getBinaryNodeChildString(productNode, "id"),
|
|
54
|
+
name: getBinaryNodeChildString(productNode, "name"),
|
|
55
|
+
imageUrl: getBinaryNodeChildString(imageNode, "url"),
|
|
56
|
+
price: +getBinaryNodeChildString(productNode, "price"),
|
|
57
|
+
currency: getBinaryNodeChildString(productNode, "currency"),
|
|
58
|
+
quantity: +getBinaryNodeChildString(productNode, "quantity"),
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
);
|
|
62
|
+
const priceNode = getBinaryNodeChild(orderNode, "price");
|
|
63
|
+
const orderDetails = {
|
|
64
|
+
price: {
|
|
65
|
+
total: +getBinaryNodeChildString(priceNode, "total"),
|
|
66
|
+
currency: getBinaryNodeChildString(priceNode, "currency"),
|
|
67
|
+
},
|
|
68
|
+
products,
|
|
69
|
+
};
|
|
70
|
+
return orderDetails;
|
|
71
|
+
};
|
|
72
|
+
export const toProductNode = (productId, product) => {
|
|
73
|
+
const attrs = {};
|
|
74
|
+
const content = [];
|
|
75
|
+
if (typeof productId !== "undefined") {
|
|
76
|
+
content.push({
|
|
77
|
+
tag: "id",
|
|
78
|
+
attrs: {},
|
|
79
|
+
content: Buffer.from(productId),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (typeof product.name !== "undefined") {
|
|
83
|
+
content.push({
|
|
84
|
+
tag: "name",
|
|
85
|
+
attrs: {},
|
|
86
|
+
content: Buffer.from(product.name),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (typeof product.description !== "undefined") {
|
|
90
|
+
content.push({
|
|
91
|
+
tag: "description",
|
|
92
|
+
attrs: {},
|
|
93
|
+
content: Buffer.from(product.description),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (typeof product.retailerId !== "undefined") {
|
|
97
|
+
content.push({
|
|
98
|
+
tag: "retailer_id",
|
|
99
|
+
attrs: {},
|
|
100
|
+
content: Buffer.from(product.retailerId),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (product.images.length) {
|
|
104
|
+
content.push({
|
|
105
|
+
tag: "media",
|
|
106
|
+
attrs: {},
|
|
107
|
+
content: product.images.map((img) => {
|
|
108
|
+
if (!("url" in img)) {
|
|
109
|
+
throw new Boom("Expected img for product to already be uploaded", {
|
|
110
|
+
statusCode: 400,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
tag: "image",
|
|
115
|
+
attrs: {},
|
|
116
|
+
content: [
|
|
117
|
+
{
|
|
118
|
+
tag: "url",
|
|
119
|
+
attrs: {},
|
|
120
|
+
content: Buffer.from(img.url.toString()),
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
}),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
if (typeof product.price !== "undefined") {
|
|
128
|
+
content.push({
|
|
129
|
+
tag: "price",
|
|
130
|
+
attrs: {},
|
|
131
|
+
content: Buffer.from(product.price.toString()),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (typeof product.currency !== "undefined") {
|
|
135
|
+
content.push({
|
|
136
|
+
tag: "currency",
|
|
137
|
+
attrs: {},
|
|
138
|
+
content: Buffer.from(product.currency),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if ("originCountryCode" in product) {
|
|
142
|
+
if (typeof product.originCountryCode === "undefined") {
|
|
143
|
+
attrs["compliance_category"] = "COUNTRY_ORIGIN_EXEMPT";
|
|
144
|
+
} else {
|
|
145
|
+
content.push({
|
|
146
|
+
tag: "compliance_info",
|
|
147
|
+
attrs: {},
|
|
148
|
+
content: [
|
|
149
|
+
{
|
|
150
|
+
tag: "country_code_origin",
|
|
151
|
+
attrs: {},
|
|
152
|
+
content: Buffer.from(product.originCountryCode),
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (typeof product.isHidden !== "undefined") {
|
|
159
|
+
attrs["is_hidden"] = product.isHidden.toString();
|
|
160
|
+
}
|
|
161
|
+
const node = {
|
|
162
|
+
tag: "product",
|
|
163
|
+
attrs,
|
|
164
|
+
content,
|
|
165
|
+
};
|
|
166
|
+
return node;
|
|
167
|
+
};
|
|
168
|
+
export const parseProductNode = (productNode) => {
|
|
169
|
+
const isHidden = productNode.attrs.is_hidden === "true";
|
|
170
|
+
const id = getBinaryNodeChildString(productNode, "id");
|
|
171
|
+
const mediaNode = getBinaryNodeChild(productNode, "media");
|
|
172
|
+
const statusInfoNode = getBinaryNodeChild(productNode, "status_info");
|
|
173
|
+
const product = {
|
|
174
|
+
id,
|
|
175
|
+
imageUrls: parseImageUrls(mediaNode),
|
|
176
|
+
reviewStatus: {
|
|
177
|
+
whatsapp: getBinaryNodeChildString(statusInfoNode, "status"),
|
|
178
|
+
},
|
|
179
|
+
availability: "in stock",
|
|
180
|
+
name: getBinaryNodeChildString(productNode, "name"),
|
|
181
|
+
retailerId: getBinaryNodeChildString(productNode, "retailer_id"),
|
|
182
|
+
url: getBinaryNodeChildString(productNode, "url"),
|
|
183
|
+
description: getBinaryNodeChildString(productNode, "description"),
|
|
184
|
+
price: +getBinaryNodeChildString(productNode, "price"),
|
|
185
|
+
currency: getBinaryNodeChildString(productNode, "currency"),
|
|
186
|
+
isHidden,
|
|
187
|
+
};
|
|
188
|
+
return product;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Uploads images not already uploaded to WA's servers
|
|
192
|
+
*/
|
|
193
|
+
export async function uploadingNecessaryImagesOfProduct(
|
|
194
|
+
product,
|
|
195
|
+
waUploadToServer,
|
|
196
|
+
timeoutMs = 30000,
|
|
197
|
+
) {
|
|
198
|
+
product = {
|
|
199
|
+
...product,
|
|
200
|
+
images: product.images
|
|
201
|
+
? await uploadingNecessaryImages(
|
|
202
|
+
product.images,
|
|
203
|
+
waUploadToServer,
|
|
204
|
+
timeoutMs,
|
|
205
|
+
)
|
|
206
|
+
: product.images,
|
|
207
|
+
};
|
|
208
|
+
return product;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Uploads images not already uploaded to WA's servers
|
|
212
|
+
*/
|
|
213
|
+
export const uploadingNecessaryImages = async (
|
|
214
|
+
images,
|
|
215
|
+
waUploadToServer,
|
|
216
|
+
timeoutMs = 30000,
|
|
217
|
+
) => {
|
|
218
|
+
const results = await Promise.all(
|
|
219
|
+
images.map(async (img) => {
|
|
220
|
+
if ("url" in img) {
|
|
221
|
+
const url = img.url.toString();
|
|
222
|
+
if (url.includes(".whatsapp.net")) {
|
|
223
|
+
return { url };
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const { stream } = await getStream(img);
|
|
227
|
+
const hasher = createHash("sha256");
|
|
228
|
+
const filePath = join(tmpdir(), "img" + generateMessageIDV2());
|
|
229
|
+
const encFileWriteStream = createWriteStream(filePath);
|
|
230
|
+
for await (const block of stream) {
|
|
231
|
+
hasher.update(block);
|
|
232
|
+
encFileWriteStream.write(block);
|
|
233
|
+
}
|
|
234
|
+
const sha = hasher.digest("base64");
|
|
235
|
+
const { directPath } = await waUploadToServer(filePath, {
|
|
236
|
+
mediaType: "product-catalog-image",
|
|
237
|
+
fileEncSha256B64: sha,
|
|
238
|
+
timeoutMs,
|
|
239
|
+
});
|
|
240
|
+
await fs
|
|
241
|
+
.unlink(filePath)
|
|
242
|
+
.catch((err) => console.log("Error deleting temp file ", err));
|
|
243
|
+
return { url: getUrlFromDirectPath(directPath) };
|
|
244
|
+
}),
|
|
245
|
+
);
|
|
246
|
+
return results;
|
|
247
|
+
};
|
|
248
|
+
const parseImageUrls = (mediaNode) => {
|
|
249
|
+
const imgNode = getBinaryNodeChild(mediaNode, "image");
|
|
250
|
+
return {
|
|
251
|
+
requested: getBinaryNodeChildString(imgNode, "request_image_url"),
|
|
252
|
+
original: getBinaryNodeChildString(imgNode, "original_image_url"),
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
const parseStatusInfo = (mediaNode) => {
|
|
256
|
+
const node = getBinaryNodeChild(mediaNode, "status_info");
|
|
257
|
+
return {
|
|
258
|
+
status: getBinaryNodeChildString(node, "status"),
|
|
259
|
+
canAppeal: getBinaryNodeChildString(node, "can_appeal") === "true",
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
//# sourceMappingURL=business.js.map
|