@itsliaaa/baileys 0.1.16-beta.2 → 0.1.16
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 +18 -12
- package/lib/Socket/socket.js +3 -4
- package/lib/Utils/companion-reg-client-utils.js +32 -0
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/messages-media.js +1 -1
- package/lib/Utils/messages.js +12 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -585,8 +585,10 @@ sock.sendMessage(jid, {
|
|
|
585
585
|
footer: '@itsliaaa/baileys',
|
|
586
586
|
optionText: '👉🏻 Select Options', // --- Optional, wrap all native flow into a single list
|
|
587
587
|
optionTitle: '📄 Select Options', // --- Optional
|
|
588
|
-
|
|
589
|
-
|
|
588
|
+
offerText: '🏷️ Newest Coupon!', // --- Optional, add an offer into message
|
|
589
|
+
offerCode: '@itsliaaa/baileys', // --- Optional
|
|
590
|
+
offerUrl: 'https://www.npmjs.com/package/@itsliaaa/baileys', // --- Optional
|
|
591
|
+
offerExpiration: Date.now() + 3_600_000, // --- Optional
|
|
590
592
|
nativeFlow: [{
|
|
591
593
|
text: '👋🏻 Greeting',
|
|
592
594
|
id: '#Greeting'
|
|
@@ -598,7 +600,7 @@ sock.sendMessage(jid, {
|
|
|
598
600
|
copy: '@itsliaaa/baileys'
|
|
599
601
|
}, {
|
|
600
602
|
text: '🌐 Source',
|
|
601
|
-
url: 'https://www.npmjs.com/package/baileys'
|
|
603
|
+
url: 'https://www.npmjs.com/package/@itsliaaa/baileys'
|
|
602
604
|
}, {
|
|
603
605
|
text: '📋 Select',
|
|
604
606
|
sections: [{
|
|
@@ -637,7 +639,7 @@ sock.sendMessage(jid, {
|
|
|
637
639
|
footer: '🏷️️ Pinterest',
|
|
638
640
|
nativeFlow: [{
|
|
639
641
|
text: '🌐 Source',
|
|
640
|
-
url: 'https://www.npmjs.com/package/baileys'
|
|
642
|
+
url: 'https://www.npmjs.com/package/@itsliaaa/baileys'
|
|
641
643
|
}]
|
|
642
644
|
}, {
|
|
643
645
|
image: {
|
|
@@ -645,11 +647,13 @@ sock.sendMessage(jid, {
|
|
|
645
647
|
},
|
|
646
648
|
caption: '🖼️ Image 2',
|
|
647
649
|
footer: '🏷️ Pinterest',
|
|
648
|
-
|
|
649
|
-
|
|
650
|
+
offerText: '🏷️ New Coupon!',
|
|
651
|
+
offerCode: '@itsliaaa/baileys',
|
|
652
|
+
offerUrl: 'https://www.npmjs.com/package/@itsliaaa/baileys',
|
|
653
|
+
offerExpiration: Date.now() + 3_600_000,
|
|
650
654
|
nativeFlow: [{
|
|
651
655
|
text: '🌐 Source',
|
|
652
|
-
url: 'https://www.npmjs.com/package/baileys'
|
|
656
|
+
url: 'https://www.npmjs.com/package/@itsliaaa/baileys'
|
|
653
657
|
}]
|
|
654
658
|
}, {
|
|
655
659
|
image: {
|
|
@@ -659,14 +663,16 @@ sock.sendMessage(jid, {
|
|
|
659
663
|
footer: '🏷️ Pinterest',
|
|
660
664
|
optionText: '👉🏻 Select Options',
|
|
661
665
|
optionTitle: '📄 Select Options',
|
|
662
|
-
|
|
663
|
-
|
|
666
|
+
offerText: '🏷️ New Coupon!',
|
|
667
|
+
offerCode: '@itsliaaa/baileys',
|
|
668
|
+
offerUrl: 'https://www.npmjs.com/package/@itsliaaa/baileys',
|
|
669
|
+
offerExpiration: Date.now() + 3_600_000,
|
|
664
670
|
nativeFlow: [{
|
|
665
671
|
text: '🛒 Product',
|
|
666
672
|
id: '#Product'
|
|
667
673
|
}, {
|
|
668
674
|
text: '🌐 Source',
|
|
669
|
-
url: 'https://www.npmjs.com/package/baileys'
|
|
675
|
+
url: 'https://www.npmjs.com/package/@itsliaaa/baileys'
|
|
670
676
|
}]
|
|
671
677
|
}]
|
|
672
678
|
}, {
|
|
@@ -689,7 +695,7 @@ sock.sendMessage(jid, {
|
|
|
689
695
|
id: '#Order'
|
|
690
696
|
}, {
|
|
691
697
|
text: '🌐 Source',
|
|
692
|
-
url: 'https://www.npmjs.com/package/baileys'
|
|
698
|
+
url: 'https://www.npmjs.com/package/@itsliaaa/baileys'
|
|
693
699
|
}, {
|
|
694
700
|
text: '📞 Call',
|
|
695
701
|
call: '628123456789'
|
|
@@ -806,7 +812,7 @@ sock.sendMessage(jid, {
|
|
|
806
812
|
body: '❓ I dont know',
|
|
807
813
|
thumbnail: fs.readFileSync('./path/to/image.jpg'), // --- Must in buffer format
|
|
808
814
|
largeThumbnail: false, // --- Or true for bigger thumbnail
|
|
809
|
-
url: 'https://www.npmjs.com/package/baileys' // --- Optional, used for WhatsApp internal thumbnail caching and direct URL
|
|
815
|
+
url: 'https://www.npmjs.com/package/@itsliaaa/baileys' // --- Optional, used for WhatsApp internal thumbnail caching and direct URL
|
|
810
816
|
}
|
|
811
817
|
}, {
|
|
812
818
|
quoted: message
|
package/lib/Socket/socket.js
CHANGED
|
@@ -5,8 +5,7 @@ import { promisify } from 'util';
|
|
|
5
5
|
import { proto } from '../../WAProto/index.js';
|
|
6
6
|
import { DEF_CALLBACK_PREFIX, DEF_TAG_PREFIX, INITIAL_PREKEY_COUNT, MIN_PREKEY_COUNT, MIN_UPLOAD_INTERVAL, NOISE_WA_HEADER, PROCESSABLE_HISTORY_TYPES, TimeMs, UPLOAD_TIMEOUT } from '../Defaults/index.js';
|
|
7
7
|
import { DisconnectReason } from '../Types/index.js';
|
|
8
|
-
import { addTransactionCapability, aesEncryptCTR, bindWaitForConnectionUpdate, bytesToCrockford, configureSuccessfulPairing, Curve, derivePairingCodeKey, generateLoginNode, generateMdTagPrefix, generateRegistrationNode, getCodeFromWSError, getErrorCodeFromStreamError, getNextPreKeysNode, makeEventBuffer, makeNoiseHandler, promiseTimeout, signedKeyPair, xmppSignedPreKey } from '../Utils/index.js';
|
|
9
|
-
import { getPlatformId } from '../Utils/browser-utils.js';
|
|
8
|
+
import { addTransactionCapability, aesEncryptCTR, bindWaitForConnectionUpdate, bytesToCrockford, buildPairingQRData, configureSuccessfulPairing, Curve, derivePairingCodeKey, generateLoginNode, generateMdTagPrefix, generateRegistrationNode, getCompanionPlatformId, getCodeFromWSError, getErrorCodeFromStreamError, getNextPreKeysNode, makeEventBuffer, makeNoiseHandler, promiseTimeout, signedKeyPair, xmppSignedPreKey } from '../Utils/index.js';
|
|
10
9
|
import { assertNodeErrorFree, binaryNodeToString, encodeBinaryNode, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildren, isLidUser, jidDecode, jidEncode, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
11
10
|
import { BinaryInfo } from '../WAM/BinaryInfo.js';
|
|
12
11
|
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
@@ -629,7 +628,7 @@ export const makeSocket = (config) => {
|
|
|
629
628
|
{
|
|
630
629
|
tag: 'companion_platform_id',
|
|
631
630
|
attrs: {},
|
|
632
|
-
content:
|
|
631
|
+
content: getCompanionPlatformId(browser)
|
|
633
632
|
},
|
|
634
633
|
{
|
|
635
634
|
tag: 'companion_platform_display',
|
|
@@ -712,7 +711,7 @@ export const makeSocket = (config) => {
|
|
|
712
711
|
return;
|
|
713
712
|
}
|
|
714
713
|
const ref = refNode.content.toString('utf-8');
|
|
715
|
-
const qr =
|
|
714
|
+
const qr = buildPairingQRData(ref, noiseKeyB64, identityKeyB64, advB64, browser);
|
|
716
715
|
ev.emit('connection.update', { qr });
|
|
717
716
|
qrTimer = setTimeout(genPairQR, qrMs);
|
|
718
717
|
qrMs = qrTimeout || 20000; // shorter subsequent qrs
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const CompanionWebClientType = {
|
|
2
|
+
UNKNOWN: 0,
|
|
3
|
+
CHROME: 1,
|
|
4
|
+
EDGE: 2,
|
|
5
|
+
FIREFOX: 3,
|
|
6
|
+
IE: 4,
|
|
7
|
+
OPERA: 5,
|
|
8
|
+
SAFARI: 6,
|
|
9
|
+
ELECTRON: 7,
|
|
10
|
+
UWP: 8,
|
|
11
|
+
OTHER_WEB_CLIENT: 9
|
|
12
|
+
};
|
|
13
|
+
const BROWSER_TO_COMPANION_WEB_CLIENT = {
|
|
14
|
+
Chrome: CompanionWebClientType.CHROME,
|
|
15
|
+
Edge: CompanionWebClientType.EDGE,
|
|
16
|
+
Firefox: CompanionWebClientType.FIREFOX,
|
|
17
|
+
IE: CompanionWebClientType.IE,
|
|
18
|
+
Opera: CompanionWebClientType.OPERA,
|
|
19
|
+
Safari: CompanionWebClientType.SAFARI
|
|
20
|
+
};
|
|
21
|
+
export const getCompanionWebClientType = ([os, browserName]) => {
|
|
22
|
+
if (browserName === 'Desktop') {
|
|
23
|
+
return os === 'Windows' ? CompanionWebClientType.UWP : CompanionWebClientType.ELECTRON;
|
|
24
|
+
}
|
|
25
|
+
return BROWSER_TO_COMPANION_WEB_CLIENT[browserName] || CompanionWebClientType.OTHER_WEB_CLIENT;
|
|
26
|
+
};
|
|
27
|
+
export const getCompanionPlatformId = (browser) => {
|
|
28
|
+
return getCompanionWebClientType(browser).toString();
|
|
29
|
+
};
|
|
30
|
+
export const buildPairingQRData = (ref, noiseKeyB64, identityKeyB64, advB64, browser) => {
|
|
31
|
+
return [ref, noiseKeyB64, identityKeyB64, advB64, getCompanionPlatformId(browser)].join(',');
|
|
32
|
+
};
|
package/lib/Utils/index.js
CHANGED
|
@@ -17,5 +17,6 @@ export * from './event-buffer.js';
|
|
|
17
17
|
export * from './process-message.js';
|
|
18
18
|
export * from './message-retry-manager.js';
|
|
19
19
|
export * from './browser-utils.js';
|
|
20
|
+
export * from './companion-reg-client-utils.js';
|
|
20
21
|
export * from './identity-change-handler.js';
|
|
21
22
|
export * from './stanza-ack.js';
|
|
@@ -700,7 +700,7 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
|
|
|
700
700
|
logger.debug(`uploading to "${hostname}"`);
|
|
701
701
|
const auth = encodeURIComponent(uploadInfo.auth);
|
|
702
702
|
// Lia@Changes 06-02-26 --- Switch media path map for newsletter uploads
|
|
703
|
-
const mediaPathMap =
|
|
703
|
+
const mediaPathMap = newsletter ? NEWSLETTER_MEDIA_PATH_MAP : MEDIA_PATH_MAP
|
|
704
704
|
// Lia@Changes 20-03-26 --- Add server thumb for newsletter media
|
|
705
705
|
const serverThumb = newsletter ? '&server_thumb_gen=1' : ''
|
|
706
706
|
const url = `https://${hostname}${mediaPathMap[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}${serverThumb}`;
|
package/lib/Utils/messages.js
CHANGED
|
@@ -534,14 +534,14 @@ const prepareNativeFlowButtons = (message) => {
|
|
|
534
534
|
const isButtonsFieldArray = Array.isArray(buttons);
|
|
535
535
|
const correctedField = isButtonsFieldArray ? buttons : buttons.buttons;
|
|
536
536
|
const messageParamsJson = {};
|
|
537
|
-
// Lia@Changes 31-01-26 --- Add
|
|
538
|
-
if (hasOptionalProperty(message, '
|
|
537
|
+
// Lia@Changes 31-01-26 --- Add offer and options inside interactive message
|
|
538
|
+
if (hasOptionalProperty(message, 'offerText') && !!message.offerText) {
|
|
539
539
|
Object.assign(messageParamsJson, {
|
|
540
540
|
limited_time_offer: {
|
|
541
|
-
text: message.
|
|
542
|
-
url: message.
|
|
543
|
-
copy_code: message.
|
|
544
|
-
expiration_time:
|
|
541
|
+
text: message.offerText || LIBRARY_NAME,
|
|
542
|
+
url: message.offerUrl || DONATE_URL, // Lia@Note 02-02-26 --- Apologies if this feels cheeky, just a fallback
|
|
543
|
+
copy_code: message.offerCode,
|
|
544
|
+
expiration_time: message.offerExpiration
|
|
545
545
|
}
|
|
546
546
|
});
|
|
547
547
|
}
|
|
@@ -560,7 +560,7 @@ const prepareNativeFlowButtons = (message) => {
|
|
|
560
560
|
}
|
|
561
561
|
return {
|
|
562
562
|
buttons: correctedField.map(button => {
|
|
563
|
-
const buttonText = button.text
|
|
563
|
+
const buttonText = button.text;
|
|
564
564
|
if (hasOptionalProperty(button, 'id') && !!button.id) {
|
|
565
565
|
return {
|
|
566
566
|
name: 'quick_reply',
|
|
@@ -1037,7 +1037,7 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
1037
1037
|
const buttonsMessage = {
|
|
1038
1038
|
buttons: message.buttons.map(button => {
|
|
1039
1039
|
// Lia@Changes 12-03-26 --- Add "single_select" shortcut!
|
|
1040
|
-
const buttonText = button.text
|
|
1040
|
+
const buttonText = button.text;
|
|
1041
1041
|
if (hasOptionalProperty(button, 'sections')) {
|
|
1042
1042
|
return {
|
|
1043
1043
|
nativeFlowInfo: {
|
|
@@ -1098,11 +1098,12 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
1098
1098
|
else if (hasNonNullishProperty(message, 'templateButtons')) {
|
|
1099
1099
|
const hydratedTemplate = {
|
|
1100
1100
|
hydratedButtons: message.templateButtons.map((button, i) => {
|
|
1101
|
+
const buttonText = button.text;
|
|
1101
1102
|
if (hasOptionalProperty(button, 'id')) {
|
|
1102
1103
|
return {
|
|
1103
1104
|
index: i,
|
|
1104
1105
|
quickReplyButton: {
|
|
1105
|
-
displayText:
|
|
1106
|
+
displayText: buttonText || '👉🏻 Click',
|
|
1106
1107
|
id: button.id
|
|
1107
1108
|
}
|
|
1108
1109
|
};
|
|
@@ -1111,7 +1112,7 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
1111
1112
|
return {
|
|
1112
1113
|
index: i,
|
|
1113
1114
|
urlButton: {
|
|
1114
|
-
displayText:
|
|
1115
|
+
displayText: buttonText || '🌐 Visit',
|
|
1115
1116
|
url: button.url
|
|
1116
1117
|
}
|
|
1117
1118
|
};
|
|
@@ -1120,7 +1121,7 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
1120
1121
|
return {
|
|
1121
1122
|
index: i,
|
|
1122
1123
|
callButton: {
|
|
1123
|
-
displayText:
|
|
1124
|
+
displayText: buttonText || '📞 Call',
|
|
1124
1125
|
phoneNumber: button.call
|
|
1125
1126
|
}
|
|
1126
1127
|
};
|