@systemzero/baileys 1.0.3 → 1.0.5
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/README.md +1020 -0
- package/lib/Defaults/index.js +9 -3
- package/lib/MB.cjs +8 -0
- package/lib/MessageBuilder.cjs +2509 -0
- package/lib/Socket/messages-send.js +51 -20
- package/lib/Types/Message.js +7 -0
- package/lib/Utils/messages-media.js +4 -3
- package/lib/Utils/messages.js +533 -8
- package/package.json +2 -2
|
@@ -12,6 +12,7 @@ import { makeNewsletterSocket } from './newsletter.js';
|
|
|
12
12
|
import Hzxx from './hzxx.js';
|
|
13
13
|
import { randomBytes } from 'crypto';
|
|
14
14
|
import axios from 'axios';
|
|
15
|
+
|
|
15
16
|
const META_AI_BOT_JID = '867051314767696@bot';
|
|
16
17
|
const META_AI_BOT_NAME = 'Meta AI';
|
|
17
18
|
const META_AI_CREATOR_NAME = 'Meta';
|
|
@@ -567,7 +568,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
567
568
|
if (isNewsletter) {
|
|
568
569
|
const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
|
|
569
570
|
const bytes = encodeNewsletterMessage(patched);
|
|
570
|
-
binaryNodeContent.push({ tag: 'plaintext', attrs:
|
|
571
|
+
binaryNodeContent.push({ tag: 'plaintext', attrs: extraAttrs, content: bytes });
|
|
571
572
|
const stanza = {
|
|
572
573
|
tag: 'message',
|
|
573
574
|
attrs: { to: jid, id: msgId, type: getMessageType(message), ...(additionalAttributes || {}) },
|
|
@@ -817,27 +818,28 @@ export const makeMessagesSocket = (config) => {
|
|
|
817
818
|
if (btn.name === 'payment_info' || btn.name === 'review_and_pay') {
|
|
818
819
|
try {
|
|
819
820
|
const params = JSON.parse(btn.buttonParamsJson);
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
params.order
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
821
|
+
if (btn.name !== 'galaxy_message') {
|
|
822
|
+
params.currency = params.currency || 'BRL';
|
|
823
|
+
params.total_amount = params.total_amount || { value: 0, offset: 100 };
|
|
824
|
+
params.reference_id = params.reference_id || randomBytes(4).toString('hex').toUpperCase();
|
|
825
|
+
params.type = params.type || 'physical-goods';
|
|
826
|
+
if (!params.order) {
|
|
827
|
+
params.order = {
|
|
828
|
+
status: 'pending',
|
|
829
|
+
subtotal: params.total_amount,
|
|
830
|
+
order_type: 'ORDER',
|
|
831
|
+
items: [{
|
|
832
|
+
name: 'Fatura via Pix',
|
|
833
|
+
amount: params.total_amount,
|
|
834
|
+
quantity: 1,
|
|
835
|
+
sale_amount: params.total_amount
|
|
836
|
+
}]
|
|
837
|
+
};
|
|
838
|
+
}
|
|
836
839
|
}
|
|
837
|
-
|
|
838
840
|
btn.buttonParamsJson = JSON.stringify(params);
|
|
839
841
|
} catch (e) {
|
|
840
|
-
logger.error({ err: e }, "
|
|
842
|
+
logger.error({ err: e }, "Erro ao processar JSON de Botao Nativo");
|
|
841
843
|
}
|
|
842
844
|
}
|
|
843
845
|
return btn;
|
|
@@ -1157,7 +1159,36 @@ export const makeMessagesSocket = (config) => {
|
|
|
1157
1159
|
ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }]);
|
|
1158
1160
|
return message;
|
|
1159
1161
|
},
|
|
1160
|
-
sendMessage
|
|
1162
|
+
sendMessage,
|
|
1163
|
+
sendVitrine: async function(jid, title, description, productId, imageBuffer, options = {}) {
|
|
1164
|
+
try {
|
|
1165
|
+
const tempMsg = await generateWAMessage(jid, { image: imageBuffer }, {
|
|
1166
|
+
userJid: authState.creds.me.id,
|
|
1167
|
+
upload: waUploadToServer,
|
|
1168
|
+
logger
|
|
1169
|
+
});
|
|
1170
|
+
|
|
1171
|
+
const productImage = tempMsg.message.imageMessage;
|
|
1172
|
+
|
|
1173
|
+
const productMsg = generateWAMessageFromContent(jid, {
|
|
1174
|
+
productMessage: {
|
|
1175
|
+
product: {
|
|
1176
|
+
productImage: productImage,
|
|
1177
|
+
productId: String(productId),
|
|
1178
|
+
title: title,
|
|
1179
|
+
description: description,
|
|
1180
|
+
productImageCount: 1
|
|
1181
|
+
},
|
|
1182
|
+
businessOwnerJid: authState.creds.me.id.split(':')[0] + '@s.whatsapp.net'
|
|
1183
|
+
}
|
|
1184
|
+
}, { userJid: authState.creds.me.id, quoted: options.quoted });
|
|
1185
|
+
|
|
1186
|
+
return await relayMessage(jid, productMsg.message, { messageId: productMsg.key.id });
|
|
1187
|
+
} catch (e) {
|
|
1188
|
+
logger.error({ err: e }, "Erro ao enviar vitrine");
|
|
1189
|
+
throw e;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1161
1192
|
};
|
|
1162
1193
|
};
|
|
1163
1194
|
//# sourceMappingURL=messages-send.js.map
|
package/lib/Types/Message.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
export const ButtonHeaderType = proto.Message.ButtonsMessage.HeaderType;
|
|
3
|
+
export const ButtonType = proto.Message.ButtonsMessage.Button.Type;
|
|
4
|
+
export const CarouselCardType = proto.Message.InteractiveMessage.CarouselMessage.CarouselCardType;
|
|
5
|
+
export const ListType = proto.Message.ListMessage.ListType;
|
|
6
|
+
export const ProtocolType = proto.Message.ProtocolMessage.Type;
|
|
7
|
+
export const AssociationType = proto.MessageAssociation?.AssociationType;
|
|
8
|
+
|
|
2
9
|
// export the WAMessage Prototypes
|
|
3
10
|
export { proto as WAProto };
|
|
4
11
|
export const WAMessageStubType = proto.WebMessageInfo.StubType;
|
|
@@ -13,7 +13,7 @@ import { getBinaryNodeChild, getBinaryNodeChildBuffer, jidNormalizedUser } from
|
|
|
13
13
|
import { aesDecryptGCM, aesEncryptGCM, hkdf } from './crypto.js';
|
|
14
14
|
import { generateMessageIDV2 } from './generics.js';
|
|
15
15
|
const getTmpFilesDirectory = () => tmpdir();
|
|
16
|
-
const getImageProcessingLibrary = async () => {
|
|
16
|
+
export const getImageProcessingLibrary = async () => {
|
|
17
17
|
//@ts-ignore
|
|
18
18
|
const [jimp, sharp] = await Promise.all([import('jimp').catch(() => { }), import('sharp').catch(() => { })]);
|
|
19
19
|
if (sharp) {
|
|
@@ -210,7 +210,8 @@ export async function getAudioWaveform(buffer, logger) {
|
|
|
210
210
|
}
|
|
211
211
|
const audioBuffer = await decoder(audioData);
|
|
212
212
|
const rawData = audioBuffer.getChannelData(0); // We only need to work with one channel of data
|
|
213
|
-
const samples = 64;
|
|
213
|
+
const samples = 64;
|
|
214
|
+
const minHeight = 0.05;
|
|
214
215
|
const blockSize = Math.floor(rawData.length / samples); // the number of samples in each subdivision
|
|
215
216
|
const filteredData = [];
|
|
216
217
|
for (let i = 0; i < samples; i++) {
|
|
@@ -225,7 +226,7 @@ export async function getAudioWaveform(buffer, logger) {
|
|
|
225
226
|
const multiplier = Math.pow(Math.max(...filteredData), -1);
|
|
226
227
|
const normalizedData = filteredData.map(n => n * multiplier);
|
|
227
228
|
// Generate waveform like WhatsApp
|
|
228
|
-
const waveform = new Uint8Array(normalizedData.map(n => Math.floor(100 * n)));
|
|
229
|
+
const waveform = new Uint8Array(normalizedData.map(n => Math.max(minHeight, n)).map(n => Math.floor(100 * n)));
|
|
229
230
|
return waveform;
|
|
230
231
|
}
|
|
231
232
|
catch (e) {
|