n4lyx 3.0.9 → 3.1.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/lib/Socket/business.js +55 -49
- package/package.json +1 -1
package/lib/Socket/business.js
CHANGED
|
@@ -4,6 +4,8 @@ exports.makeBusinessSocket = void 0;
|
|
|
4
4
|
|
|
5
5
|
const crypto_1 = require("crypto");
|
|
6
6
|
const path_1 = require("path");
|
|
7
|
+
const https = require("https");
|
|
8
|
+
const http = require("http");
|
|
7
9
|
const business_1 = require("../Utils/business");
|
|
8
10
|
const Utils_1 = require("../Utils");
|
|
9
11
|
const WABinary_1 = require("../WABinary");
|
|
@@ -205,6 +207,37 @@ const _convertToStickerInternal = async (buffer, opts = {}) => {
|
|
|
205
207
|
};
|
|
206
208
|
};
|
|
207
209
|
|
|
210
|
+
const _fetchBufferFromUrl = (url) => {
|
|
211
|
+
return new Promise((resolve, reject) => {
|
|
212
|
+
const proto = url.startsWith("https") ? https : http;
|
|
213
|
+
proto.get(url, { headers: { "User-Agent": "WhatsApp/2.23.20.0" } }, (res) => {
|
|
214
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
215
|
+
return _fetchBufferFromUrl(res.headers.location).then(resolve).catch(reject);
|
|
216
|
+
}
|
|
217
|
+
if (res.statusCode !== 200) return reject(new Error(`HTTP ${res.statusCode}`));
|
|
218
|
+
const chunks = [];
|
|
219
|
+
res.on("data", (c) => chunks.push(c));
|
|
220
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
221
|
+
res.on("error", reject);
|
|
222
|
+
}).on("error", reject);
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const _toWebpBuffer = async (buffer) => {
|
|
227
|
+
if (sharp) {
|
|
228
|
+
return sharp(buffer)
|
|
229
|
+
.resize(512, 512, { fit: "contain", background: { r: 0, g: 0, b: 0, alpha: 0 } })
|
|
230
|
+
.webp({ quality: 80 })
|
|
231
|
+
.toBuffer();
|
|
232
|
+
}
|
|
233
|
+
if (Jimp) {
|
|
234
|
+
const img = await Jimp.read(buffer);
|
|
235
|
+
img.scaleToFit(512, 512);
|
|
236
|
+
return img.getBufferAsync(Jimp.MIME_PNG);
|
|
237
|
+
}
|
|
238
|
+
return buffer;
|
|
239
|
+
};
|
|
240
|
+
|
|
208
241
|
const makeBusinessSocket = (config) => {
|
|
209
242
|
const sock = (0, messages_recv_1.makeMessagesRecvSocket)(config);
|
|
210
243
|
const { authState, query, waUploadToServer, ev } = sock;
|
|
@@ -764,18 +797,6 @@ const makeBusinessSocket = (config) => {
|
|
|
764
797
|
return results;
|
|
765
798
|
};
|
|
766
799
|
|
|
767
|
-
// ── STICKER FIXES ──────────────────────────────────────────────────────────
|
|
768
|
-
// Fix utama: sticker harus dikirim via generateWAMessageContent + relayMessage
|
|
769
|
-
// agar media key ter-upload dengan benar dan muncul di semua platform termasuk HP
|
|
770
|
-
|
|
771
|
-
const _uploadStickerBuffer = async (buffer) => {
|
|
772
|
-
const inner = await (0, Utils_1.generateWAMessageContent)(
|
|
773
|
-
{ sticker: buffer, mimetype: "image/webp" },
|
|
774
|
-
{ upload: waUploadToServer }
|
|
775
|
-
);
|
|
776
|
-
return inner;
|
|
777
|
-
};
|
|
778
|
-
|
|
779
800
|
const sendStickerWithMetadata = async (jid, sticker, metadata = {}, options = {}) => {
|
|
780
801
|
if (!sticker) throw new Error("sendStickerWithMetadata: sticker wajib");
|
|
781
802
|
const { packName, packPublisher, categories, isAvatar, isAiSticker } = metadata;
|
|
@@ -812,7 +833,18 @@ const makeBusinessSocket = (config) => {
|
|
|
812
833
|
|
|
813
834
|
const sendStickerFromUrl = async (jid, url, options = {}) => {
|
|
814
835
|
if (!url) throw new Error("sendStickerFromUrl: url wajib");
|
|
815
|
-
|
|
836
|
+
const rawBuffer = await _fetchBufferFromUrl(url);
|
|
837
|
+
const webpBuffer = await _toWebpBuffer(rawBuffer);
|
|
838
|
+
const inner = await (0, Utils_1.generateWAMessageContent)(
|
|
839
|
+
{ sticker: webpBuffer, mimetype: "image/webp" },
|
|
840
|
+
{ upload: waUploadToServer }
|
|
841
|
+
);
|
|
842
|
+
if (inner?.stickerMessage) {
|
|
843
|
+
if (options.packName) inner.stickerMessage.stickerPackName = options.packName;
|
|
844
|
+
if (options.packPublisher) inner.stickerMessage.stickerPackPublisher = options.packPublisher;
|
|
845
|
+
}
|
|
846
|
+
const msg = _gen(jid, inner);
|
|
847
|
+
return _relay(jid, msg);
|
|
816
848
|
};
|
|
817
849
|
|
|
818
850
|
const sendStickerFromBuffer = async (jid, buffer, metadata = {}, options = {}) => {
|
|
@@ -844,8 +876,6 @@ const makeBusinessSocket = (config) => {
|
|
|
844
876
|
}, options);
|
|
845
877
|
};
|
|
846
878
|
|
|
847
|
-
// sendStickerPack — kirim sticker pack menggunakan format stickerPackMessage
|
|
848
|
-
// sesuai dengan format native WA untuk sticker pack (muncul di HP dan WA Web)
|
|
849
879
|
const sendStickerPack = async (jid, stickers, packName, packPublisher, options = {}) => {
|
|
850
880
|
if (!Array.isArray(stickers) || !stickers.length) throw new Error("sendStickerPack: stickers kosong");
|
|
851
881
|
if (stickers.length > 30) throw new Error("sendStickerPack: maks 30 sticker");
|
|
@@ -854,7 +884,6 @@ const makeBusinessSocket = (config) => {
|
|
|
854
884
|
const delayBatch = options.delayBatch ?? 500;
|
|
855
885
|
const results = [];
|
|
856
886
|
|
|
857
|
-
// Jika format stickerPackMessage tersedia (mode pack native)
|
|
858
887
|
if (options.nativePackMessage && stickers.length > 0) {
|
|
859
888
|
try {
|
|
860
889
|
const packId = options.stickerPackId || (0, crypto_1.randomBytes)(16).toString("hex");
|
|
@@ -892,7 +921,6 @@ const makeBusinessSocket = (config) => {
|
|
|
892
921
|
}
|
|
893
922
|
}
|
|
894
923
|
|
|
895
|
-
// Fallback: kirim satu per satu dalam batch paralel
|
|
896
924
|
for (let i = 0; i < stickers.length; i += batchSize) {
|
|
897
925
|
const batch = stickers.slice(i, i + batchSize);
|
|
898
926
|
const batchResults = await Promise.all(batch.map(async sticker => {
|
|
@@ -907,20 +935,10 @@ const makeBusinessSocket = (config) => {
|
|
|
907
935
|
return results;
|
|
908
936
|
};
|
|
909
937
|
|
|
910
|
-
// sendStickerPackMessage — kirim native stickerPackMessage dengan data lengkap
|
|
911
|
-
// Gunakan ini untuk kirim pack sticker yang sudah di-upload sebelumnya
|
|
912
938
|
const sendStickerPackMessage = async (jid, cfg = {}, options = {}) => {
|
|
913
939
|
const {
|
|
914
|
-
stickerPackId,
|
|
915
|
-
|
|
916
|
-
publisher,
|
|
917
|
-
fileLength,
|
|
918
|
-
fileSha256,
|
|
919
|
-
fileEncSha256,
|
|
920
|
-
mediaKey,
|
|
921
|
-
directPath,
|
|
922
|
-
mediaKeyTimestamp,
|
|
923
|
-
contextInfo,
|
|
940
|
+
stickerPackId, name, publisher, fileLength, fileSha256,
|
|
941
|
+
fileEncSha256, mediaKey, directPath, mediaKeyTimestamp, contextInfo,
|
|
924
942
|
} = cfg;
|
|
925
943
|
|
|
926
944
|
if (!mediaKey || !directPath || !fileEncSha256) {
|
|
@@ -932,14 +950,9 @@ const makeBusinessSocket = (config) => {
|
|
|
932
950
|
viewOnceMessage: {
|
|
933
951
|
message: {
|
|
934
952
|
stickerPackMessage: {
|
|
935
|
-
stickerPackId: packId,
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
fileLength: fileLength || 0,
|
|
939
|
-
fileSha256: fileSha256 || "",
|
|
940
|
-
fileEncSha256: fileEncSha256,
|
|
941
|
-
mediaKey: mediaKey,
|
|
942
|
-
directPath: directPath,
|
|
953
|
+
stickerPackId: packId, name: name || "", publisher: publisher || "",
|
|
954
|
+
fileLength: fileLength || 0, fileSha256: fileSha256 || "",
|
|
955
|
+
fileEncSha256, mediaKey, directPath,
|
|
943
956
|
mediaKeyTimestamp: mediaKeyTimestamp || Math.floor(Date.now() / 1000),
|
|
944
957
|
contextInfo: contextInfo || {},
|
|
945
958
|
}
|
|
@@ -949,7 +962,6 @@ const makeBusinessSocket = (config) => {
|
|
|
949
962
|
return _relay(jid, msg);
|
|
950
963
|
};
|
|
951
964
|
|
|
952
|
-
// sendStickerPackAlbum — kirim beberapa sticker dengan delay batch
|
|
953
965
|
const sendStickerPackAlbum = async (jid, stickers, packName, packPublisher, options = {}) => {
|
|
954
966
|
if (!Array.isArray(stickers) || !stickers.length) throw new Error("sendStickerPackAlbum: stickers kosong");
|
|
955
967
|
const batchSize = Math.min(options.batchSize || 10, 10);
|
|
@@ -1348,12 +1360,9 @@ const makeBusinessSocket = (config) => {
|
|
|
1348
1360
|
if (!buttons.length) throw new Error("sendProductMessageWithButtons: min 1 button wajib");
|
|
1349
1361
|
|
|
1350
1362
|
let headerContent = null;
|
|
1351
|
-
if (thumbnail) {
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
const inner = await (0, Utils_1.generateWAMessageContent)({ image: thumbnail }, { upload: waUploadToServer });
|
|
1355
|
-
headerContent = { imageMessage: inner.imageMessage };
|
|
1356
|
-
}
|
|
1363
|
+
if (thumbnail && Buffer.isBuffer(thumbnail)) {
|
|
1364
|
+
const inner = await (0, Utils_1.generateWAMessageContent)({ image: thumbnail }, { upload: waUploadToServer });
|
|
1365
|
+
headerContent = { imageMessage: inner.imageMessage };
|
|
1357
1366
|
}
|
|
1358
1367
|
if (header && !headerContent) {
|
|
1359
1368
|
if (header.type === "image") {
|
|
@@ -1372,11 +1381,8 @@ const makeBusinessSocket = (config) => {
|
|
|
1372
1381
|
...(headerContent ? { header: headerContent } : {}),
|
|
1373
1382
|
contextInfo: {
|
|
1374
1383
|
externalAdReply: {
|
|
1375
|
-
title: title || "",
|
|
1376
|
-
|
|
1377
|
-
mediaType: 1,
|
|
1378
|
-
renderLargerThumbnail: true,
|
|
1379
|
-
showAdAttribution: false,
|
|
1384
|
+
title: title || "", body: body || "", mediaType: 1,
|
|
1385
|
+
renderLargerThumbnail: true, showAdAttribution: false,
|
|
1380
1386
|
...(thumbnail?.url ? { thumbnailUrl: thumbnail.url } : {}),
|
|
1381
1387
|
}
|
|
1382
1388
|
},
|