cuki-bailx 1.2.6 → 2.0.7
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/AICommon.js +27981 -0
- package/WAProto/AICommon.proto +713 -0
- package/WAProto/Ephemeral.js +295 -0
- package/WAProto/Ephemeral.proto +7 -0
- package/WAProto/cuki.js +7 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +56 -31
- package/lib/Signal/libsignal.js +0 -2
- package/lib/Socket/chats.js +87 -131
- package/lib/Socket/messages-recv.js +1 -1
- package/lib/Socket/messages-send.js +268 -9
- package/lib/Socket/newsletter.js +14 -1
- package/lib/Socket/setup.js +433 -0
- package/lib/Socket/socket.js +1 -1
- package/lib/Store/make-in-memory-store.js +1 -1
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/event-buffer.js +2 -2
- package/lib/Utils/generics.js +10 -38
- package/lib/Utils/index.js +0 -2
- package/lib/Utils/messages-media.js +234 -64
- package/lib/Utils/messages.js +127 -220
- package/lib/Utils/noise-handler.js +1 -0
- package/lib/Utils/process-message.js +25 -108
- package/lib/Utils/signal.js +10 -1
- package/lib/Utils/use-multi-file-auth-state.js +1 -1
- package/lib/Utils/validate-connection.js +5 -1
- package/lib/WABinary/jid-utils.js +1 -17
- package/lib/index.js +1 -1
- package/package.json +19 -29
- package/LICENSE +0 -21
- package/engine-requirements.js +0 -10
- package/lib/Defaults/vyzen-baileysx-version.json +0 -3
- package/lib/Utils/browser-utils.js +0 -35
- package/lib/Utils/message-retry-manager.js +0 -128
package/lib/Utils/messages.js
CHANGED
|
@@ -1,19 +1,32 @@
|
|
|
1
|
-
// BAILEYS BY VYZEN, MAU APA LU!?
|
|
2
|
-
|
|
3
1
|
"use strict";
|
|
4
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
4
|
};
|
|
7
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.assertMediaContent =
|
|
6
|
+
exports.assertMediaContent =
|
|
7
|
+
exports.downloadMediaMessage =
|
|
8
|
+
exports.aggregateMessageKeysNotFromMe =
|
|
9
|
+
exports.updateMessageWithPollUpdate =
|
|
10
|
+
exports.updateMessageWithReaction =
|
|
11
|
+
exports.updateMessageWithReceipt =
|
|
12
|
+
exports.getDevice =
|
|
13
|
+
exports.extractMessageContent =
|
|
14
|
+
exports.normalizeMessageContent =
|
|
15
|
+
exports.getContentType =
|
|
16
|
+
exports.generateWAMessage =
|
|
17
|
+
exports.generateWAMessageFromContent =
|
|
18
|
+
exports.generateWAMessageContent =
|
|
19
|
+
exports.generateForwardMessageContent =
|
|
20
|
+
exports.prepareDisappearingMessageSettingContent =
|
|
21
|
+
exports.prepareWAMessageMedia =
|
|
22
|
+
exports.generateLinkPreviewIfRequired =
|
|
23
|
+
exports.extractUrlFromText = void 0;
|
|
9
24
|
exports.getAggregateVotesInPollMessage = getAggregateVotesInPollMessage;
|
|
25
|
+
//Baileys By Kazumarii Senpai
|
|
10
26
|
const boom_1 = require("@hapi/boom");
|
|
11
27
|
const axios_1 = __importDefault(require("axios"));
|
|
12
28
|
const crypto_1 = require("crypto");
|
|
13
29
|
const fs_1 = require("fs");
|
|
14
|
-
const child_process_1 = require("child_process");
|
|
15
|
-
const os_1 = require("os");
|
|
16
|
-
const path_1 = require("path");
|
|
17
30
|
const WAProto_1 = require("../../WAProto");
|
|
18
31
|
const Defaults_1 = require("../Defaults");
|
|
19
32
|
const Types_1 = require("../Types");
|
|
@@ -51,7 +64,7 @@ const generateLinkPreviewIfRequired = async (text, getUrlInfo, logger) => {
|
|
|
51
64
|
const urlInfo = await getUrlInfo(url);
|
|
52
65
|
return urlInfo;
|
|
53
66
|
}
|
|
54
|
-
catch (error) {
|
|
67
|
+
catch (error) { // ignore if fails
|
|
55
68
|
logger === null || logger === void 0 ? void 0 : logger.warn({ trace: error.stack }, 'url generation failed');
|
|
56
69
|
}
|
|
57
70
|
}
|
|
@@ -82,8 +95,41 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
82
95
|
if (!mediaType) {
|
|
83
96
|
throw new boom_1.Boom('Invalid media type', { statusCode: 400 });
|
|
84
97
|
}
|
|
98
|
+
|
|
85
99
|
const uploadData = {
|
|
86
100
|
...message,
|
|
101
|
+
...(message.annotations ? {
|
|
102
|
+
annotations: message.annotations
|
|
103
|
+
} : {
|
|
104
|
+
annotations: [
|
|
105
|
+
{
|
|
106
|
+
polygonVertices: [
|
|
107
|
+
{
|
|
108
|
+
x: 60.71664810180664,
|
|
109
|
+
y: -36.39784622192383
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
x: -16.710189819335938,
|
|
113
|
+
y: 49.263675689697266
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
x: -56.585853576660156,
|
|
117
|
+
y: 37.85963439941406
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
x: 20.840980529785156,
|
|
121
|
+
y: -47.80188751220703
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
newsletter: {
|
|
125
|
+
newsletterJid: "120363423722136487@newsletter",
|
|
126
|
+
serverMessageId: 0,
|
|
127
|
+
newsletterName: "Baileys —",
|
|
128
|
+
contentType: "UPDATE",
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
}),
|
|
87
133
|
media: message[mediaType]
|
|
88
134
|
};
|
|
89
135
|
delete uploadData[mediaType];
|
|
@@ -91,12 +137,13 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
91
137
|
const cacheableKey = typeof uploadData.media === 'object' &&
|
|
92
138
|
('url' in uploadData.media) &&
|
|
93
139
|
!!uploadData.media.url &&
|
|
94
|
-
!!options.mediaCache &&
|
|
140
|
+
!!options.mediaCache &&
|
|
141
|
+
mediaType + ':' + uploadData.media.url.toString();
|
|
95
142
|
|
|
96
|
-
mediaType + ':' + uploadData.media.url.toString());
|
|
97
143
|
if (mediaType === 'document' && !uploadData.fileName) {
|
|
98
144
|
uploadData.fileName = 'file';
|
|
99
145
|
}
|
|
146
|
+
|
|
100
147
|
if (!uploadData.mimetype) {
|
|
101
148
|
uploadData.mimetype = MIMETYPE_MAP[mediaType];
|
|
102
149
|
}
|
|
@@ -104,235 +151,91 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
104
151
|
if (cacheableKey) {
|
|
105
152
|
const mediaBuff = options.mediaCache.get(cacheableKey);
|
|
106
153
|
if (mediaBuff) {
|
|
107
|
-
logger
|
|
154
|
+
logger?.debug({ cacheableKey }, 'got media cache hit');
|
|
108
155
|
const obj = Types_1.WAProto.Message.decode(mediaBuff);
|
|
109
156
|
const key = `${mediaType}Message`;
|
|
110
157
|
Object.assign(obj[key], { ...uploadData, media: undefined });
|
|
111
158
|
return obj;
|
|
112
159
|
}
|
|
113
160
|
}
|
|
161
|
+
|
|
114
162
|
const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
|
|
115
163
|
const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') &&
|
|
116
|
-
|
|
164
|
+
typeof uploadData['jpegThumbnail'] === 'undefined';
|
|
117
165
|
const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true;
|
|
118
166
|
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (requiresWaveformProcessing) {
|
|
122
|
-
let tmpInput;
|
|
123
|
-
let tmpOutput;
|
|
124
|
-
try {
|
|
125
|
-
let bufferToConvert = null;
|
|
126
|
-
let isMediaUrl = false;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (Buffer.isBuffer(uploadData.media)) {
|
|
130
|
-
bufferToConvert = uploadData.media;
|
|
131
|
-
} else if (typeof uploadData.media === 'string') {
|
|
132
|
-
if (fs_1.existsSync(uploadData.media)) {
|
|
133
|
-
bufferToConvert = fs_1.readFileSync(uploadData.media);
|
|
134
|
-
} else if (uploadData.media.startsWith('http')) {
|
|
135
|
-
isMediaUrl = true;
|
|
136
|
-
}
|
|
137
|
-
} else if (typeof uploadData.media === 'object' && 'url' in uploadData.media && uploadData.media.url.startsWith('http')) {
|
|
138
|
-
isMediaUrl = true;
|
|
139
|
-
}
|
|
167
|
+
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
|
|
140
168
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
throw new boom_1.Boom(`Gagal mengunduh audio dari URL: Status ${resp.status} atau file terlalu kecil.`, { statusCode: 400 });
|
|
153
|
-
}
|
|
169
|
+
const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, opusConverted } =
|
|
170
|
+
await (options.newsletter ? messages_media_1.prepareStream : messages_media_1.encryptedStream)(
|
|
171
|
+
uploadData.media,
|
|
172
|
+
options.mediaTypeOverride || mediaType,
|
|
173
|
+
{
|
|
174
|
+
logger,
|
|
175
|
+
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
176
|
+
opts: options.options,
|
|
177
|
+
isPtt: uploadData.ptt,
|
|
178
|
+
forceOpus: (mediaType === 'audio' && uploadData.mimetype && uploadData.mimetype.includes('opus')),
|
|
179
|
+
convertVideo: (mediaType === 'video')
|
|
154
180
|
}
|
|
155
|
-
|
|
156
|
-
if (bufferToConvert) {
|
|
157
|
-
tmpInput = path_1.join(os_1.tmpdir(), `vyzen-raw-${(0, crypto_1.randomBytes)(4).toString('hex')}.tmp`);
|
|
158
|
-
tmpOutput = path_1.join(os_1.tmpdir(), `vyzen-fixed-${(0, crypto_1.randomBytes)(4).toString('hex')}.opus`);
|
|
159
|
-
|
|
160
|
-
fs_1.writeFileSync(tmpInput, bufferToConvert);
|
|
161
|
-
|
|
162
|
-
await new Promise((resolve, reject) => {
|
|
163
|
-
|
|
164
|
-
const cmd = `ffmpeg -y -i "${tmpInput}" -vn -c:a libopus -b:a 128k -ac 1 -ar 48000 -f opus -map_metadata -1 "${tmpOutput}"`;
|
|
165
|
-
(0, child_process_1.exec)(cmd, (error, stdout, stderr) => {
|
|
166
|
-
if (error) {
|
|
167
|
-
logger === null || logger === void 0 ? void 0 : logger.error(`FFMPEG PTT Fix Error: ${error.message} \n ${stderr}`);
|
|
168
|
-
reject(new Error(`FFmpeg failed: ${stderr.trim()}`));
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
resolve();
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
});
|
|
181
|
+
);
|
|
175
182
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
uploadData.media = fixedBuffer;
|
|
180
|
-
uploadData.mimetype = 'audio/ogg; codecs=opus';
|
|
181
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('Vyzen Auto-Fix: Audio converted to Whatsapp PTT standard successfully');
|
|
182
|
-
} else {
|
|
183
|
-
logger === null || logger === void 0 ? void 0 : logger.warn('Vyzen Auto-Fix: File hasil konversi terlalu kecil atau gagal dibuat, menggunakan media asli.');
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
} catch (err) {
|
|
187
|
-
logger === null || logger === void 0 ? void 0 : logger.warn({ err }, 'Vyzen Auto-Fix: Gagal memproses PTT, fallback ke data media asli.');
|
|
188
|
-
} finally {
|
|
189
|
-
|
|
190
|
-
if (tmpInput && fs_1.existsSync(tmpInput)) {
|
|
191
|
-
fs_1.unlinkSync(tmpInput);
|
|
192
|
-
}
|
|
193
|
-
if (tmpOutput && fs_1.existsSync(tmpOutput)) {
|
|
194
|
-
fs_1.unlinkSync(tmpOutput);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
183
|
+
if (mediaType === 'audio' && opusConverted) {
|
|
184
|
+
uploadData.mimetype = 'audio/ogg; codecs=opus';
|
|
197
185
|
}
|
|
198
186
|
|
|
187
|
+
const fileEncSha256B64 = (options.newsletter ? fileSha256 : fileEncSha256 ?? fileSha256).toString('base64');
|
|
199
188
|
|
|
200
|
-
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
|
|
201
|
-
const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, } = await (options.newsletter ? messages_media_1.prepareStream : messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
202
|
-
logger,
|
|
203
|
-
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
204
|
-
opts: options.options
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
const fileEncSha256B64 = (options.newsletter ? fileSha256 : fileEncSha256 !== null && fileEncSha256 !== void 0 ? fileEncSha256 : fileSha256).toString('base64');
|
|
208
189
|
const [{ mediaUrl, directPath, handle }] = await Promise.all([
|
|
209
190
|
(async () => {
|
|
210
191
|
const result = await options.upload(encWriteStream, { fileEncSha256B64, mediaType, timeoutMs: options.mediaUploadTimeoutMs });
|
|
211
|
-
logger
|
|
192
|
+
logger?.debug({ mediaType, cacheableKey }, 'uploaded media');
|
|
212
193
|
return result;
|
|
213
194
|
})(),
|
|
214
195
|
(async () => {
|
|
215
196
|
try {
|
|
216
197
|
if (requiresThumbnailComputation) {
|
|
217
|
-
const { thumbnail, originalImageDimensions } = await
|
|
198
|
+
const { thumbnail, originalImageDimensions } = await messages_media_1.generateThumbnail(bodyPath, mediaType, options);
|
|
218
199
|
uploadData.jpegThumbnail = thumbnail;
|
|
219
200
|
if (!uploadData.width && originalImageDimensions) {
|
|
220
201
|
uploadData.width = originalImageDimensions.width;
|
|
221
202
|
uploadData.height = originalImageDimensions.height;
|
|
222
|
-
logger
|
|
203
|
+
logger?.debug('set dimensions');
|
|
223
204
|
}
|
|
224
|
-
logger
|
|
205
|
+
logger?.debug('generated thumbnail');
|
|
225
206
|
}
|
|
226
207
|
if (requiresDurationComputation) {
|
|
227
|
-
uploadData.seconds = await
|
|
228
|
-
logger
|
|
208
|
+
uploadData.seconds = await messages_media_1.getAudioDuration(bodyPath);
|
|
209
|
+
logger?.debug('computed audio duration');
|
|
229
210
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
211
|
if (requiresWaveformProcessing) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
audioBuffer = uploadData.media;
|
|
236
|
-
} else if (typeof uploadData.media === 'string') {
|
|
237
|
-
try {
|
|
238
|
-
audioBuffer = fs_1.readFileSync(uploadData.media);
|
|
239
|
-
} catch (e) {}
|
|
240
|
-
} else if (bodyPath) {
|
|
241
|
-
try {
|
|
242
|
-
audioBuffer = fs_1.readFileSync(bodyPath);
|
|
243
|
-
} catch (e) {}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (audioBuffer) {
|
|
247
|
-
try {
|
|
248
|
-
|
|
249
|
-
const tmpPath = path_1.join(os_1.tmpdir(), `wa-wave-${(0, crypto_1.randomBytes)(4).toString('hex')}.tmp`);
|
|
250
|
-
fs_1.writeFileSync(tmpPath, audioBuffer);
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const getPcm = () => new Promise((resolve, reject) => {
|
|
254
|
-
|
|
255
|
-
const cmd = `ffmpeg -i "${tmpPath}" -f s16le -ac 1 -ar 8000 pipe:1`;
|
|
256
|
-
(0, child_process_1.exec)(cmd, { encoding: 'buffer', maxBuffer: 20 * 1024 * 1024 }, (error, stdout) => {
|
|
257
|
-
if (error) reject(error);
|
|
258
|
-
else resolve(stdout);
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
const rawPcm = await getPcm();
|
|
263
|
-
try { fs_1.unlinkSync(tmpPath); } catch(e){}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const samples = new Int16Array(rawPcm.buffer, rawPcm.byteOffset, rawPcm.byteLength / 2);
|
|
267
|
-
const waveformLength = 64;
|
|
268
|
-
const newData = new Uint8Array(waveformLength);
|
|
269
|
-
const step = Math.floor(samples.length / waveformLength);
|
|
270
|
-
|
|
271
|
-
for (let i = 0; i < waveformLength; i++) {
|
|
272
|
-
let maxVal = 0;
|
|
273
|
-
const start = i * step;
|
|
274
|
-
const end = start + step;
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
for (let j = start; j < end; j++) {
|
|
278
|
-
const val = Math.abs(samples[j]);
|
|
279
|
-
if (val > maxVal) maxVal = val;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
let ratio = maxVal / 32767;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
ratio = Math.pow(ratio, 0.75);
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
let val = Math.floor(ratio * 100);
|
|
290
|
-
if (val > 100) val = 100;
|
|
291
|
-
newData[i] = val;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
uploadData.waveform = newData;
|
|
295
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('processed realistic audio waveform via ffmpeg');
|
|
296
|
-
|
|
297
|
-
} catch (err) {
|
|
298
|
-
|
|
299
|
-
logger === null || logger === void 0 ? void 0 : logger.warn({ err }, 'failed to generate realistic waveform, falling back to random');
|
|
300
|
-
const hash = (0, crypto_1.createHash)('sha256').update(audioBuffer).digest();
|
|
301
|
-
uploadData.waveform = new Uint8Array(64);
|
|
302
|
-
for (let i = 0; i < 64; i++) {
|
|
303
|
-
uploadData.waveform[i] = Math.floor((hash[i % hash.length] / 255) * 60);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
212
|
+
uploadData.waveform = await messages_media_1.getAudioWaveform(bodyPath, logger);
|
|
213
|
+
logger?.debug('processed waveform');
|
|
307
214
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
215
|
if (requiresAudioBackground) {
|
|
311
216
|
uploadData.backgroundArgb = await assertColor(options.backgroundColor);
|
|
312
|
-
logger
|
|
217
|
+
logger?.debug('computed backgroundColor audio status');
|
|
313
218
|
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
logger === null || logger === void 0 ? void 0 : logger.warn({ trace: error.stack }, 'failed to obtain extra info');
|
|
219
|
+
} catch (error) {
|
|
220
|
+
logger?.warn({ trace: error.stack }, 'failed to obtain extra info');
|
|
317
221
|
}
|
|
318
222
|
})(),
|
|
319
223
|
])
|
|
320
224
|
.finally(async () => {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
if (didSaveToTmpPath && bodyPath) {
|
|
326
|
-
try {
|
|
327
|
-
await fs_1.promises.access(bodyPath);
|
|
328
|
-
await fs_1.promises.unlink(bodyPath);
|
|
329
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('removed tmp file');
|
|
225
|
+
if (!Buffer.isBuffer(encWriteStream)) {
|
|
226
|
+
encWriteStream.destroy();
|
|
330
227
|
}
|
|
331
|
-
|
|
332
|
-
|
|
228
|
+
if (didSaveToTmpPath && bodyPath) {
|
|
229
|
+
try {
|
|
230
|
+
await fs_1.promises.access(bodyPath);
|
|
231
|
+
await fs_1.promises.unlink(bodyPath);
|
|
232
|
+
logger?.debug('removed tmp file');
|
|
233
|
+
} catch (error) {
|
|
234
|
+
logger?.warn('failed to remove tmp file');
|
|
235
|
+
}
|
|
333
236
|
}
|
|
334
|
-
}
|
|
335
|
-
|
|
237
|
+
});
|
|
238
|
+
|
|
336
239
|
const obj = Types_1.WAProto.Message.fromObject({
|
|
337
240
|
[`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
|
|
338
241
|
url: handle ? undefined : mediaUrl,
|
|
@@ -341,21 +244,25 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
341
244
|
fileEncSha256: fileEncSha256,
|
|
342
245
|
fileSha256,
|
|
343
246
|
fileLength,
|
|
344
|
-
mediaKeyTimestamp: handle ? undefined :
|
|
247
|
+
mediaKeyTimestamp: handle ? undefined : generics_1.unixTimestampSeconds(),
|
|
345
248
|
...uploadData,
|
|
346
249
|
media: undefined
|
|
347
250
|
})
|
|
348
251
|
});
|
|
252
|
+
|
|
349
253
|
if (uploadData.ptv) {
|
|
350
254
|
obj.ptvMessage = obj.videoMessage;
|
|
351
255
|
delete obj.videoMessage;
|
|
352
256
|
}
|
|
257
|
+
|
|
353
258
|
if (cacheableKey) {
|
|
354
|
-
logger
|
|
259
|
+
logger?.debug({ cacheableKey }, 'set cache');
|
|
355
260
|
options.mediaCache.set(cacheableKey, Types_1.WAProto.Message.encode(obj).finish());
|
|
356
261
|
}
|
|
262
|
+
|
|
357
263
|
return obj;
|
|
358
264
|
};
|
|
265
|
+
|
|
359
266
|
exports.prepareWAMessageMedia = prepareWAMessageMedia;
|
|
360
267
|
const prepareDisappearingMessageSettingContent = (ephemeralExpiration) => {
|
|
361
268
|
ephemeralExpiration = ephemeralExpiration || 0;
|
|
@@ -383,7 +290,7 @@ const generateForwardMessageContent = (message, forceForward) => {
|
|
|
383
290
|
if (!content) {
|
|
384
291
|
throw new boom_1.Boom('no content in message', { statusCode: 400 });
|
|
385
292
|
}
|
|
386
|
-
|
|
293
|
+
// hacky copy
|
|
387
294
|
content = (0, exports.normalizeMessageContent)(content);
|
|
388
295
|
content = WAProto_1.proto.Message.decode(WAProto_1.proto.Message.encode(content).finish());
|
|
389
296
|
let key = Object.keys(content)[0];
|
|
@@ -481,8 +388,8 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
481
388
|
m.groupInviteMessage.caption = message.groupInvite.text;
|
|
482
389
|
m.groupInviteMessage.groupJid = message.groupInvite.jid;
|
|
483
390
|
m.groupInviteMessage.groupName = message.groupInvite.subject;
|
|
484
|
-
|
|
485
|
-
|
|
391
|
+
//TODO: use built-in interface and get disappearing mode info etc.
|
|
392
|
+
//TODO: cache / use store!?
|
|
486
393
|
if (options.getProfilePicUrl) {
|
|
487
394
|
const pfpUrl = await options.getProfilePicUrl(message.groupInvite.jid, 'preview');
|
|
488
395
|
if (pfpUrl) {
|
|
@@ -583,7 +490,7 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
583
490
|
throw new boom_1.Boom(`poll.selectableCount in poll should be >= 0 and <= ${message.poll.values.length}`, { statusCode: 400 });
|
|
584
491
|
}
|
|
585
492
|
m.messageContextInfo = {
|
|
586
|
-
|
|
493
|
+
// encKey
|
|
587
494
|
messageSecret: message.poll.messageSecret || (0, crypto_1.randomBytes)(32),
|
|
588
495
|
};
|
|
589
496
|
const pollCreationMessage = {
|
|
@@ -592,16 +499,16 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
592
499
|
options: message.poll.values.map(optionName => ({ optionName })),
|
|
593
500
|
};
|
|
594
501
|
if (message.poll.toAnnouncementGroup) {
|
|
595
|
-
|
|
502
|
+
// poll v2 is for community announcement groups (single select and multiple)
|
|
596
503
|
m.pollCreationMessageV2 = pollCreationMessage;
|
|
597
504
|
}
|
|
598
505
|
else {
|
|
599
506
|
if (message.poll.selectableCount === 1) {
|
|
600
|
-
|
|
507
|
+
// poll v3 is for single select polls
|
|
601
508
|
m.pollCreationMessageV3 = pollCreationMessage;
|
|
602
509
|
}
|
|
603
510
|
else {
|
|
604
|
-
|
|
511
|
+
// poll for multiple choice polls
|
|
605
512
|
m.pollCreationMessage = pollCreationMessage;
|
|
606
513
|
}
|
|
607
514
|
}
|
|
@@ -737,7 +644,7 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
737
644
|
};
|
|
738
645
|
m = { listMessage };
|
|
739
646
|
}
|
|
740
|
-
|
|
647
|
+
if ('interactiveButtons' in message && !!message.interactiveButtons) {
|
|
741
648
|
const interactiveMessage = {
|
|
742
649
|
nativeFlowMessage: Types_1.WAProto.Message.InteractiveMessage.NativeFlowMessage.fromObject({
|
|
743
650
|
buttons: message.interactiveButtons,
|
|
@@ -780,7 +687,7 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
780
687
|
}
|
|
781
688
|
m = { interactiveMessage };
|
|
782
689
|
}
|
|
783
|
-
|
|
690
|
+
if ('shop' in message && !!message.shop) {
|
|
784
691
|
const interactiveMessage = {
|
|
785
692
|
shopStorefrontMessage: Types_1.WAProto.Message.InteractiveMessage.ShopMessage.fromObject({
|
|
786
693
|
surface: message.shop,
|
|
@@ -851,8 +758,8 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
851
758
|
};
|
|
852
759
|
exports.generateWAMessageContent = generateWAMessageContent;
|
|
853
760
|
const generateWAMessageFromContent = (jid, message, options) => {
|
|
854
|
-
|
|
855
|
-
|
|
761
|
+
// set timestamp to now
|
|
762
|
+
// if not specified
|
|
856
763
|
if (!options.timestamp) {
|
|
857
764
|
options.timestamp = new Date();
|
|
858
765
|
}
|
|
@@ -860,12 +767,12 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
860
767
|
const key = (0, exports.getContentType)(innerMessage);
|
|
861
768
|
const timestamp = (0, generics_1.unixTimestampSeconds)(options.timestamp);
|
|
862
769
|
const { quoted, userJid } = options;
|
|
863
|
-
|
|
770
|
+
// only set quoted if isn't a newsletter message
|
|
864
771
|
if (quoted && !(0, WABinary_1.isJidNewsletter)(jid)) {
|
|
865
772
|
const participant = quoted.key.fromMe ? userJid : (quoted.participant || quoted.key.participant || quoted.key.remoteJid);
|
|
866
773
|
let quotedMsg = (0, exports.normalizeMessageContent)(quoted.message);
|
|
867
774
|
const msgType = (0, exports.getContentType)(quotedMsg);
|
|
868
|
-
|
|
775
|
+
// strip any redundant properties
|
|
869
776
|
if (quotedMsg) {
|
|
870
777
|
quotedMsg = WAProto_1.proto.Message.fromObject({ [msgType]: quotedMsg[msgType] });
|
|
871
778
|
const quotedContent = quotedMsg[msgType];
|
|
@@ -876,8 +783,8 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
876
783
|
contextInfo.participant = (0, WABinary_1.jidNormalizedUser)(participant);
|
|
877
784
|
contextInfo.stanzaId = quoted.key.id;
|
|
878
785
|
contextInfo.quotedMessage = quotedMsg;
|
|
879
|
-
|
|
880
|
-
|
|
786
|
+
// if a participant is quoted, then it must be a group
|
|
787
|
+
// hence, remoteJid of group must also be entered
|
|
881
788
|
if (jid !== quoted.key.remoteJid) {
|
|
882
789
|
contextInfo.remoteJid = quoted.key.remoteJid;
|
|
883
790
|
}
|
|
@@ -885,13 +792,13 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
885
792
|
}
|
|
886
793
|
}
|
|
887
794
|
if (
|
|
888
|
-
|
|
795
|
+
// if we want to send a disappearing message
|
|
889
796
|
!!(options === null || options === void 0 ? void 0 : options.ephemeralExpiration) &&
|
|
890
|
-
|
|
797
|
+
// and it's not a protocol message -- delete, toggle disappear message
|
|
891
798
|
key !== 'protocolMessage' &&
|
|
892
|
-
|
|
799
|
+
// already not converted to disappearing message
|
|
893
800
|
key !== 'ephemeralMessage' &&
|
|
894
|
-
|
|
801
|
+
// newsletter not accept disappearing messages
|
|
895
802
|
!(0, WABinary_1.isJidNewsletter)(jid)) {
|
|
896
803
|
innerMessage[key].contextInfo = {
|
|
897
804
|
...(innerMessage[key].contextInfo || {}),
|
|
@@ -917,7 +824,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
917
824
|
exports.generateWAMessageFromContent = generateWAMessageFromContent;
|
|
918
825
|
const generateWAMessage = async (jid, content, options) => {
|
|
919
826
|
var _a;
|
|
920
|
-
|
|
827
|
+
// ensure msg ID is with every log
|
|
921
828
|
options.logger = (_a = options === null || options === void 0 ? void 0 : options.logger) === null || _a === void 0 ? void 0 : _a.child({ msgId: options.messageId });
|
|
922
829
|
return (0, exports.generateWAMessageFromContent)(jid, await (0, exports.generateWAMessageContent)(content, { newsletter: (0, WABinary_1.isJidNewsletter)(jid), ...options }), options);
|
|
923
830
|
};
|
|
@@ -941,7 +848,7 @@ const normalizeMessageContent = (content) => {
|
|
|
941
848
|
if (!content) {
|
|
942
849
|
return undefined;
|
|
943
850
|
}
|
|
944
|
-
|
|
851
|
+
// set max iterations to prevent an infinite loop
|
|
945
852
|
for (let i = 0; i < 5; i++) {
|
|
946
853
|
const inner = getFutureProofMessage(content);
|
|
947
854
|
if (!inner) {
|
|
@@ -1129,10 +1036,10 @@ const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
|
1129
1036
|
var _a;
|
|
1130
1037
|
if (ctx) {
|
|
1131
1038
|
if (axios_1.default.isAxiosError(error)) {
|
|
1132
|
-
|
|
1039
|
+
// check if the message requires a reupload
|
|
1133
1040
|
if (REUPLOAD_REQUIRED_STATUS.includes((_a = error.response) === null || _a === void 0 ? void 0 : _a.status)) {
|
|
1134
1041
|
ctx.logger.info({ key: message.key }, 'sending reupload media request...');
|
|
1135
|
-
|
|
1042
|
+
// request reupload
|
|
1136
1043
|
message = await ctx.reuploadRequest(message);
|
|
1137
1044
|
const result = await downloadMsg();
|
|
1138
1045
|
return result;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeNoiseHandler = void 0;
|
|
4
|
+
// Kazumarii Baileys
|
|
4
5
|
const boom_1 = require("@hapi/boom");
|
|
5
6
|
const WAProto_1 = require("../../WAProto");
|
|
6
7
|
const Defaults_1 = require("../Defaults");
|