@rexxhayanasi/elaina-baileys 1.1.4 → 1.1.6
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/Signal/Group/keyhelper.js +25 -4
- package/lib/Utils/messages-media.js +7 -1
- package/lib/Utils/messages.js +193 -14
- package/package.json +7 -4
|
@@ -38,18 +38,39 @@ exports.generateSenderKeyId = generateSenderKeyId;
|
|
|
38
38
|
exports.generateSenderSigningKey = generateSenderSigningKey;
|
|
39
39
|
const nodeCrypto = __importStar(require("crypto"));
|
|
40
40
|
const curve_1 = require("libsignal/src/curve");
|
|
41
|
+
|
|
41
42
|
function generateSenderKey() {
|
|
42
|
-
|
|
43
|
+
const key = nodeCrypto.randomBytes(32);
|
|
44
|
+
if (!Buffer.isBuffer(key) || key.length !== 32) {
|
|
45
|
+
throw new Error("Failed to generate valid sender key");
|
|
46
|
+
}
|
|
47
|
+
return key;
|
|
43
48
|
}
|
|
49
|
+
|
|
44
50
|
function generateSenderKeyId() {
|
|
45
|
-
|
|
51
|
+
const id = nodeCrypto.randomInt(2147483647);
|
|
52
|
+
if (typeof id !== 'number') {
|
|
53
|
+
throw new Error("Failed to generate sender key ID");
|
|
54
|
+
}
|
|
55
|
+
return id;
|
|
46
56
|
}
|
|
57
|
+
|
|
47
58
|
function generateSenderSigningKey(key) {
|
|
48
59
|
if (!key) {
|
|
49
60
|
key = (0, curve_1.generateKeyPair)();
|
|
50
61
|
}
|
|
62
|
+
if (!key || !key.pubKey || !key.privKey) {
|
|
63
|
+
throw new Error("Invalid key pair provided");
|
|
64
|
+
}
|
|
65
|
+
const publicBuf = Buffer.from(key.pubKey);
|
|
66
|
+
const privateBuf = Buffer.from(key.privKey);
|
|
67
|
+
|
|
68
|
+
if (publicBuf.length !== 32 || privateBuf.length !== 32) {
|
|
69
|
+
throw new Error("Invalid signing key length");
|
|
70
|
+
}
|
|
71
|
+
|
|
51
72
|
return {
|
|
52
|
-
public:
|
|
53
|
-
private:
|
|
73
|
+
public: publicBuf,
|
|
74
|
+
private: privateBuf
|
|
54
75
|
};
|
|
55
76
|
}
|
|
@@ -83,6 +83,9 @@ const getImageProcessingLibrary = async () => {
|
|
|
83
83
|
throw new boom_1.Boom('No image processing library available');
|
|
84
84
|
};
|
|
85
85
|
const hkdfInfoKey = (type) => {
|
|
86
|
+
if (type === 'ptv') return 'WhatsApp Video Keys';
|
|
87
|
+
if (type === 'sticker-pack') return 'WhatsApp Image Keys';
|
|
88
|
+
|
|
86
89
|
const hkdfInfo = Defaults_1.MEDIA_HKDF_KEY_MAPPING[type];
|
|
87
90
|
return `WhatsApp ${hkdfInfo} Keys`;
|
|
88
91
|
};
|
|
@@ -739,6 +742,9 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
739
742
|
const reqBody = Buffer.isBuffer(stream) ? stream : Buffer.concat(chunks);
|
|
740
743
|
fileEncSha256B64 = (0, exports.encodeBase64EncodedStringForUpload)(fileEncSha256B64);
|
|
741
744
|
let media = Defaults_1.MEDIA_PATH_MAP[mediaType];
|
|
745
|
+
if (mediaType === 'sticker-pack') {
|
|
746
|
+
media = '/mms/image';
|
|
747
|
+
}
|
|
742
748
|
if (newsletter) {
|
|
743
749
|
media = media === null || media === void 0 ? void 0 : media.replace('/mms/', '/newsletter/newsletter-');
|
|
744
750
|
}
|
|
@@ -876,4 +882,4 @@ const MEDIA_RETRY_STATUS_MAP = {
|
|
|
876
882
|
};
|
|
877
883
|
function __importStar(arg0) {
|
|
878
884
|
throw new Error('Function not implemented.');
|
|
879
|
-
}
|
|
885
|
+
}
|
package/lib/Utils/messages.js
CHANGED
|
@@ -2,11 +2,29 @@
|
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
6
|
-
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
6
|
+
const getImageProcessingLibrary = async () => {
|
|
7
|
+
const lib = {};
|
|
8
|
+
try {
|
|
9
|
+
lib.sharp = require('sharp');
|
|
10
|
+
} catch {}
|
|
11
|
+
try {
|
|
12
|
+
lib.jimp = require('jimp');
|
|
13
|
+
} catch {}
|
|
14
|
+
return lib;
|
|
15
|
+
};
|
|
16
|
+
const isWebPBuffer = (buffer) => {
|
|
17
|
+
return buffer.length >= 12 && buffer.toString('ascii', 8, 12) === 'WEBP';
|
|
18
|
+
};
|
|
19
|
+
const isAnimatedWebP = (buffer) => {
|
|
20
|
+
if (!isWebPBuffer(buffer)) return false;
|
|
21
|
+
return buffer.includes(Buffer.from("ANIM"));
|
|
22
|
+
};
|
|
23
|
+
exports.prepareStickerPackMessage = exports.assertMediaContent = exports.downloadMediaMessage = exports.aggregateMessageKeysNotFromMe = exports.updateMessageWithPollUpdate = exports.updateMessageWithReaction = exports.updateMessageWithReceipt = exports.getDevice = exports.extractMessageContent = exports.normalizeMessageContent = exports.getContentType = exports.generateWAMessage = exports.generateWAMessageFromContent = exports.generateWAMessageContent = exports.generateForwardMessageContent = exports.prepareDisappearingMessageSettingContent = exports.prepareWAMessageMedia = exports.generateLinkPreviewIfRequired = exports.extractUrlFromText = void 0;
|
|
7
24
|
exports.getAggregateVotesInPollMessage = getAggregateVotesInPollMessage;
|
|
8
25
|
const boom_1 = require("@hapi/boom");
|
|
9
26
|
const axios_1 = __importDefault(require("axios"));
|
|
27
|
+
const fflate_1 = require("fflate");
|
|
10
28
|
const crypto_1 = require("crypto");
|
|
11
29
|
const fs_1 = require("fs");
|
|
12
30
|
const WAProto_1 = require("../../WAProto");
|
|
@@ -23,6 +41,7 @@ const MIMETYPE_MAP = {
|
|
|
23
41
|
audio: 'audio/ogg; codecs=opus',
|
|
24
42
|
sticker: 'image/webp',
|
|
25
43
|
'product-catalog-image': 'image/jpeg',
|
|
44
|
+
'sticker-pack': 'application/x-zip-compressed'
|
|
26
45
|
};
|
|
27
46
|
const MessageTypeProto = {
|
|
28
47
|
'image': Types_1.WAProto.Message.ImageMessage,
|
|
@@ -378,8 +397,11 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
378
397
|
break;
|
|
379
398
|
}
|
|
380
399
|
}
|
|
381
|
-
|
|
382
|
-
const { videoMessage } = await (0, exports.prepareWAMessageMedia)({
|
|
400
|
+
else if ('ptv' in message && message.ptv) {
|
|
401
|
+
const { videoMessage } = await (0, exports.prepareWAMessageMedia)({
|
|
402
|
+
video: message.ptv,
|
|
403
|
+
ptv: true
|
|
404
|
+
}, options);
|
|
383
405
|
m.ptvMessage = videoMessage;
|
|
384
406
|
}
|
|
385
407
|
else if ('product' in message) {
|
|
@@ -1029,16 +1051,6 @@ const assertMediaContent = (content) => {
|
|
|
1029
1051
|
};
|
|
1030
1052
|
exports.assertMediaContent = assertMediaContent;
|
|
1031
1053
|
|
|
1032
|
-
const toJid = (id) => {
|
|
1033
|
-
if (!id)
|
|
1034
|
-
return '';
|
|
1035
|
-
if (id.endsWith('@lid'))
|
|
1036
|
-
return id.replace('@lid', '@s.whatsapp.net');
|
|
1037
|
-
if (id.includes('@'))
|
|
1038
|
-
return id;
|
|
1039
|
-
return `${id}@s.whatsapp.net`;
|
|
1040
|
-
};
|
|
1041
|
-
exports.toJid = toJid;
|
|
1042
1054
|
const getSenderLid = (message) => {
|
|
1043
1055
|
const sender = message.key.participant || message.key.remoteJid;
|
|
1044
1056
|
const user = (0, WABinary_1.jidDecode)(sender)?.user || '';
|
|
@@ -1047,3 +1059,170 @@ const getSenderLid = (message) => {
|
|
|
1047
1059
|
return { jid: sender, lid };
|
|
1048
1060
|
};
|
|
1049
1061
|
exports.getSenderLid = getSenderLid;
|
|
1062
|
+
|
|
1063
|
+
/**
|
|
1064
|
+
STICKER PACK FUNCTION RECODE BY
|
|
1065
|
+
@RexxHayanasi < Maintainer @rexxhayanasi/elaina-baileys >
|
|
1066
|
+
**/
|
|
1067
|
+
|
|
1068
|
+
const prepareStickerPackMessage = async (stickerPack, options) => {
|
|
1069
|
+
const { stickers, name, publisher, packId, description } = stickerPack;
|
|
1070
|
+
|
|
1071
|
+
if (stickers.length > 60) {
|
|
1072
|
+
throw new boom_1.Boom('Sticker pack exceeds the maximum limit of 60 stickers', { statusCode: 400 });
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
if (stickers.length === 0) {
|
|
1076
|
+
throw new boom_1.Boom('Sticker pack must contain at least one sticker', { statusCode: 400 });
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
const stickerPackIdValue = packId || (0, generics_1.generateMessageIDV2)();
|
|
1080
|
+
const lib = await getImageProcessingLibrary();
|
|
1081
|
+
const stickerData = {};
|
|
1082
|
+
|
|
1083
|
+
const stickerPromises = stickers.map(async (s, i) => {
|
|
1084
|
+
const { stream } = await (0, messages_media_1.getStream)(s.data);
|
|
1085
|
+
const buffer = await (0, generics_1.toBuffer)(stream);
|
|
1086
|
+
|
|
1087
|
+
let webpBuffer;
|
|
1088
|
+
let isAnimated = false;
|
|
1089
|
+
const isWebP = isWebPBuffer(buffer);
|
|
1090
|
+
|
|
1091
|
+
if (isWebP) {
|
|
1092
|
+
webpBuffer = buffer;
|
|
1093
|
+
isAnimated = isAnimatedWebP(buffer);
|
|
1094
|
+
} else if (lib.sharp) {
|
|
1095
|
+
webpBuffer = await lib.sharp(buffer).webp().toBuffer();
|
|
1096
|
+
isAnimated = false;
|
|
1097
|
+
} else {
|
|
1098
|
+
throw new boom_1.Boom(
|
|
1099
|
+
'No image processing library (sharp) available for converting sticker to WebP. Either install sharp or provide stickers in WebP format.'
|
|
1100
|
+
);
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
if (webpBuffer.length > 1024 * 1024) {
|
|
1104
|
+
throw new boom_1.Boom(`Sticker at index ${i} exceeds the 1MB size limit`, { statusCode: 400 });
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
const hash = (0, crypto_2.sha256)(webpBuffer).toString('base64').replace(/\//g, '-');
|
|
1108
|
+
const fileName = `${hash}.webp`;
|
|
1109
|
+
|
|
1110
|
+
stickerData[fileName] = [new Uint8Array(webpBuffer), { level: 0 }];
|
|
1111
|
+
|
|
1112
|
+
return {
|
|
1113
|
+
fileName,
|
|
1114
|
+
mimetype: 'image/webp',
|
|
1115
|
+
isAnimated,
|
|
1116
|
+
emojis: s.emojis || [],
|
|
1117
|
+
accessibilityLabel: s.accessibilityLabel
|
|
1118
|
+
};
|
|
1119
|
+
});
|
|
1120
|
+
|
|
1121
|
+
const stickerMetadata = await Promise.all(stickerPromises);
|
|
1122
|
+
|
|
1123
|
+
const trayIconFileName = `${stickerPackIdValue}.webp`;
|
|
1124
|
+
const { stream: coverStream } = await (0, messages_media_1.getStream)(stickerPack.cover);
|
|
1125
|
+
const coverBuffer = await (0, generics_1.toBuffer)(coverStream);
|
|
1126
|
+
|
|
1127
|
+
let coverWebpBuffer;
|
|
1128
|
+
const isCoverWebP = isWebPBuffer(coverBuffer);
|
|
1129
|
+
|
|
1130
|
+
if (isCoverWebP) {
|
|
1131
|
+
coverWebpBuffer = coverBuffer;
|
|
1132
|
+
} else if (lib.sharp) {
|
|
1133
|
+
coverWebpBuffer = await lib.sharp(coverBuffer).webp().toBuffer();
|
|
1134
|
+
} else {
|
|
1135
|
+
throw new boom_1.Boom(
|
|
1136
|
+
'No image processing library (sharp) available for converting cover to WebP. Either install sharp or provide cover in WebP format.'
|
|
1137
|
+
);
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
stickerData[trayIconFileName] = [new Uint8Array(coverWebpBuffer), { level: 0 }];
|
|
1141
|
+
|
|
1142
|
+
const zipBuffer = await new Promise((resolve, reject) => {
|
|
1143
|
+
(0, fflate_1.zip)(stickerData, (err, data) => {
|
|
1144
|
+
if (err) {
|
|
1145
|
+
reject(err);
|
|
1146
|
+
} else {
|
|
1147
|
+
resolve(Buffer.from(data));
|
|
1148
|
+
}
|
|
1149
|
+
});
|
|
1150
|
+
});
|
|
1151
|
+
|
|
1152
|
+
const stickerPackSize = zipBuffer.length;
|
|
1153
|
+
|
|
1154
|
+
const stickerPackUpload = await (0, messages_media_1.encryptedStream)(zipBuffer, 'sticker-pack', {
|
|
1155
|
+
logger: options.logger,
|
|
1156
|
+
opts: options.options
|
|
1157
|
+
});
|
|
1158
|
+
|
|
1159
|
+
const stickerPackUploadResult = await options.upload(stickerPackUpload.encFilePath, {
|
|
1160
|
+
fileEncSha256B64: stickerPackUpload.fileEncSha256.toString('base64'),
|
|
1161
|
+
mediaType: 'sticker-pack',
|
|
1162
|
+
timeoutMs: options.mediaUploadTimeoutMs
|
|
1163
|
+
});
|
|
1164
|
+
|
|
1165
|
+
await fs_1.promises.unlink(stickerPackUpload.encFilePath);
|
|
1166
|
+
|
|
1167
|
+
const stickerPackMessage = {
|
|
1168
|
+
name: name,
|
|
1169
|
+
publisher: publisher,
|
|
1170
|
+
stickerPackId: stickerPackIdValue,
|
|
1171
|
+
packDescription: description,
|
|
1172
|
+
stickerPackOrigin: WAProto_1.proto.Message.StickerPackMessage.StickerPackOrigin.USER_CREATED,
|
|
1173
|
+
stickerPackSize: stickerPackSize,
|
|
1174
|
+
stickers: stickerMetadata,
|
|
1175
|
+
fileSha256: stickerPackUpload.fileSha256,
|
|
1176
|
+
fileEncSha256: stickerPackUpload.fileEncSha256,
|
|
1177
|
+
mediaKey: stickerPackUpload.mediaKey,
|
|
1178
|
+
directPath: stickerPackUploadResult.directPath,
|
|
1179
|
+
fileLength: stickerPackUpload.fileLength,
|
|
1180
|
+
mediaKeyTimestamp: (0, generics_1.unixTimestampSeconds)(),
|
|
1181
|
+
trayIconFileName: trayIconFileName
|
|
1182
|
+
};
|
|
1183
|
+
|
|
1184
|
+
try {
|
|
1185
|
+
let thumbnailBuffer;
|
|
1186
|
+
if (lib.sharp) {
|
|
1187
|
+
thumbnailBuffer = await lib.sharp(coverBuffer).resize(252, 252).jpeg().toBuffer();
|
|
1188
|
+
} else if (lib.jimp) {
|
|
1189
|
+
const jimpImage = await lib.jimp.read(coverBuffer);
|
|
1190
|
+
thumbnailBuffer = await jimpImage.resize(252, 252).getBufferAsync(lib.jimp.MIME_JPEG);
|
|
1191
|
+
} else {
|
|
1192
|
+
throw new Error('No image processing library available for thumbnail generation');
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
if (!thumbnailBuffer || thumbnailBuffer.length === 0) {
|
|
1196
|
+
throw new Error('Failed to generate thumbnail buffer');
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
const thumbUpload = await (0, messages_media_1.encryptedStream)(thumbnailBuffer, 'thumbnail-sticker-pack', {
|
|
1200
|
+
logger: options.logger,
|
|
1201
|
+
opts: options.options,
|
|
1202
|
+
mediaKey: stickerPackUpload.mediaKey
|
|
1203
|
+
});
|
|
1204
|
+
|
|
1205
|
+
const thumbUploadResult = await options.upload(thumbUpload.encFilePath, {
|
|
1206
|
+
fileEncSha256B64: thumbUpload.fileEncSha256.toString('base64'),
|
|
1207
|
+
mediaType: 'thumbnail-sticker-pack',
|
|
1208
|
+
timeoutMs: options.mediaUploadTimeoutMs
|
|
1209
|
+
});
|
|
1210
|
+
|
|
1211
|
+
await fs_1.promises.unlink(thumbUpload.encFilePath);
|
|
1212
|
+
|
|
1213
|
+
Object.assign(stickerPackMessage, {
|
|
1214
|
+
thumbnailDirectPath: thumbUploadResult.directPath,
|
|
1215
|
+
thumbnailSha256: thumbUpload.fileSha256,
|
|
1216
|
+
thumbnailEncSha256: thumbUpload.fileEncSha256,
|
|
1217
|
+
thumbnailHeight: 252,
|
|
1218
|
+
thumbnailWidth: 252,
|
|
1219
|
+
imageDataHash: (0, crypto_2.sha256)(thumbnailBuffer).toString('base64')
|
|
1220
|
+
});
|
|
1221
|
+
|
|
1222
|
+
} catch (e) {
|
|
1223
|
+
options.logger === null || options.logger === void 0 ? void 0 : options.logger.warn(`Thumbnail generation failed: ${e}`);
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
return { stickerPackMessage };
|
|
1227
|
+
};
|
|
1228
|
+
exports.prepareStickerPackMessage = prepareStickerPackMessage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexxhayanasi/elaina-baileys",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "Custom Baileys WhatsApp API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"baileys",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"audio-decode": "^2.1.3",
|
|
51
51
|
"axios": "^1.6.0",
|
|
52
52
|
"chalk": "^4.1.2",
|
|
53
|
+
"fflate": "^0.8.2",
|
|
53
54
|
"gradient-string": "^2.0.2",
|
|
54
55
|
"cache-manager": "^5.7.6",
|
|
55
56
|
"cheerio": "^1.0.0-rc.12",
|
|
@@ -88,8 +89,7 @@
|
|
|
88
89
|
"jimp": "^0.22.10",
|
|
89
90
|
"link-preview-js": "^3.0.0",
|
|
90
91
|
"qrcode-terminal": "^0.12.0",
|
|
91
|
-
"sharp": "^0.34.1"
|
|
92
|
-
"better-sqlite3": "^12.5.0"
|
|
92
|
+
"sharp": "^0.34.1"
|
|
93
93
|
},
|
|
94
94
|
"peerDependenciesMeta": {
|
|
95
95
|
"jimp": {
|
|
@@ -103,7 +103,10 @@
|
|
|
103
103
|
},
|
|
104
104
|
"sharp": {
|
|
105
105
|
"optional": true
|
|
106
|
-
}
|
|
106
|
+
},
|
|
107
|
+
"better-sqlite3": {
|
|
108
|
+
"optional": true
|
|
109
|
+
}
|
|
107
110
|
},
|
|
108
111
|
"packageManager": "yarn@1.22.19",
|
|
109
112
|
"engines": {
|