@vinzsocket/baileys 2.8.10 → 2.8.30
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/lib/Defaults/index.js +75 -73
- package/lib/Signal/Group/ciphertext-message.js +9 -9
- package/lib/Signal/Group/group-session-builder.js +21 -21
- package/lib/Signal/Group/group_cipher.js +79 -81
- package/lib/Signal/Group/index.js +2 -2
- package/lib/Signal/Group/keyhelper.js +9 -9
- package/lib/Signal/Group/queue-job.js +43 -46
- package/lib/Signal/Group/sender-chain-key.js +24 -25
- package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
- package/lib/Signal/Group/sender-key-message.js +55 -60
- package/lib/Signal/Group/sender-key-name.js +38 -39
- package/lib/Signal/Group/sender-key-record.js +39 -41
- package/lib/Signal/Group/sender-key-state.js +85 -89
- package/lib/Signal/Group/sender-message-key.js +22 -22
- package/lib/Signal/libsignal.js +387 -292
- package/lib/Signal/lid-mapping.js +98 -93
- package/lib/Socket/Client/types.js +6 -6
- package/lib/Socket/Client/websocket.js +44 -44
- package/lib/Socket/business.js +350 -365
- package/lib/Socket/chats.js +1019 -914
- package/lib/Socket/communities.js +454 -376
- package/lib/Socket/groups.js +378 -310
- package/lib/Socket/index.js +11 -11
- package/lib/Socket/messages-recv.js +1355 -1182
- package/lib/Socket/messages-send.js +1224 -1081
- package/lib/Socket/mex.js +40 -34
- package/lib/Socket/newsletter.js +212 -169
- package/lib/Socket/socket.js +896 -757
- package/lib/Store/index.js +1 -1
- package/lib/Store/make-cache-manager-store.js +75 -79
- package/lib/Store/make-in-memory-store.js +450 -389
- package/lib/Store/make-ordered-dictionary.js +73 -76
- package/lib/Store/object-repository.js +24 -22
- package/lib/Types/Chat.js +1 -7
- package/lib/Types/Label.js +20 -20
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +2 -2
- package/lib/Types/Newsletter.js +24 -24
- package/lib/Types/Socket.js +1 -1
- package/lib/Types/State.js +8 -8
- package/lib/Types/index.js +10 -10
- package/lib/Utils/auth-utils.js +408 -401
- package/lib/Utils/baileys-event-stream.js +44 -35
- package/lib/Utils/business.js +200 -197
- package/lib/Utils/chat-utils.js +775 -708
- package/lib/Utils/crypto.js +97 -85
- package/lib/Utils/decode-wa-message.js +240 -227
- package/lib/Utils/event-buffer.js +547 -518
- package/lib/Utils/extended-messages.js +250 -203
- package/lib/Utils/generics.js +300 -289
- package/lib/Utils/history.js +76 -69
- package/lib/Utils/lid-resolver.js +47 -42
- package/lib/Utils/link-preview.js +75 -65
- package/lib/Utils/logger.js +3 -1
- package/lib/Utils/lt-hash.js +38 -34
- package/lib/Utils/make-mutex.js +32 -34
- package/lib/Utils/mention.js +79 -86
- package/lib/Utils/message-retry-manager.js +148 -136
- package/lib/Utils/messages-media.js +652 -562
- package/lib/Utils/messages.js +753 -707
- package/lib/Utils/noise-handler.js +156 -135
- package/lib/Utils/process-message.js +404 -341
- package/lib/Utils/signal.js +180 -118
- package/lib/Utils/use-multi-file-auth-state.js +87 -91
- package/lib/Utils/validate-connection.js +167 -142
- package/lib/WABinary/constants.js +28 -1293
- package/lib/WABinary/decode.js +220 -218
- package/lib/WABinary/encode.js +199 -201
- package/lib/WABinary/generic-utils.js +80 -77
- package/lib/WABinary/jid-utils.js +41 -35
- package/lib/WAM/BinaryInfo.js +7 -7
- package/lib/WAM/constants.js +1 -15241
- package/lib/WAM/encode.js +124 -131
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
- package/lib/WAUSync/USyncQuery.js +82 -84
- package/lib/WAUSync/USyncUser.js +20 -20
- package/package.json +4 -2
|
@@ -10,18 +10,24 @@ import { makeMutex } from './make-mutex.js';
|
|
|
10
10
|
* @param filename File to save to
|
|
11
11
|
*/
|
|
12
12
|
export const captureEventStream = (ev, filename) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
const oldEmit = ev.emit;
|
|
14
|
+
// write mutex so data is appended in order
|
|
15
|
+
const writeMutex = makeMutex();
|
|
16
|
+
// monkey patch eventemitter to capture all events
|
|
17
|
+
ev.emit = function (...args) {
|
|
18
|
+
const content = JSON.stringify({
|
|
19
|
+
timestamp: Date.now(),
|
|
20
|
+
event: args[0],
|
|
21
|
+
data: args[1]
|
|
22
|
+
}) + '\n';
|
|
23
|
+
const result = oldEmit.apply(ev, args);
|
|
24
|
+
writeMutex.mutex(async () => {
|
|
25
|
+
await writeFile(filename, content, {
|
|
26
|
+
flag: 'a'
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
25
31
|
};
|
|
26
32
|
/**
|
|
27
33
|
* Read event file and emit events from there
|
|
@@ -29,28 +35,31 @@ export const captureEventStream = (ev, filename) => {
|
|
|
29
35
|
* @param delayIntervalMs delay between each event emit
|
|
30
36
|
*/
|
|
31
37
|
export const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
38
|
+
const ev = new EventEmitter();
|
|
39
|
+
const fireEvents = async () => {
|
|
40
|
+
// from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
|
|
41
|
+
const fileStream = createReadStream(filename);
|
|
42
|
+
const rl = createInterface({
|
|
43
|
+
input: fileStream,
|
|
44
|
+
crlfDelay: Infinity
|
|
45
|
+
});
|
|
46
|
+
// Note: we use the crlfDelay option to recognize all instances of CR LF
|
|
47
|
+
// ('\r\n') in input.txt as a single line break.
|
|
48
|
+
for await (const line of rl) {
|
|
49
|
+
if (line) {
|
|
50
|
+
const {
|
|
51
|
+
event,
|
|
52
|
+
data
|
|
53
|
+
} = JSON.parse(line);
|
|
54
|
+
ev.emit(event, data);
|
|
55
|
+
delayIntervalMs && (await delay(delayIntervalMs));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
fileStream.close();
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
ev,
|
|
62
|
+
task: fireEvents()
|
|
63
|
+
};
|
|
55
64
|
};
|
|
56
65
|
//# sourceMappingURL=baileys-event-stream.js.map
|
package/lib/Utils/business.js
CHANGED
|
@@ -6,226 +6,229 @@ import { join } from 'path';
|
|
|
6
6
|
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString } from '../WABinary/index.js';
|
|
7
7
|
import { generateMessageIDV2 } from './generics.js';
|
|
8
8
|
import { getStream, getUrlFromDirectPath } from './messages-media.js';
|
|
9
|
-
export const parseCatalogNode =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
export const parseCatalogNode = node => {
|
|
10
|
+
const catalogNode = getBinaryNodeChild(node, 'product_catalog');
|
|
11
|
+
const products = getBinaryNodeChildren(catalogNode, 'product').map(parseProductNode);
|
|
12
|
+
const paging = getBinaryNodeChild(catalogNode, 'paging');
|
|
13
|
+
return {
|
|
14
|
+
products,
|
|
15
|
+
nextPageCursor: paging ? getBinaryNodeChildString(paging, 'after') : undefined
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export const parseCollectionsNode = node => {
|
|
19
|
+
const collectionsNode = getBinaryNodeChild(node, 'collections');
|
|
20
|
+
const collections = getBinaryNodeChildren(collectionsNode, 'collection').map(collectionNode => {
|
|
21
|
+
const id = getBinaryNodeChildString(collectionNode, 'id');
|
|
22
|
+
const name = getBinaryNodeChildString(collectionNode, 'name');
|
|
23
|
+
const products = getBinaryNodeChildren(collectionNode, 'product').map(parseProductNode);
|
|
13
24
|
return {
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
id,
|
|
26
|
+
name,
|
|
27
|
+
products,
|
|
28
|
+
status: parseStatusInfo(collectionNode)
|
|
16
29
|
};
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
collections
|
|
33
|
+
};
|
|
17
34
|
};
|
|
18
|
-
export const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const name = getBinaryNodeChildString(collectionNode, 'name');
|
|
23
|
-
const products = getBinaryNodeChildren(collectionNode, 'product').map(parseProductNode);
|
|
24
|
-
return {
|
|
25
|
-
id,
|
|
26
|
-
name,
|
|
27
|
-
products,
|
|
28
|
-
status: parseStatusInfo(collectionNode)
|
|
29
|
-
};
|
|
30
|
-
});
|
|
35
|
+
export const parseOrderDetailsNode = node => {
|
|
36
|
+
const orderNode = getBinaryNodeChild(node, 'order');
|
|
37
|
+
const products = getBinaryNodeChildren(orderNode, 'product').map(productNode => {
|
|
38
|
+
const imageNode = getBinaryNodeChild(productNode, 'image');
|
|
31
39
|
return {
|
|
32
|
-
|
|
40
|
+
id: getBinaryNodeChildString(productNode, 'id'),
|
|
41
|
+
name: getBinaryNodeChildString(productNode, 'name'),
|
|
42
|
+
imageUrl: getBinaryNodeChildString(imageNode, 'url'),
|
|
43
|
+
price: +getBinaryNodeChildString(productNode, 'price'),
|
|
44
|
+
currency: getBinaryNodeChildString(productNode, 'currency'),
|
|
45
|
+
quantity: +getBinaryNodeChildString(productNode, 'quantity')
|
|
33
46
|
};
|
|
47
|
+
});
|
|
48
|
+
const priceNode = getBinaryNodeChild(orderNode, 'price');
|
|
49
|
+
const orderDetails = {
|
|
50
|
+
price: {
|
|
51
|
+
total: +getBinaryNodeChildString(priceNode, 'total'),
|
|
52
|
+
currency: getBinaryNodeChildString(priceNode, 'currency')
|
|
53
|
+
},
|
|
54
|
+
products
|
|
55
|
+
};
|
|
56
|
+
return orderDetails;
|
|
34
57
|
};
|
|
35
|
-
export const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
58
|
+
export const toProductNode = (productId, product) => {
|
|
59
|
+
const attrs = {};
|
|
60
|
+
const content = [];
|
|
61
|
+
if (typeof productId !== 'undefined') {
|
|
62
|
+
content.push({
|
|
63
|
+
tag: 'id',
|
|
64
|
+
attrs: {},
|
|
65
|
+
content: Buffer.from(productId)
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (typeof product.name !== 'undefined') {
|
|
69
|
+
content.push({
|
|
70
|
+
tag: 'name',
|
|
71
|
+
attrs: {},
|
|
72
|
+
content: Buffer.from(product.name)
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (typeof product.description !== 'undefined') {
|
|
76
|
+
content.push({
|
|
77
|
+
tag: 'description',
|
|
78
|
+
attrs: {},
|
|
79
|
+
content: Buffer.from(product.description)
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (typeof product.retailerId !== 'undefined') {
|
|
83
|
+
content.push({
|
|
84
|
+
tag: 'retailer_id',
|
|
85
|
+
attrs: {},
|
|
86
|
+
content: Buffer.from(product.retailerId)
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (product.images.length) {
|
|
90
|
+
content.push({
|
|
91
|
+
tag: 'media',
|
|
92
|
+
attrs: {},
|
|
93
|
+
content: product.images.map(img => {
|
|
94
|
+
if (!('url' in img)) {
|
|
95
|
+
throw new Boom('Expected img for product to already be uploaded', {
|
|
96
|
+
statusCode: 400
|
|
97
|
+
});
|
|
98
|
+
}
|
|
39
99
|
return {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
100
|
+
tag: 'image',
|
|
101
|
+
attrs: {},
|
|
102
|
+
content: [{
|
|
103
|
+
tag: 'url',
|
|
104
|
+
attrs: {},
|
|
105
|
+
content: Buffer.from(img.url.toString())
|
|
106
|
+
}]
|
|
46
107
|
};
|
|
108
|
+
})
|
|
47
109
|
});
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
content.push({
|
|
77
|
-
tag: 'description',
|
|
78
|
-
attrs: {},
|
|
79
|
-
content: Buffer.from(product.description)
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
if (typeof product.retailerId !== 'undefined') {
|
|
83
|
-
content.push({
|
|
84
|
-
tag: 'retailer_id',
|
|
85
|
-
attrs: {},
|
|
86
|
-
content: Buffer.from(product.retailerId)
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
if (product.images.length) {
|
|
90
|
-
content.push({
|
|
91
|
-
tag: 'media',
|
|
92
|
-
attrs: {},
|
|
93
|
-
content: product.images.map(img => {
|
|
94
|
-
if (!('url' in img)) {
|
|
95
|
-
throw new Boom('Expected img for product to already be uploaded', { statusCode: 400 });
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
tag: 'image',
|
|
99
|
-
attrs: {},
|
|
100
|
-
content: [
|
|
101
|
-
{
|
|
102
|
-
tag: 'url',
|
|
103
|
-
attrs: {},
|
|
104
|
-
content: Buffer.from(img.url.toString())
|
|
105
|
-
}
|
|
106
|
-
]
|
|
107
|
-
};
|
|
108
|
-
})
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
if (typeof product.price !== 'undefined') {
|
|
112
|
-
content.push({
|
|
113
|
-
tag: 'price',
|
|
114
|
-
attrs: {},
|
|
115
|
-
content: Buffer.from(product.price.toString())
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
if (typeof product.currency !== 'undefined') {
|
|
119
|
-
content.push({
|
|
120
|
-
tag: 'currency',
|
|
121
|
-
attrs: {},
|
|
122
|
-
content: Buffer.from(product.currency)
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
if ('originCountryCode' in product) {
|
|
126
|
-
if (typeof product.originCountryCode === 'undefined') {
|
|
127
|
-
attrs['compliance_category'] = 'COUNTRY_ORIGIN_EXEMPT';
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
content.push({
|
|
131
|
-
tag: 'compliance_info',
|
|
132
|
-
attrs: {},
|
|
133
|
-
content: [
|
|
134
|
-
{
|
|
135
|
-
tag: 'country_code_origin',
|
|
136
|
-
attrs: {},
|
|
137
|
-
content: Buffer.from(product.originCountryCode)
|
|
138
|
-
}
|
|
139
|
-
]
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (typeof product.isHidden !== 'undefined') {
|
|
144
|
-
attrs['is_hidden'] = product.isHidden.toString();
|
|
110
|
+
}
|
|
111
|
+
if (typeof product.price !== 'undefined') {
|
|
112
|
+
content.push({
|
|
113
|
+
tag: 'price',
|
|
114
|
+
attrs: {},
|
|
115
|
+
content: Buffer.from(product.price.toString())
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (typeof product.currency !== 'undefined') {
|
|
119
|
+
content.push({
|
|
120
|
+
tag: 'currency',
|
|
121
|
+
attrs: {},
|
|
122
|
+
content: Buffer.from(product.currency)
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if ('originCountryCode' in product) {
|
|
126
|
+
if (typeof product.originCountryCode === 'undefined') {
|
|
127
|
+
attrs['compliance_category'] = 'COUNTRY_ORIGIN_EXEMPT';
|
|
128
|
+
} else {
|
|
129
|
+
content.push({
|
|
130
|
+
tag: 'compliance_info',
|
|
131
|
+
attrs: {},
|
|
132
|
+
content: [{
|
|
133
|
+
tag: 'country_code_origin',
|
|
134
|
+
attrs: {},
|
|
135
|
+
content: Buffer.from(product.originCountryCode)
|
|
136
|
+
}]
|
|
137
|
+
});
|
|
145
138
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
139
|
+
}
|
|
140
|
+
if (typeof product.isHidden !== 'undefined') {
|
|
141
|
+
attrs['is_hidden'] = product.isHidden.toString();
|
|
142
|
+
}
|
|
143
|
+
const node = {
|
|
144
|
+
tag: 'product',
|
|
145
|
+
attrs,
|
|
146
|
+
content
|
|
147
|
+
};
|
|
148
|
+
return node;
|
|
152
149
|
};
|
|
153
|
-
export const parseProductNode =
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
150
|
+
export const parseProductNode = productNode => {
|
|
151
|
+
const isHidden = productNode.attrs.is_hidden === 'true';
|
|
152
|
+
const id = getBinaryNodeChildString(productNode, 'id');
|
|
153
|
+
const mediaNode = getBinaryNodeChild(productNode, 'media');
|
|
154
|
+
const statusInfoNode = getBinaryNodeChild(productNode, 'status_info');
|
|
155
|
+
const product = {
|
|
156
|
+
id,
|
|
157
|
+
imageUrls: parseImageUrls(mediaNode),
|
|
158
|
+
reviewStatus: {
|
|
159
|
+
whatsapp: getBinaryNodeChildString(statusInfoNode, 'status')
|
|
160
|
+
},
|
|
161
|
+
availability: 'in stock',
|
|
162
|
+
name: getBinaryNodeChildString(productNode, 'name'),
|
|
163
|
+
retailerId: getBinaryNodeChildString(productNode, 'retailer_id'),
|
|
164
|
+
url: getBinaryNodeChildString(productNode, 'url'),
|
|
165
|
+
description: getBinaryNodeChildString(productNode, 'description'),
|
|
166
|
+
price: +getBinaryNodeChildString(productNode, 'price'),
|
|
167
|
+
currency: getBinaryNodeChildString(productNode, 'currency'),
|
|
168
|
+
isHidden
|
|
169
|
+
};
|
|
170
|
+
return product;
|
|
174
171
|
};
|
|
175
172
|
/**
|
|
176
173
|
* Uploads images not already uploaded to WA's servers
|
|
177
174
|
*/
|
|
178
175
|
export async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
};
|
|
185
|
-
return product;
|
|
176
|
+
product = {
|
|
177
|
+
...product,
|
|
178
|
+
images: product.images ? await uploadingNecessaryImages(product.images, waUploadToServer, timeoutMs) : product.images
|
|
179
|
+
};
|
|
180
|
+
return product;
|
|
186
181
|
}
|
|
187
182
|
/**
|
|
188
183
|
* Uploads images not already uploaded to WA's servers
|
|
189
184
|
*/
|
|
190
185
|
export const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
186
|
+
const results = await Promise.all(images.map(async img => {
|
|
187
|
+
if ('url' in img) {
|
|
188
|
+
const url = img.url.toString();
|
|
189
|
+
if (url.includes('.whatsapp.net')) {
|
|
190
|
+
return {
|
|
191
|
+
url
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const {
|
|
196
|
+
stream
|
|
197
|
+
} = await getStream(img);
|
|
198
|
+
const hasher = createHash('sha256');
|
|
199
|
+
const filePath = join(tmpdir(), 'img' + generateMessageIDV2());
|
|
200
|
+
const encFileWriteStream = createWriteStream(filePath);
|
|
201
|
+
for await (const block of stream) {
|
|
202
|
+
hasher.update(block);
|
|
203
|
+
encFileWriteStream.write(block);
|
|
204
|
+
}
|
|
205
|
+
const sha = hasher.digest('base64');
|
|
206
|
+
const {
|
|
207
|
+
directPath
|
|
208
|
+
} = await waUploadToServer(filePath, {
|
|
209
|
+
mediaType: 'product-catalog-image',
|
|
210
|
+
fileEncSha256B64: sha,
|
|
211
|
+
timeoutMs
|
|
212
|
+
});
|
|
213
|
+
await fs.unlink(filePath).catch(err => console.log('Error deleting temp file ', err));
|
|
219
214
|
return {
|
|
220
|
-
|
|
221
|
-
original: getBinaryNodeChildString(imgNode, 'original_image_url')
|
|
215
|
+
url: getUrlFromDirectPath(directPath)
|
|
222
216
|
};
|
|
217
|
+
}));
|
|
218
|
+
return results;
|
|
223
219
|
};
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
220
|
+
const parseImageUrls = mediaNode => {
|
|
221
|
+
const imgNode = getBinaryNodeChild(mediaNode, 'image');
|
|
222
|
+
return {
|
|
223
|
+
requested: getBinaryNodeChildString(imgNode, 'request_image_url'),
|
|
224
|
+
original: getBinaryNodeChildString(imgNode, 'original_image_url')
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
const parseStatusInfo = mediaNode => {
|
|
228
|
+
const node = getBinaryNodeChild(mediaNode, 'status_info');
|
|
229
|
+
return {
|
|
230
|
+
status: getBinaryNodeChildString(node, 'status'),
|
|
231
|
+
canAppeal: getBinaryNodeChildString(node, 'can_appeal') === 'true'
|
|
232
|
+
};
|
|
230
233
|
};
|
|
231
234
|
//# sourceMappingURL=business.js.map
|