luna-baileys 9.0.24 → 9.0.25
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/package.json +1 -1
- package/src/Utils/messages.js +71 -0
package/package.json
CHANGED
package/src/Utils/messages.js
CHANGED
|
@@ -730,6 +730,31 @@ export const hasValidCarouselHeader = (message) => {
|
|
|
730
730
|
message.videoMessage ||
|
|
731
731
|
message.productMessage);
|
|
732
732
|
};
|
|
733
|
+
|
|
734
|
+
// Accept the same raw buttonsMessage payload used by Noxleyss. Location
|
|
735
|
+
// thumbnails are normalized to JPEG before being placed in the protobuf.
|
|
736
|
+
const processLocationThumbnail = async (input, options = {}) => {
|
|
737
|
+
let buffer;
|
|
738
|
+
if (Buffer.isBuffer(input)) {
|
|
739
|
+
buffer = input;
|
|
740
|
+
}
|
|
741
|
+
else if (typeof input === 'string' && /^https?:\/\//i.test(input)) {
|
|
742
|
+
const response = await fetch(input, { dispatcher: options?.dispatcher });
|
|
743
|
+
if (!response.ok) {
|
|
744
|
+
throw new Boom(`could not fetch location thumbnail: ${response.status}`, { statusCode: 400 });
|
|
745
|
+
}
|
|
746
|
+
buffer = Buffer.from(await response.arrayBuffer());
|
|
747
|
+
}
|
|
748
|
+
else if (typeof input === 'string') {
|
|
749
|
+
buffer = await fs.readFile(input);
|
|
750
|
+
}
|
|
751
|
+
else {
|
|
752
|
+
throw new Boom('location thumbnail must be a URL, file path, or Buffer', { statusCode: 400 });
|
|
753
|
+
}
|
|
754
|
+
const { buffer: jpeg } = await extractImageThumb(buffer, 300);
|
|
755
|
+
return jpeg;
|
|
756
|
+
};
|
|
757
|
+
|
|
733
758
|
export const generateWAMessageContent = async (message, options) => {
|
|
734
759
|
var _a, _b;
|
|
735
760
|
let m = {};
|
|
@@ -1216,6 +1241,52 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
1216
1241
|
})
|
|
1217
1242
|
};
|
|
1218
1243
|
}
|
|
1244
|
+
else if (hasNonNullishProperty(message, 'buttonsMessage')) {
|
|
1245
|
+
const bm = message.buttonsMessage;
|
|
1246
|
+
let locationMessage;
|
|
1247
|
+
|
|
1248
|
+
if (bm.locationMessage) {
|
|
1249
|
+
const loc = bm.locationMessage;
|
|
1250
|
+
const thumbnailInput = loc.jpegThumbnail || loc.thumbnail;
|
|
1251
|
+
const jpegThumbnail = thumbnailInput
|
|
1252
|
+
? await processLocationThumbnail(thumbnailInput, options?.options)
|
|
1253
|
+
: undefined;
|
|
1254
|
+
|
|
1255
|
+
locationMessage = proto.Message.LocationMessage.create({
|
|
1256
|
+
degreesLatitude: loc.degreesLatitude ?? 0,
|
|
1257
|
+
degreesLongitude: loc.degreesLongitude ?? 0,
|
|
1258
|
+
name: loc.name || '',
|
|
1259
|
+
address: loc.address || '',
|
|
1260
|
+
jpegThumbnail
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
const buttons = (bm.buttons || []).map(button => proto.Message.ButtonsMessage.Button.create({
|
|
1265
|
+
buttonId: button.buttonId || '',
|
|
1266
|
+
buttonText: proto.Message.ButtonsMessage.Button.ButtonText.create({
|
|
1267
|
+
displayText: button.buttonText?.displayText || ''
|
|
1268
|
+
}),
|
|
1269
|
+
type: button.type ?? 1,
|
|
1270
|
+
nativeFlowInfo: button.nativeFlowInfo
|
|
1271
|
+
? proto.Message.ButtonsMessage.Button.NativeFlowInfo.create({
|
|
1272
|
+
name: button.nativeFlowInfo.name || '',
|
|
1273
|
+
paramsJson: button.nativeFlowInfo.paramsJson || '',
|
|
1274
|
+
buttonParamsJson: button.nativeFlowInfo.buttonParamsJson || button.nativeFlowInfo.paramsJson || ''
|
|
1275
|
+
})
|
|
1276
|
+
: undefined
|
|
1277
|
+
}));
|
|
1278
|
+
|
|
1279
|
+
m = {
|
|
1280
|
+
buttonsMessage: proto.Message.ButtonsMessage.create({
|
|
1281
|
+
locationMessage,
|
|
1282
|
+
contentText: bm.contentText || '',
|
|
1283
|
+
footerText: bm.footerText || '',
|
|
1284
|
+
buttons,
|
|
1285
|
+
headerType: bm.headerType ?? 6,
|
|
1286
|
+
viewOnce: !!bm.viewOnce
|
|
1287
|
+
})
|
|
1288
|
+
};
|
|
1289
|
+
}
|
|
1219
1290
|
else {
|
|
1220
1291
|
m = await prepareWAMessageMedia(message, options);
|
|
1221
1292
|
}
|