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