@vinzsocket/baileys 2.8.30 → 3.0.0
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/WAProto/fix-imports.js +7 -16
- package/WAProto/index.js +1 -37306
- package/lib/Defaults/index.js +37 -33
- package/lib/Signal/Group/ciphertext-message.js +6 -2
- package/lib/Signal/Group/group-session-builder.js +12 -7
- package/lib/Signal/Group/group_cipher.js +18 -13
- package/lib/Signal/Group/index.js +77 -12
- package/lib/Signal/Group/keyhelper.js +15 -8
- package/lib/Signal/Group/queue-job.js +7 -2
- package/lib/Signal/Group/sender-chain-key.js +11 -6
- package/lib/Signal/Group/sender-key-distribution-message.js +10 -6
- package/lib/Signal/Group/sender-key-message.js +14 -9
- package/lib/Signal/Group/sender-key-name.js +6 -2
- package/lib/Signal/Group/sender-key-record.js +13 -9
- package/lib/Signal/Group/sender-key-state.js +10 -6
- package/lib/Signal/Group/sender-message-key.js +9 -4
- package/lib/Signal/libsignal.js +34 -28
- package/lib/Signal/lid-mapping.js +24 -19
- package/lib/Socket/Client/index.js +25 -3
- package/lib/Socket/Client/types.js +8 -4
- package/lib/Socket/Client/websocket.js +16 -11
- package/lib/Socket/business.js +38 -34
- package/lib/Socket/chats.js +100 -95
- package/lib/Socket/communities.js +55 -49
- package/lib/Socket/groups.js +56 -51
- package/lib/Socket/index.js +9 -6
- package/lib/Socket/messages-recv.js +150 -145
- package/lib/Socket/messages-send.js +109 -104
- package/lib/Socket/mex.js +12 -8
- package/lib/Socket/newsletter.js +27 -23
- package/lib/Socket/socket.js +111 -107
- package/lib/Store/index.js +47 -4
- package/lib/Store/make-cache-manager-store.js +17 -11
- package/lib/Store/make-in-memory-store.js +31 -29
- package/lib/Store/make-ordered-dictionary.js +7 -2
- package/lib/Store/object-repository.js +7 -2
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -2
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.js +5 -2
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.js +1 -2
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.js +6 -3
- package/lib/Types/LabelAssociation.js +6 -3
- package/lib/Types/Message.js +16 -7
- package/lib/Types/Newsletter.js +8 -5
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.js +1 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +7 -4
- package/lib/Types/USync.js +1 -2
- package/lib/Types/index.js +153 -15
- package/lib/Utils/auth-utils.js +32 -25
- package/lib/Utils/baileys-event-stream.js +21 -15
- package/lib/Utils/business.js +71 -61
- package/lib/Utils/chat-utils.js +91 -77
- package/lib/Utils/crypto.js +54 -32
- package/lib/Utils/decode-wa-message.js +46 -39
- package/lib/Utils/event-buffer.js +24 -19
- package/lib/Utils/extended-messages.js +14 -9
- package/lib/Utils/generics.js +100 -64
- package/lib/Utils/history.js +30 -23
- package/lib/Utils/index.js +234 -22
- package/lib/Utils/lid-resolver.js +12 -5
- package/lib/Utils/link-preview.js +11 -7
- package/lib/Utils/logger.js +8 -4
- package/lib/Utils/lt-hash.js +8 -5
- package/lib/Utils/make-mutex.js +8 -3
- package/lib/Utils/mention.js +12 -4
- package/lib/Utils/message-retry-manager.js +10 -6
- package/lib/Utils/messages-media.js +127 -95
- package/lib/Utils/messages.js +122 -98
- package/lib/Utils/noise-handler.js +25 -21
- package/lib/Utils/process-message.js +72 -63
- package/lib/Utils/signal.js +45 -33
- package/lib/Utils/use-multi-file-auth-state.js +24 -20
- package/lib/Utils/validate-connection.js +54 -47
- package/lib/WABinary/constants.js +9 -6
- package/lib/WABinary/decode.js +17 -10
- package/lib/WABinary/encode.js +11 -6
- package/lib/WABinary/generic-utils.js +31 -17
- package/lib/WABinary/index.js +58 -6
- package/lib/WABinary/jid-utils.js +36 -20
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +6 -2
- package/lib/WAM/constants.js +1 -1
- package/lib/WAM/encode.js +16 -12
- package/lib/WAM/index.js +36 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +9 -5
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -6
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +8 -4
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +8 -4
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +9 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +23 -19
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -2
- package/lib/WAUSync/Protocols/index.js +58 -6
- package/lib/WAUSync/USyncQuery.js +21 -17
- package/lib/WAUSync/USyncUser.js +6 -2
- package/lib/WAUSync/index.js +36 -4
- package/lib/index.js +112 -12
- package/package.json +8 -6
package/lib/Utils/messages.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2
|
+
value: true
|
|
3
|
+
});
|
|
4
|
+
exports.generateWAMessageFromContent = exports.generateWAMessageContent = exports.generateWAMessage = exports.generateLinkPreviewIfRequired = exports.generateForwardMessageContent = exports.extractUrlFromText = exports.extractMessageContent = exports.downloadMediaMessage = exports.assertMediaContent = exports.aggregateMessageKeysNotFromMe = void 0;
|
|
5
|
+
exports.getAggregateVotesInPollMessage = getAggregateVotesInPollMessage;
|
|
6
|
+
exports.updateMessageWithReceipt = exports.updateMessageWithReaction = exports.updateMessageWithPollUpdate = exports.prepareWAMessageMedia = exports.prepareDisappearingMessageSettingContent = exports.normalizeMessageContent = exports.getDevice = exports.getContentType = void 0;
|
|
7
|
+
var _boom = require("@hapi/boom");
|
|
8
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
9
|
+
var _crypto = require("crypto");
|
|
10
|
+
var _fs = require("fs");
|
|
11
|
+
require("stream");
|
|
12
|
+
var _index = require("../../WAProto/index.js");
|
|
13
|
+
var _index2 = require("../Defaults/index.js");
|
|
14
|
+
var _index3 = require("../Types/index.js");
|
|
15
|
+
var _index4 = require("../WABinary/index.js");
|
|
16
|
+
var _crypto2 = require("./crypto.js");
|
|
17
|
+
var _generics = require("./generics.js");
|
|
18
|
+
var _messagesMedia = require("./messages-media.js");
|
|
19
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
20
|
const MIMETYPE_MAP = {
|
|
14
21
|
image: 'image/jpeg',
|
|
15
22
|
video: 'video/mp4',
|
|
@@ -19,19 +26,20 @@ const MIMETYPE_MAP = {
|
|
|
19
26
|
'product-catalog-image': 'image/jpeg'
|
|
20
27
|
};
|
|
21
28
|
const MessageTypeProto = {
|
|
22
|
-
image: WAProto.Message.ImageMessage,
|
|
23
|
-
video: WAProto.Message.VideoMessage,
|
|
24
|
-
audio: WAProto.Message.AudioMessage,
|
|
25
|
-
sticker: WAProto.Message.StickerMessage,
|
|
26
|
-
document: WAProto.Message.DocumentMessage
|
|
29
|
+
image: _index3.WAProto.Message.ImageMessage,
|
|
30
|
+
video: _index3.WAProto.Message.VideoMessage,
|
|
31
|
+
audio: _index3.WAProto.Message.AudioMessage,
|
|
32
|
+
sticker: _index3.WAProto.Message.StickerMessage,
|
|
33
|
+
document: _index3.WAProto.Message.DocumentMessage
|
|
27
34
|
};
|
|
28
35
|
/**
|
|
29
36
|
* Uses a regex to test whether the string contains a URL, and returns the URL if it does.
|
|
30
37
|
* @param text eg. hello https://google.com
|
|
31
38
|
* @returns the URL, eg. https://google.com
|
|
32
39
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
const extractUrlFromText = text => text.match(_index2.URL_REGEX)?.[0];
|
|
41
|
+
exports.extractUrlFromText = extractUrlFromText;
|
|
42
|
+
const generateLinkPreviewIfRequired = async (text, getUrlInfo, logger) => {
|
|
35
43
|
const url = extractUrlFromText(text);
|
|
36
44
|
if (!!getUrlInfo && url) {
|
|
37
45
|
try {
|
|
@@ -45,6 +53,7 @@ export const generateLinkPreviewIfRequired = async (text, getUrlInfo, logger) =>
|
|
|
45
53
|
}
|
|
46
54
|
}
|
|
47
55
|
};
|
|
56
|
+
exports.generateLinkPreviewIfRequired = generateLinkPreviewIfRequired;
|
|
48
57
|
const assertColor = async color => {
|
|
49
58
|
let assertedColor;
|
|
50
59
|
if (typeof color === 'number') {
|
|
@@ -58,16 +67,16 @@ const assertColor = async color => {
|
|
|
58
67
|
return assertedColor;
|
|
59
68
|
}
|
|
60
69
|
};
|
|
61
|
-
|
|
70
|
+
const prepareWAMessageMedia = async (message, options) => {
|
|
62
71
|
const logger = options.logger;
|
|
63
72
|
let mediaType;
|
|
64
|
-
for (const key of MEDIA_KEYS) {
|
|
73
|
+
for (const key of _index2.MEDIA_KEYS) {
|
|
65
74
|
if (key in message) {
|
|
66
75
|
mediaType = key;
|
|
67
76
|
}
|
|
68
77
|
}
|
|
69
78
|
if (!mediaType) {
|
|
70
|
-
throw new Boom('Invalid media type', {
|
|
79
|
+
throw new _boom.Boom('Invalid media type', {
|
|
71
80
|
statusCode: 400
|
|
72
81
|
});
|
|
73
82
|
}
|
|
@@ -90,7 +99,7 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
90
99
|
logger?.debug({
|
|
91
100
|
cacheableKey
|
|
92
101
|
}, 'got media cache hit');
|
|
93
|
-
const obj = WAProto.Message.decode(mediaBuff);
|
|
102
|
+
const obj = _index3.WAProto.Message.decode(mediaBuff);
|
|
94
103
|
const key = `${mediaType}Message`;
|
|
95
104
|
Object.assign(obj[key], {
|
|
96
105
|
...uploadData,
|
|
@@ -99,7 +108,7 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
99
108
|
return obj;
|
|
100
109
|
}
|
|
101
110
|
}
|
|
102
|
-
const isNewsletter = !!options.jid && isJidNewsletter(options.jid);
|
|
111
|
+
const isNewsletter = !!options.jid && (0, _index4.isJidNewsletter)(options.jid);
|
|
103
112
|
if (isNewsletter) {
|
|
104
113
|
logger?.info({
|
|
105
114
|
key: cacheableKey
|
|
@@ -108,7 +117,7 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
108
117
|
filePath,
|
|
109
118
|
fileSha256,
|
|
110
119
|
fileLength
|
|
111
|
-
} = await getRawMediaUploadData(uploadData.media, options.mediaTypeOverride || mediaType, logger);
|
|
120
|
+
} = await (0, _messagesMedia.getRawMediaUploadData)(uploadData.media, options.mediaTypeOverride || mediaType, logger);
|
|
112
121
|
const fileSha256B64 = fileSha256.toString('base64');
|
|
113
122
|
const {
|
|
114
123
|
mediaUrl,
|
|
@@ -118,8 +127,8 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
118
127
|
mediaType: mediaType,
|
|
119
128
|
timeoutMs: options.mediaUploadTimeoutMs
|
|
120
129
|
});
|
|
121
|
-
await
|
|
122
|
-
const obj = WAProto.Message.create({
|
|
130
|
+
await _fs.promises.unlink(filePath);
|
|
131
|
+
const obj = _index3.WAProto.Message.create({
|
|
123
132
|
// todo: add more support here
|
|
124
133
|
[`${mediaType}Message`]: MessageTypeProto[mediaType].create({
|
|
125
134
|
url: mediaUrl,
|
|
@@ -138,7 +147,7 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
138
147
|
logger?.debug({
|
|
139
148
|
cacheableKey
|
|
140
149
|
}, 'set cache');
|
|
141
|
-
options.mediaCache.set(cacheableKey, WAProto.Message.encode(obj).finish());
|
|
150
|
+
options.mediaCache.set(cacheableKey, _index3.WAProto.Message.encode(obj).finish());
|
|
142
151
|
}
|
|
143
152
|
return obj;
|
|
144
153
|
}
|
|
@@ -154,7 +163,7 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
154
163
|
fileEncSha256,
|
|
155
164
|
fileSha256,
|
|
156
165
|
fileLength
|
|
157
|
-
} = await encryptedStream(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
166
|
+
} = await (0, _messagesMedia.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
158
167
|
logger,
|
|
159
168
|
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
160
169
|
opts: options.options
|
|
@@ -180,7 +189,7 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
180
189
|
const {
|
|
181
190
|
thumbnail,
|
|
182
191
|
originalImageDimensions
|
|
183
|
-
} = await generateThumbnail(originalFilePath, mediaType, options);
|
|
192
|
+
} = await (0, _messagesMedia.generateThumbnail)(originalFilePath, mediaType, options);
|
|
184
193
|
uploadData.jpegThumbnail = thumbnail;
|
|
185
194
|
if (!uploadData.width && originalImageDimensions) {
|
|
186
195
|
uploadData.width = originalImageDimensions.width;
|
|
@@ -190,11 +199,11 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
190
199
|
logger?.debug('generated thumbnail');
|
|
191
200
|
}
|
|
192
201
|
if (requiresDurationComputation) {
|
|
193
|
-
uploadData.seconds = await getAudioDuration(originalFilePath);
|
|
202
|
+
uploadData.seconds = await (0, _messagesMedia.getAudioDuration)(originalFilePath);
|
|
194
203
|
logger?.debug('computed audio duration');
|
|
195
204
|
}
|
|
196
205
|
if (requiresWaveformProcessing) {
|
|
197
|
-
uploadData.waveform = await getAudioWaveform(originalFilePath, logger);
|
|
206
|
+
uploadData.waveform = await (0, _messagesMedia.getAudioWaveform)(originalFilePath, logger);
|
|
198
207
|
logger?.debug('processed waveform');
|
|
199
208
|
}
|
|
200
209
|
if (requiresAudioBackground) {
|
|
@@ -208,16 +217,16 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
208
217
|
}
|
|
209
218
|
})()]).finally(async () => {
|
|
210
219
|
try {
|
|
211
|
-
await
|
|
220
|
+
await _fs.promises.unlink(encFilePath);
|
|
212
221
|
if (originalFilePath) {
|
|
213
|
-
await
|
|
222
|
+
await _fs.promises.unlink(originalFilePath);
|
|
214
223
|
}
|
|
215
224
|
logger?.debug('removed tmp files');
|
|
216
225
|
} catch (error) {
|
|
217
226
|
logger?.warn('failed to remove tmp file');
|
|
218
227
|
}
|
|
219
228
|
});
|
|
220
|
-
const obj = WAProto.Message.create({
|
|
229
|
+
const obj = _index3.WAProto.Message.create({
|
|
221
230
|
[`${mediaType}Message`]: MessageTypeProto[mediaType].create({
|
|
222
231
|
url: mediaUrl,
|
|
223
232
|
directPath,
|
|
@@ -225,7 +234,7 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
225
234
|
fileEncSha256,
|
|
226
235
|
fileSha256,
|
|
227
236
|
fileLength,
|
|
228
|
-
mediaKeyTimestamp: unixTimestampSeconds(),
|
|
237
|
+
mediaKeyTimestamp: (0, _generics.unixTimestampSeconds)(),
|
|
229
238
|
...uploadData,
|
|
230
239
|
media: undefined
|
|
231
240
|
})
|
|
@@ -238,39 +247,41 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
238
247
|
logger?.debug({
|
|
239
248
|
cacheableKey
|
|
240
249
|
}, 'set cache');
|
|
241
|
-
options.mediaCache.set(cacheableKey, WAProto.Message.encode(obj).finish());
|
|
250
|
+
options.mediaCache.set(cacheableKey, _index3.WAProto.Message.encode(obj).finish());
|
|
242
251
|
}
|
|
243
252
|
return obj;
|
|
244
253
|
};
|
|
245
|
-
|
|
254
|
+
exports.prepareWAMessageMedia = prepareWAMessageMedia;
|
|
255
|
+
const prepareDisappearingMessageSettingContent = ephemeralExpiration => {
|
|
246
256
|
ephemeralExpiration = ephemeralExpiration || 0;
|
|
247
257
|
const content = {
|
|
248
258
|
ephemeralMessage: {
|
|
249
259
|
message: {
|
|
250
260
|
protocolMessage: {
|
|
251
|
-
type: WAProto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
|
|
261
|
+
type: _index3.WAProto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
|
|
252
262
|
ephemeralExpiration
|
|
253
263
|
}
|
|
254
264
|
}
|
|
255
265
|
}
|
|
256
266
|
};
|
|
257
|
-
return WAProto.Message.create(content);
|
|
267
|
+
return _index3.WAProto.Message.create(content);
|
|
258
268
|
};
|
|
259
269
|
/**
|
|
260
270
|
* Generate forwarded message content like WA does
|
|
261
271
|
* @param message the message to forward
|
|
262
272
|
* @param options.forceForward will show the message as forwarded even if it is from you
|
|
263
273
|
*/
|
|
264
|
-
|
|
274
|
+
exports.prepareDisappearingMessageSettingContent = prepareDisappearingMessageSettingContent;
|
|
275
|
+
const generateForwardMessageContent = (message, forceForward) => {
|
|
265
276
|
let content = message.message;
|
|
266
277
|
if (!content) {
|
|
267
|
-
throw new Boom('no content in message', {
|
|
278
|
+
throw new _boom.Boom('no content in message', {
|
|
268
279
|
statusCode: 400
|
|
269
280
|
});
|
|
270
281
|
}
|
|
271
282
|
// hacky copy
|
|
272
283
|
content = normalizeMessageContent(content);
|
|
273
|
-
content = proto.Message.decode(proto.Message.encode(content).finish());
|
|
284
|
+
content = _index.proto.Message.decode(_index.proto.Message.encode(content).finish());
|
|
274
285
|
let key = Object.keys(content)[0];
|
|
275
286
|
let score = content?.[key]?.contextInfo?.forwardingScore || 0;
|
|
276
287
|
score += message.key.fromMe && !forceForward ? 0 : 1;
|
|
@@ -292,7 +303,8 @@ export const generateForwardMessageContent = (message, forceForward) => {
|
|
|
292
303
|
}
|
|
293
304
|
return content;
|
|
294
305
|
};
|
|
295
|
-
|
|
306
|
+
exports.generateForwardMessageContent = generateForwardMessageContent;
|
|
307
|
+
const generateWAMessageContent = async (message, options) => {
|
|
296
308
|
var _a, _b;
|
|
297
309
|
let m = {};
|
|
298
310
|
if ('text' in message) {
|
|
@@ -330,31 +342,31 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
330
342
|
} else if ('contacts' in message) {
|
|
331
343
|
const contactLen = message.contacts.contacts.length;
|
|
332
344
|
if (!contactLen) {
|
|
333
|
-
throw new Boom('require atleast 1 contact', {
|
|
345
|
+
throw new _boom.Boom('require atleast 1 contact', {
|
|
334
346
|
statusCode: 400
|
|
335
347
|
});
|
|
336
348
|
}
|
|
337
349
|
if (contactLen === 1) {
|
|
338
|
-
m.contactMessage = WAProto.Message.ContactMessage.create(message.contacts.contacts[0]);
|
|
350
|
+
m.contactMessage = _index3.WAProto.Message.ContactMessage.create(message.contacts.contacts[0]);
|
|
339
351
|
} else {
|
|
340
|
-
m.contactsArrayMessage = WAProto.Message.ContactsArrayMessage.create(message.contacts);
|
|
352
|
+
m.contactsArrayMessage = _index3.WAProto.Message.ContactsArrayMessage.create(message.contacts);
|
|
341
353
|
}
|
|
342
354
|
} else if ('location' in message) {
|
|
343
|
-
m.locationMessage = WAProto.Message.LocationMessage.create(message.location);
|
|
355
|
+
m.locationMessage = _index3.WAProto.Message.LocationMessage.create(message.location);
|
|
344
356
|
} else if ('react' in message) {
|
|
345
357
|
if (!message.react.senderTimestampMs) {
|
|
346
358
|
message.react.senderTimestampMs = Date.now();
|
|
347
359
|
}
|
|
348
|
-
m.reactionMessage = WAProto.Message.ReactionMessage.create(message.react);
|
|
360
|
+
m.reactionMessage = _index3.WAProto.Message.ReactionMessage.create(message.react);
|
|
349
361
|
} else if ('delete' in message) {
|
|
350
362
|
m.protocolMessage = {
|
|
351
363
|
key: message.delete,
|
|
352
|
-
type: WAProto.Message.ProtocolMessage.Type.REVOKE
|
|
364
|
+
type: _index3.WAProto.Message.ProtocolMessage.Type.REVOKE
|
|
353
365
|
};
|
|
354
366
|
} else if ('forward' in message) {
|
|
355
367
|
m = generateForwardMessageContent(message.forward, message.force);
|
|
356
368
|
} else if ('disappearingMessagesInChat' in message) {
|
|
357
|
-
const exp = typeof message.disappearingMessagesInChat === 'boolean' ? message.disappearingMessagesInChat ? WA_DEFAULT_EPHEMERAL : 0 : message.disappearingMessagesInChat;
|
|
369
|
+
const exp = typeof message.disappearingMessagesInChat === 'boolean' ? message.disappearingMessagesInChat ? _index2.WA_DEFAULT_EPHEMERAL : 0 : message.disappearingMessagesInChat;
|
|
358
370
|
m = prepareDisappearingMessageSettingContent(exp);
|
|
359
371
|
} else if ('groupInvite' in message) {
|
|
360
372
|
m.groupInviteMessage = {};
|
|
@@ -368,7 +380,7 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
368
380
|
if (options.getProfilePicUrl) {
|
|
369
381
|
const pfpUrl = await options.getProfilePicUrl(message.groupInvite.jid, 'preview');
|
|
370
382
|
if (pfpUrl) {
|
|
371
|
-
const resp = await
|
|
383
|
+
const resp = await _axios.default.get(pfpUrl, {
|
|
372
384
|
responseType: 'arraybuffer'
|
|
373
385
|
});
|
|
374
386
|
if (resp.status === 200) {
|
|
@@ -396,7 +408,7 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
396
408
|
m.buttonsResponseMessage = {
|
|
397
409
|
selectedButtonId: message.buttonReply.id,
|
|
398
410
|
selectedDisplayText: message.buttonReply.displayText,
|
|
399
|
-
type: proto.Message.ButtonsResponseMessage.Type.DISPLAY_TEXT
|
|
411
|
+
type: _index.proto.Message.ButtonsResponseMessage.Type.DISPLAY_TEXT
|
|
400
412
|
};
|
|
401
413
|
break;
|
|
402
414
|
}
|
|
@@ -413,7 +425,7 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
413
425
|
} = await prepareWAMessageMedia({
|
|
414
426
|
image: message.product.productImage
|
|
415
427
|
}, options);
|
|
416
|
-
m.productMessage = WAProto.Message.ProductMessage.create({
|
|
428
|
+
m.productMessage = _index3.WAProto.Message.ProductMessage.create({
|
|
417
429
|
...message,
|
|
418
430
|
product: {
|
|
419
431
|
...message.product,
|
|
@@ -431,11 +443,11 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
431
443
|
const token = await options.getCallLink(message.event.call, {
|
|
432
444
|
startTime
|
|
433
445
|
});
|
|
434
|
-
m.eventMessage.joinLink = (message.event.call === 'audio' ? CALL_AUDIO_PREFIX : CALL_VIDEO_PREFIX) + token;
|
|
446
|
+
m.eventMessage.joinLink = (message.event.call === 'audio' ? _index2.CALL_AUDIO_PREFIX : _index2.CALL_VIDEO_PREFIX) + token;
|
|
435
447
|
}
|
|
436
448
|
m.messageContextInfo = {
|
|
437
449
|
// encKey
|
|
438
|
-
messageSecret: message.event.messageSecret || randomBytes(32)
|
|
450
|
+
messageSecret: message.event.messageSecret || (0, _crypto.randomBytes)(32)
|
|
439
451
|
};
|
|
440
452
|
m.eventMessage.name = message.event.name;
|
|
441
453
|
m.eventMessage.description = message.event.description;
|
|
@@ -449,18 +461,18 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
449
461
|
(_a = message.poll).selectableCount || (_a.selectableCount = 0);
|
|
450
462
|
(_b = message.poll).toAnnouncementGroup || (_b.toAnnouncementGroup = false);
|
|
451
463
|
if (!Array.isArray(message.poll.values)) {
|
|
452
|
-
throw new Boom('Invalid poll values', {
|
|
464
|
+
throw new _boom.Boom('Invalid poll values', {
|
|
453
465
|
statusCode: 400
|
|
454
466
|
});
|
|
455
467
|
}
|
|
456
468
|
if (message.poll.selectableCount < 0 || message.poll.selectableCount > message.poll.values.length) {
|
|
457
|
-
throw new Boom(`poll.selectableCount in poll should be >= 0 and <= ${message.poll.values.length}`, {
|
|
469
|
+
throw new _boom.Boom(`poll.selectableCount in poll should be >= 0 and <= ${message.poll.values.length}`, {
|
|
458
470
|
statusCode: 400
|
|
459
471
|
});
|
|
460
472
|
}
|
|
461
473
|
m.messageContextInfo = {
|
|
462
474
|
// encKey
|
|
463
|
-
messageSecret: message.poll.messageSecret || randomBytes(32)
|
|
475
|
+
messageSecret: message.poll.messageSecret || (0, _crypto.randomBytes)(32)
|
|
464
476
|
};
|
|
465
477
|
const pollCreationMessage = {
|
|
466
478
|
name: message.poll.name,
|
|
@@ -483,7 +495,7 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
483
495
|
}
|
|
484
496
|
} else if ('sharePhoneNumber' in message) {
|
|
485
497
|
m.protocolMessage = {
|
|
486
|
-
type: proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER
|
|
498
|
+
type: _index.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER
|
|
487
499
|
};
|
|
488
500
|
} else if ('requestPhoneNumber' in message) {
|
|
489
501
|
m.requestPhoneNumberMessage = {};
|
|
@@ -514,7 +526,7 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
514
526
|
key: message.edit,
|
|
515
527
|
editedMessage: m,
|
|
516
528
|
timestampMs: Date.now(),
|
|
517
|
-
type: WAProto.Message.ProtocolMessage.Type.MESSAGE_EDIT
|
|
529
|
+
type: _index3.WAProto.Message.ProtocolMessage.Type.MESSAGE_EDIT
|
|
518
530
|
}
|
|
519
531
|
};
|
|
520
532
|
}
|
|
@@ -530,9 +542,10 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
530
542
|
key.contextInfo = message.contextInfo;
|
|
531
543
|
}
|
|
532
544
|
}
|
|
533
|
-
return WAProto.Message.create(m);
|
|
545
|
+
return _index3.WAProto.Message.create(m);
|
|
534
546
|
};
|
|
535
|
-
|
|
547
|
+
exports.generateWAMessageContent = generateWAMessageContent;
|
|
548
|
+
const generateWAMessageFromContent = (jid, message, options) => {
|
|
536
549
|
// set timestamp to now
|
|
537
550
|
// if not specified
|
|
538
551
|
if (!options.timestamp) {
|
|
@@ -540,17 +553,17 @@ export const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
540
553
|
}
|
|
541
554
|
const innerMessage = normalizeMessageContent(message);
|
|
542
555
|
const key = getContentType(innerMessage);
|
|
543
|
-
const timestamp = unixTimestampSeconds(options.timestamp);
|
|
556
|
+
const timestamp = (0, _generics.unixTimestampSeconds)(options.timestamp);
|
|
544
557
|
const {
|
|
545
558
|
quoted,
|
|
546
559
|
userJid
|
|
547
560
|
} = options;
|
|
548
|
-
if (quoted && !isJidNewsletter(jid)) {
|
|
561
|
+
if (quoted && !(0, _index4.isJidNewsletter)(jid)) {
|
|
549
562
|
const participant = quoted.key.fromMe ? userJid : quoted.participant || quoted.key.participant || quoted.key.remoteJid;
|
|
550
563
|
let quotedMsg = normalizeMessageContent(quoted.message);
|
|
551
564
|
const msgType = getContentType(quotedMsg);
|
|
552
565
|
// strip any redundant properties
|
|
553
|
-
quotedMsg = proto.Message.create({
|
|
566
|
+
quotedMsg = _index.proto.Message.create({
|
|
554
567
|
[msgType]: quotedMsg[msgType]
|
|
555
568
|
});
|
|
556
569
|
const quotedContent = quotedMsg[msgType];
|
|
@@ -558,7 +571,7 @@ export const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
558
571
|
delete quotedContent.contextInfo;
|
|
559
572
|
}
|
|
560
573
|
const contextInfo = 'contextInfo' in innerMessage[key] && innerMessage[key]?.contextInfo || {};
|
|
561
|
-
contextInfo.participant = jidNormalizedUser(participant);
|
|
574
|
+
contextInfo.participant = (0, _index4.jidNormalizedUser)(participant);
|
|
562
575
|
contextInfo.stanzaId = quoted.key.id;
|
|
563
576
|
contextInfo.quotedMessage = quotedMsg;
|
|
564
577
|
// if a participant is quoted, then it must be a group
|
|
@@ -579,30 +592,31 @@ export const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
579
592
|
// already not converted to disappearing message
|
|
580
593
|
key !== 'ephemeralMessage' &&
|
|
581
594
|
// newsletters don't support ephemeral messages
|
|
582
|
-
!isJidNewsletter(jid)) {
|
|
595
|
+
!(0, _index4.isJidNewsletter)(jid)) {
|
|
583
596
|
/* @ts-ignore */
|
|
584
597
|
innerMessage[key].contextInfo = {
|
|
585
598
|
...(innerMessage[key].contextInfo || {}),
|
|
586
|
-
expiration: options.ephemeralExpiration || WA_DEFAULT_EPHEMERAL
|
|
599
|
+
expiration: options.ephemeralExpiration || _index2.WA_DEFAULT_EPHEMERAL
|
|
587
600
|
//ephemeralSettingTimestamp: options.ephemeralOptions.eph_setting_ts?.toString()
|
|
588
601
|
};
|
|
589
602
|
}
|
|
590
|
-
message = WAProto.Message.create(message);
|
|
603
|
+
message = _index3.WAProto.Message.create(message);
|
|
591
604
|
const messageJSON = {
|
|
592
605
|
key: {
|
|
593
606
|
remoteJid: jid,
|
|
594
607
|
fromMe: true,
|
|
595
|
-
id: options?.messageId || generateMessageIDV2()
|
|
608
|
+
id: options?.messageId || (0, _generics.generateMessageIDV2)()
|
|
596
609
|
},
|
|
597
610
|
message: message,
|
|
598
611
|
messageTimestamp: timestamp,
|
|
599
612
|
messageStubParameters: [],
|
|
600
|
-
participant: isJidGroup(jid) || isJidStatusBroadcast(jid) ? userJid : undefined,
|
|
601
|
-
status: WAMessageStatus.PENDING
|
|
613
|
+
participant: (0, _index4.isJidGroup)(jid) || (0, _index4.isJidStatusBroadcast)(jid) ? userJid : undefined,
|
|
614
|
+
status: _index3.WAMessageStatus.PENDING
|
|
602
615
|
};
|
|
603
|
-
return WAProto.WebMessageInfo.create(messageJSON);
|
|
616
|
+
return _index3.WAProto.WebMessageInfo.create(messageJSON);
|
|
604
617
|
};
|
|
605
|
-
|
|
618
|
+
exports.generateWAMessageFromContent = generateWAMessageFromContent;
|
|
619
|
+
const generateWAMessage = async (jid, content, options) => {
|
|
606
620
|
// ensure msg ID is with every log
|
|
607
621
|
options.logger = options?.logger?.child({
|
|
608
622
|
msgId: options.messageId
|
|
@@ -614,7 +628,8 @@ export const generateWAMessage = async (jid, content, options) => {
|
|
|
614
628
|
}), options);
|
|
615
629
|
};
|
|
616
630
|
/** Get the key to access the true type of content */
|
|
617
|
-
|
|
631
|
+
exports.generateWAMessage = generateWAMessage;
|
|
632
|
+
const getContentType = content => {
|
|
618
633
|
if (content) {
|
|
619
634
|
const keys = Object.keys(content);
|
|
620
635
|
const key = keys.find(k => (k === 'conversation' || k.includes('Message')) && k !== 'senderKeyDistributionMessage');
|
|
@@ -627,7 +642,8 @@ export const getContentType = content => {
|
|
|
627
642
|
* @param content
|
|
628
643
|
* @returns
|
|
629
644
|
*/
|
|
630
|
-
|
|
645
|
+
exports.getContentType = getContentType;
|
|
646
|
+
const normalizeMessageContent = content => {
|
|
631
647
|
if (!content) {
|
|
632
648
|
return undefined;
|
|
633
649
|
}
|
|
@@ -648,7 +664,8 @@ export const normalizeMessageContent = content => {
|
|
|
648
664
|
* Extract the true message content from a message
|
|
649
665
|
* Eg. extracts the inner message from a disappearing message/view once message
|
|
650
666
|
*/
|
|
651
|
-
|
|
667
|
+
exports.normalizeMessageContent = normalizeMessageContent;
|
|
668
|
+
const extractMessageContent = content => {
|
|
652
669
|
const extractFromTemplateMessage = msg => {
|
|
653
670
|
if (msg.imageMessage) {
|
|
654
671
|
return {
|
|
@@ -690,9 +707,11 @@ export const extractMessageContent = content => {
|
|
|
690
707
|
/**
|
|
691
708
|
* Returns the device predicted by message ID
|
|
692
709
|
*/
|
|
693
|
-
|
|
710
|
+
exports.extractMessageContent = extractMessageContent;
|
|
711
|
+
const getDevice = id => /^3A.{18}$/.test(id) ? 'ios' : /^3E.{20}$/.test(id) ? 'web' : /^(.{21}|.{32})$/.test(id) ? 'android' : /^(3F|.{18}$)/.test(id) ? 'desktop' : 'unknown';
|
|
694
712
|
/** Upserts a receipt in the message */
|
|
695
|
-
|
|
713
|
+
exports.getDevice = getDevice;
|
|
714
|
+
const updateMessageWithReceipt = (msg, receipt) => {
|
|
696
715
|
msg.userReceipt = msg.userReceipt || [];
|
|
697
716
|
const recp = msg.userReceipt.find(m => m.userJid === receipt.userJid);
|
|
698
717
|
if (recp) {
|
|
@@ -702,17 +721,19 @@ export const updateMessageWithReceipt = (msg, receipt) => {
|
|
|
702
721
|
}
|
|
703
722
|
};
|
|
704
723
|
/** Update the message with a new reaction */
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
const
|
|
724
|
+
exports.updateMessageWithReceipt = updateMessageWithReceipt;
|
|
725
|
+
const updateMessageWithReaction = (msg, reaction) => {
|
|
726
|
+
const authorID = (0, _generics.getKeyAuthor)(reaction.key);
|
|
727
|
+
const reactions = (msg.reactions || []).filter(r => (0, _generics.getKeyAuthor)(r.key) !== authorID);
|
|
708
728
|
reaction.text = reaction.text || '';
|
|
709
729
|
reactions.push(reaction);
|
|
710
730
|
msg.reactions = reactions;
|
|
711
731
|
};
|
|
712
732
|
/** Update the message with a new poll update */
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
const
|
|
733
|
+
exports.updateMessageWithReaction = updateMessageWithReaction;
|
|
734
|
+
const updateMessageWithPollUpdate = (msg, update) => {
|
|
735
|
+
const authorID = (0, _generics.getKeyAuthor)(update.pollUpdateMessageKey);
|
|
736
|
+
const reactions = (msg.pollUpdates || []).filter(r => (0, _generics.getKeyAuthor)(r.pollUpdateMessageKey) !== authorID);
|
|
716
737
|
if (update.vote?.selectedOptions?.length) {
|
|
717
738
|
reactions.push(update);
|
|
718
739
|
}
|
|
@@ -724,13 +745,14 @@ export const updateMessageWithPollUpdate = (msg, update) => {
|
|
|
724
745
|
* @param meId your jid
|
|
725
746
|
* @returns A list of options & their voters
|
|
726
747
|
*/
|
|
727
|
-
|
|
748
|
+
exports.updateMessageWithPollUpdate = updateMessageWithPollUpdate;
|
|
749
|
+
function getAggregateVotesInPollMessage({
|
|
728
750
|
message,
|
|
729
751
|
pollUpdates
|
|
730
752
|
}, meId) {
|
|
731
753
|
const opts = message?.pollCreationMessage?.options || message?.pollCreationMessageV2?.options || message?.pollCreationMessageV3?.options || [];
|
|
732
754
|
const voteHashMap = opts.reduce((acc, opt) => {
|
|
733
|
-
const hash = sha256(Buffer.from(opt.optionName || '')).toString();
|
|
755
|
+
const hash = (0, _crypto2.sha256)(Buffer.from(opt.optionName || '')).toString();
|
|
734
756
|
acc[hash] = {
|
|
735
757
|
name: opt.optionName || '',
|
|
736
758
|
voters: []
|
|
@@ -754,13 +776,13 @@ export function getAggregateVotesInPollMessage({
|
|
|
754
776
|
};
|
|
755
777
|
data = voteHashMap[hash];
|
|
756
778
|
}
|
|
757
|
-
voteHashMap[hash].voters.push(getKeyAuthor(update.pollUpdateMessageKey, meId));
|
|
779
|
+
voteHashMap[hash].voters.push((0, _generics.getKeyAuthor)(update.pollUpdateMessageKey, meId));
|
|
758
780
|
}
|
|
759
781
|
}
|
|
760
782
|
return Object.values(voteHashMap);
|
|
761
783
|
}
|
|
762
784
|
/** Given a list of message keys, aggregates them by chat & sender. Useful for sending read receipts in bulk */
|
|
763
|
-
|
|
785
|
+
const aggregateMessageKeysNotFromMe = keys => {
|
|
764
786
|
const keyMap = {};
|
|
765
787
|
for (const {
|
|
766
788
|
remoteJid,
|
|
@@ -782,13 +804,14 @@ export const aggregateMessageKeysNotFromMe = keys => {
|
|
|
782
804
|
}
|
|
783
805
|
return Object.values(keyMap);
|
|
784
806
|
};
|
|
807
|
+
exports.aggregateMessageKeysNotFromMe = aggregateMessageKeysNotFromMe;
|
|
785
808
|
const REUPLOAD_REQUIRED_STATUS = [410, 404];
|
|
786
809
|
/**
|
|
787
810
|
* Downloads the given message. Throws an error if it's not a media message
|
|
788
811
|
*/
|
|
789
|
-
|
|
812
|
+
const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
790
813
|
const result = await downloadMsg().catch(async error => {
|
|
791
|
-
if (ctx &&
|
|
814
|
+
if (ctx && _axios.default.isAxiosError(error) &&
|
|
792
815
|
// check if the message requires a reupload
|
|
793
816
|
REUPLOAD_REQUIRED_STATUS.includes(error.response?.status)) {
|
|
794
817
|
ctx.logger.info({
|
|
@@ -805,7 +828,7 @@ export const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
|
805
828
|
async function downloadMsg() {
|
|
806
829
|
const mContent = extractMessageContent(message.message);
|
|
807
830
|
if (!mContent) {
|
|
808
|
-
throw new Boom('No message present', {
|
|
831
|
+
throw new _boom.Boom('No message present', {
|
|
809
832
|
statusCode: 400,
|
|
810
833
|
data: message
|
|
811
834
|
});
|
|
@@ -814,7 +837,7 @@ export const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
|
814
837
|
let mediaType = contentType?.replace('Message', '');
|
|
815
838
|
const media = mContent[contentType];
|
|
816
839
|
if (!media || typeof media !== 'object' || !('url' in media) && !('thumbnailDirectPath' in media)) {
|
|
817
|
-
throw new Boom(`"${contentType}" message is not a media message`);
|
|
840
|
+
throw new _boom.Boom(`"${contentType}" message is not a media message`);
|
|
818
841
|
}
|
|
819
842
|
let download;
|
|
820
843
|
if ('thumbnailDirectPath' in media && !('url' in media)) {
|
|
@@ -826,7 +849,7 @@ export const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
|
826
849
|
} else {
|
|
827
850
|
download = media;
|
|
828
851
|
}
|
|
829
|
-
const stream = await downloadContentFromMessage(download, mediaType, options);
|
|
852
|
+
const stream = await (0, _messagesMedia.downloadContentFromMessage)(download, mediaType, options);
|
|
830
853
|
if (type === 'buffer') {
|
|
831
854
|
const bufferArray = [];
|
|
832
855
|
for await (const chunk of stream) {
|
|
@@ -838,15 +861,16 @@ export const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
|
838
861
|
}
|
|
839
862
|
};
|
|
840
863
|
/** Checks whether the given message is a media message; if it is returns the inner content */
|
|
841
|
-
|
|
864
|
+
exports.downloadMediaMessage = downloadMediaMessage;
|
|
865
|
+
const assertMediaContent = content => {
|
|
842
866
|
content = extractMessageContent(content);
|
|
843
867
|
const mediaContent = content?.documentMessage || content?.imageMessage || content?.videoMessage || content?.audioMessage || content?.stickerMessage;
|
|
844
868
|
if (!mediaContent) {
|
|
845
|
-
throw new Boom('given message is not a media message', {
|
|
869
|
+
throw new _boom.Boom('given message is not a media message', {
|
|
846
870
|
statusCode: 400,
|
|
847
871
|
data: content
|
|
848
872
|
});
|
|
849
873
|
}
|
|
850
874
|
return mediaContent;
|
|
851
875
|
};
|
|
852
|
-
|
|
876
|
+
exports.assertMediaContent = assertMediaContent;
|