@elrayyxml/baileys 1.0.3 → 1.0.7
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 +2517 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +51 -0
- package/lib/Defaults/index.js +9 -1
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/business.d.ts +172 -0
- package/lib/Socket/chats.d.ts +82 -0
- package/lib/Socket/groups.d.ts +124 -0
- package/lib/Socket/index.d.ts +172 -0
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-send.d.ts +151 -0
- package/lib/Socket/messages-send.js +236 -59
- package/lib/Socket/newsletter.d.ts +136 -0
- package/lib/Socket/newsletter.js +5 -1
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Store/index.d.ts +2 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Types/Auth.d.ts +103 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Chat.d.ts +109 -0
- package/lib/Types/Contact.d.ts +23 -0
- package/lib/Types/Events.d.ts +199 -0
- package/lib/Types/GroupMetadata.d.ts +64 -0
- package/lib/Types/Label.d.ts +35 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/Message.d.ts +400 -0
- package/lib/Types/Newsletter.d.ts +79 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Socket.d.ts +119 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/index.d.ts +64 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/decode-wa-message.d.ts +35 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/generics.d.ts +89 -0
- package/lib/Utils/generics.js +31 -4
- package/lib/Utils/history.d.ts +19 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/logger.d.ts +11 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/messages-media.d.ts +120 -0
- package/lib/Utils/messages.d.ts +75 -0
- package/lib/Utils/messages.js +400 -38
- package/lib/Utils/noise-handler.d.ts +19 -0
- package/lib/Utils/process-message.d.ts +42 -0
- package/lib/Utils/signal.d.ts +33 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/lib/Utils/validate-connection.d.ts +10 -0
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/decode.d.ts +6 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/generic-utils.d.ts +14 -0
- package/lib/WABinary/generic-utils.js +11 -8
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/jid-utils.d.ts +36 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +4 -1
- package/package.json +17 -14
- package/README.MD +0 -78
- package/lib/Socket/type.js +0 -405
|
@@ -14,7 +14,6 @@ const link_preview_1 = require("../Utils/link-preview");
|
|
|
14
14
|
const WABinary_1 = require("../WABinary");
|
|
15
15
|
const WAUSync_1 = require("../WAUSync");
|
|
16
16
|
const newsletter_1 = require("./newsletter");
|
|
17
|
-
const elrayyxml_1 = require("./type");
|
|
18
17
|
const makeMessagesSocket = (config) => {
|
|
19
18
|
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata, } = config;
|
|
20
19
|
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
|
@@ -489,17 +488,26 @@ const makeMessagesSocket = (config) => {
|
|
|
489
488
|
content: (0, Utils_1.encodeSignedDeviceIdentity)(authState.creds.account, true)
|
|
490
489
|
});
|
|
491
490
|
logger.debug({ jid }, 'adding device identity');
|
|
492
|
-
}
|
|
493
|
-
|
|
491
|
+
}
|
|
494
492
|
if (AI && isPrivate) {
|
|
495
493
|
const botNode = {
|
|
496
494
|
tag: 'bot',
|
|
497
|
-
attrs: {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
495
|
+
attrs: {
|
|
496
|
+
biz_bot: '1'
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
|
|
501
|
+
|
|
502
|
+
if (filteredBizBot) {
|
|
503
|
+
stanza.content.push(...additionalNodes)
|
|
504
|
+
didPushAdditional = true
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
else {
|
|
508
|
+
stanza.content.push(botNode)
|
|
509
|
+
}
|
|
501
510
|
}
|
|
502
|
-
|
|
503
511
|
if (additionalNodes && additionalNodes.length > 0) {
|
|
504
512
|
stanza.content.push(...additionalNodes);
|
|
505
513
|
}
|
|
@@ -561,6 +569,9 @@ const makeMessagesSocket = (config) => {
|
|
|
561
569
|
else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
|
|
562
570
|
return 'poll';
|
|
563
571
|
}
|
|
572
|
+
else if (msg.eventMessage) {
|
|
573
|
+
return 'event';
|
|
574
|
+
}
|
|
564
575
|
else if (getMediaType(msg)) {
|
|
565
576
|
return 'media';
|
|
566
577
|
}
|
|
@@ -572,27 +583,39 @@ const makeMessagesSocket = (config) => {
|
|
|
572
583
|
if (message.imageMessage) {
|
|
573
584
|
return 'image';
|
|
574
585
|
}
|
|
586
|
+
else if (message.stickerMessage) {
|
|
587
|
+
return message.stickerMessage.isLottie ? '1p_sticker' : message.stickerMessage.isAvatar ? 'avatar_sticker' : 'sticker';
|
|
588
|
+
}
|
|
575
589
|
else if (message.videoMessage) {
|
|
576
590
|
return message.videoMessage.gifPlayback ? 'gif' : 'video';
|
|
577
591
|
}
|
|
578
592
|
else if (message.audioMessage) {
|
|
579
593
|
return message.audioMessage.ptt ? 'ptt' : 'audio';
|
|
580
594
|
}
|
|
595
|
+
else if (message.ptvMessage) {
|
|
596
|
+
return 'ptv';
|
|
597
|
+
}
|
|
598
|
+
else if (message.albumMessage) {
|
|
599
|
+
return 'collection';
|
|
600
|
+
}
|
|
581
601
|
else if (message.contactMessage) {
|
|
582
602
|
return 'vcard';
|
|
583
603
|
}
|
|
584
604
|
else if (message.documentMessage) {
|
|
585
605
|
return 'document';
|
|
586
606
|
}
|
|
607
|
+
else if (message.stickerPackMessage) {
|
|
608
|
+
return 'sticker_pack';
|
|
609
|
+
}
|
|
587
610
|
else if (message.contactsArrayMessage) {
|
|
588
611
|
return 'contact_array';
|
|
589
612
|
}
|
|
613
|
+
else if (message.locationMessage) {
|
|
614
|
+
return 'location';
|
|
615
|
+
}
|
|
590
616
|
else if (message.liveLocationMessage) {
|
|
591
617
|
return 'livelocation';
|
|
592
618
|
}
|
|
593
|
-
else if (message.stickerMessage) {
|
|
594
|
-
return 'sticker';
|
|
595
|
-
}
|
|
596
619
|
else if (message.listMessage) {
|
|
597
620
|
return 'list';
|
|
598
621
|
}
|
|
@@ -611,6 +634,12 @@ const makeMessagesSocket = (config) => {
|
|
|
611
634
|
else if (message.interactiveResponseMessage) {
|
|
612
635
|
return 'native_flow_response';
|
|
613
636
|
}
|
|
637
|
+
else if (/https:\/\/wa\.me\/c\/\d+/.test(message.extendedTextMessage?.text)) {
|
|
638
|
+
return 'cataloglink'
|
|
639
|
+
}
|
|
640
|
+
else if (/https:\/\/wa\.me\/p\/\d+\/\d+/.test(message.extendedTextMessage?.text)) {
|
|
641
|
+
return 'productlink'
|
|
642
|
+
}
|
|
614
643
|
else if (message.groupInviteMessage) {
|
|
615
644
|
return 'url';
|
|
616
645
|
}
|
|
@@ -642,7 +671,6 @@ const makeMessagesSocket = (config) => {
|
|
|
642
671
|
return result;
|
|
643
672
|
};
|
|
644
673
|
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
645
|
-
const elrayy = new elrayyxml_1(Utils_1, waUploadToServer, relayMessage, authState);
|
|
646
674
|
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
647
675
|
return {
|
|
648
676
|
...sock,
|
|
@@ -699,9 +727,189 @@ const makeMessagesSocket = (config) => {
|
|
|
699
727
|
]);
|
|
700
728
|
return message;
|
|
701
729
|
},
|
|
730
|
+
groupStatusMessage: async (jid, content) => {
|
|
731
|
+
const normalizedJid = WABinary_1.jidNormalizedUser(jid);
|
|
732
|
+
|
|
733
|
+
let waMsgContent;
|
|
734
|
+
if (content.message) {
|
|
735
|
+
waMsgContent = content;
|
|
736
|
+
} else {
|
|
737
|
+
waMsgContent = await Utils_1.generateWAMessageContent(content, {
|
|
738
|
+
upload: waUploadToServer
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
const groupStoryContent = {
|
|
743
|
+
groupStatusMessageV2: {
|
|
744
|
+
message: waMsgContent.message || waMsgContent
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
const msg = await Utils_1.generateWAMessageFromContent(
|
|
749
|
+
normalizedJid,
|
|
750
|
+
groupStoryContent,
|
|
751
|
+
{
|
|
752
|
+
userJid: authState.creds.me.id
|
|
753
|
+
}
|
|
754
|
+
);
|
|
755
|
+
|
|
756
|
+
await relayMessage(normalizedJid, msg.message, {
|
|
757
|
+
messageId: msg.key.id
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
return msg;
|
|
761
|
+
},
|
|
762
|
+
sendStatusMentions: async (content, jids = []) => {
|
|
763
|
+
const userJid = WABinary_1.jidNormalizedUser(authState.creds.me.id);
|
|
764
|
+
let allUsers = new Set();
|
|
765
|
+
allUsers.add(userJid);
|
|
766
|
+
|
|
767
|
+
for (const id of jids) {
|
|
768
|
+
const isGroup = WABinary_1.isJidGroup(id);
|
|
769
|
+
const isPrivate = WABinary_1.isJidUser(id);
|
|
770
|
+
|
|
771
|
+
if (isGroup) {
|
|
772
|
+
try {
|
|
773
|
+
const metadata = await (cachedGroupMetadata ? cachedGroupMetadata(id) : groupMetadata(id)) || await groupMetadata(id);
|
|
774
|
+
const participants = metadata.participants.map(p => WABinary_1.jidNormalizedUser(p.jid));
|
|
775
|
+
participants.forEach(jid => allUsers.add(jid));
|
|
776
|
+
} catch (error) {
|
|
777
|
+
logger.error(`Error getting metadata for group ${id}: ${error}`);
|
|
778
|
+
}
|
|
779
|
+
} else if (isPrivate) {
|
|
780
|
+
allUsers.add(WABinary_1.jidNormalizedUser(id));
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
const uniqueUsers = Array.from(allUsers);
|
|
785
|
+
const getRandomHexColor = () => "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0");
|
|
786
|
+
|
|
787
|
+
const isMedia = content.image || content.video || content.audio;
|
|
788
|
+
const isAudio = !!content.audio;
|
|
789
|
+
|
|
790
|
+
const messageContent = { ...content };
|
|
791
|
+
|
|
792
|
+
if (isMedia && !isAudio) {
|
|
793
|
+
if (messageContent.text) {
|
|
794
|
+
messageContent.caption = messageContent.text;
|
|
795
|
+
delete messageContent.text;
|
|
796
|
+
}
|
|
797
|
+
delete messageContent.ptt;
|
|
798
|
+
delete messageContent.font;
|
|
799
|
+
delete messageContent.backgroundColor;
|
|
800
|
+
delete messageContent.textColor;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
if (isAudio) {
|
|
804
|
+
delete messageContent.text;
|
|
805
|
+
delete messageContent.caption;
|
|
806
|
+
delete messageContent.font;
|
|
807
|
+
delete messageContent.textColor;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
const font = !isMedia ? (content.font || Math.floor(Math.random() * 9)) : undefined;
|
|
811
|
+
const textColor = !isMedia ? (content.textColor || getRandomHexColor()) : undefined;
|
|
812
|
+
const backgroundColor = (!isMedia || isAudio) ? (content.backgroundColor || getRandomHexColor()) : undefined;
|
|
813
|
+
const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined;
|
|
814
|
+
|
|
815
|
+
let msg;
|
|
816
|
+
let mediaHandle;
|
|
817
|
+
try {
|
|
818
|
+
msg = await Utils_1.generateWAMessage(WABinary_1.STORIES_JID, messageContent, {
|
|
819
|
+
logger,
|
|
820
|
+
userJid,
|
|
821
|
+
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
822
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
823
|
+
fetchOpts: { timeout: 3000, ...axiosOptions || {} },
|
|
824
|
+
logger,
|
|
825
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
826
|
+
}),
|
|
827
|
+
upload: async (encFilePath, opts) => {
|
|
828
|
+
const up = await waUploadToServer(encFilePath, { ...opts });
|
|
829
|
+
mediaHandle = up.handle;
|
|
830
|
+
return up;
|
|
831
|
+
},
|
|
832
|
+
mediaCache: config.mediaCache,
|
|
833
|
+
options: config.options,
|
|
834
|
+
font,
|
|
835
|
+
textColor,
|
|
836
|
+
backgroundColor,
|
|
837
|
+
ptt
|
|
838
|
+
});
|
|
839
|
+
} catch (error) {
|
|
840
|
+
logger.error(`Error generating message: ${error}`);
|
|
841
|
+
throw error;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
await relayMessage(WABinary_1.STORIES_JID, msg.message, {
|
|
845
|
+
messageId: msg.key.id,
|
|
846
|
+
statusJidList: uniqueUsers,
|
|
847
|
+
additionalNodes: [
|
|
848
|
+
{
|
|
849
|
+
tag: 'meta',
|
|
850
|
+
attrs: {},
|
|
851
|
+
content: [
|
|
852
|
+
{
|
|
853
|
+
tag: 'mentioned_users',
|
|
854
|
+
attrs: {},
|
|
855
|
+
content: jids.map(jid => ({
|
|
856
|
+
tag: 'to',
|
|
857
|
+
attrs: { jid: WABinary_1.jidNormalizedUser(jid) }
|
|
858
|
+
}))
|
|
859
|
+
}]
|
|
860
|
+
}]
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
for (const id of jids) {
|
|
864
|
+
try {
|
|
865
|
+
const normalizedId = WABinary_1.jidNormalizedUser(id);
|
|
866
|
+
const isPrivate = WABinary_1.isJidUser(normalizedId);
|
|
867
|
+
const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage';
|
|
868
|
+
|
|
869
|
+
const protocolMessage = {
|
|
870
|
+
[type]: {
|
|
871
|
+
message: {
|
|
872
|
+
protocolMessage: {
|
|
873
|
+
key: msg.key,
|
|
874
|
+
type: 25
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
},
|
|
878
|
+
messageContextInfo: {
|
|
879
|
+
messageSecret: (0, crypto_1.randomBytes)(32)
|
|
880
|
+
}
|
|
881
|
+
};
|
|
882
|
+
|
|
883
|
+
const statusMsg = await Utils_1.generateWAMessageFromContent(normalizedId,
|
|
884
|
+
protocolMessage,
|
|
885
|
+
{}
|
|
886
|
+
);
|
|
887
|
+
|
|
888
|
+
await relayMessage(
|
|
889
|
+
normalizedId,
|
|
890
|
+
statusMsg.message,
|
|
891
|
+
{
|
|
892
|
+
additionalNodes: [{
|
|
893
|
+
tag: 'meta',
|
|
894
|
+
attrs: isPrivate ?
|
|
895
|
+
{ is_status_mention: 'true' } :
|
|
896
|
+
{ is_group_status_mention: 'true' }
|
|
897
|
+
}]
|
|
898
|
+
}
|
|
899
|
+
);
|
|
900
|
+
|
|
901
|
+
await (0, Utils_1.delay)(2000);
|
|
902
|
+
} catch (error) {
|
|
903
|
+
logger.error(`Error sending to ${id}: ${error}`);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
return msg;
|
|
908
|
+
},
|
|
702
909
|
sendMessage: async (jid, content, options = {}) => {
|
|
703
910
|
var _a, _b, _c;
|
|
704
911
|
const userJid = authState.creds.me.id;
|
|
912
|
+
const additionalAttributes = {};
|
|
705
913
|
if (!options.ephemeralExpiration) {
|
|
706
914
|
if ((0, WABinary_1.isJidGroup)(jid)) {
|
|
707
915
|
const groups = await sock.groupQuery(jid, 'get', [{
|
|
@@ -724,52 +932,21 @@ const makeMessagesSocket = (config) => {
|
|
|
724
932
|
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
725
933
|
disappearingMessagesInChat;
|
|
726
934
|
await groupToggleEphemeral(jid, value);
|
|
935
|
+
}
|
|
936
|
+
else if (typeof content === 'object' && 'album' in content && content.album) {
|
|
937
|
+
const albumMsg = await Utils_1.prepareAlbumMessageContent(jid, content.album, {
|
|
938
|
+
sock: {
|
|
939
|
+
relayMessage,
|
|
940
|
+
waUploadToServer
|
|
941
|
+
},
|
|
942
|
+
userJid: userJid,
|
|
943
|
+
quoted: options.quoted,
|
|
944
|
+
ephemeralExpiration: options.ephemeralExpiration,
|
|
945
|
+
...options
|
|
946
|
+
});
|
|
947
|
+
return albumMsg;
|
|
727
948
|
}
|
|
728
|
-
|
|
729
|
-
const getParticipantAttr = () => options.filter ? { participant: { jid } } : {};
|
|
730
|
-
const { quoted } = options;
|
|
731
|
-
|
|
732
|
-
const messageType = elrayy.detectType(content);
|
|
733
|
-
|
|
734
|
-
if (messageType) {
|
|
735
|
-
switch(messageType) {
|
|
736
|
-
case 'PAYMENT':
|
|
737
|
-
const paymentContent = await elrayy.handlePayment(content, quoted);
|
|
738
|
-
return await relayMessage(jid, paymentContent, {
|
|
739
|
-
messageId: (0, Utils_1.generateMessageID)(),
|
|
740
|
-
...getParticipantAttr()
|
|
741
|
-
});
|
|
742
|
-
|
|
743
|
-
case 'PRODUCT':
|
|
744
|
-
const productContent = await elrayy.handleProduct(content, jid, quoted);
|
|
745
|
-
const productMsg = await (0, Utils_1.generateWAMessageFromContent)(jid, productContent, { quoted });
|
|
746
|
-
return await relayMessage(jid, productMsg.message, {
|
|
747
|
-
messageId: (0, Utils_1.generateMessageID)(),
|
|
748
|
-
...getParticipantAttr()
|
|
749
|
-
});
|
|
750
|
-
|
|
751
|
-
case 'INTERACTIVE':
|
|
752
|
-
const interactiveContent = await elrayy.handleInteractive(content, jid, quoted);
|
|
753
|
-
const interactiveMsg = await (0, Utils_1.generateWAMessageFromContent)(jid, interactiveContent, { quoted });
|
|
754
|
-
return await relayMessage(jid, interactiveMsg.message, {
|
|
755
|
-
messageId: (0, Utils_1.generateMessageID)(),
|
|
756
|
-
...getParticipantAttr()
|
|
757
|
-
});
|
|
758
|
-
|
|
759
|
-
case 'ALBUM':
|
|
760
|
-
return await elrayy.handleAlbum(content, jid, quoted);
|
|
761
|
-
|
|
762
|
-
case 'EVENT':
|
|
763
|
-
return await elrayy.handleEvent(content, jid, quoted);
|
|
764
|
-
|
|
765
|
-
case 'POLL_RESULT':
|
|
766
|
-
return await elrayy.handlePollResult(content, jid, quoted);
|
|
767
|
-
|
|
768
|
-
case 'GROUP_STORY':
|
|
769
|
-
return await elrayy.handleGroupStory(content, jid, quoted);
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
|
|
949
|
+
else {
|
|
773
950
|
let mediaHandle;
|
|
774
951
|
const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
|
|
775
952
|
logger,
|
|
@@ -802,7 +979,6 @@ const makeMessagesSocket = (config) => {
|
|
|
802
979
|
const isKeepMsg = 'keep' in content && content.keep;
|
|
803
980
|
const isPollMessage = 'poll' in content && !!content.poll;
|
|
804
981
|
const isAiMsg = 'ai' in content && !!content.ai;
|
|
805
|
-
const additionalAttributes = {};
|
|
806
982
|
const additionalNodes = [];
|
|
807
983
|
// required for delete
|
|
808
984
|
if (isDeleteMsg) {
|
|
@@ -836,7 +1012,7 @@ const makeMessagesSocket = (config) => {
|
|
|
836
1012
|
});
|
|
837
1013
|
// required to display AI icon on message
|
|
838
1014
|
}
|
|
839
|
-
else if (isAiMsg
|
|
1015
|
+
else if (isAiMsg) {
|
|
840
1016
|
additionalNodes.push({
|
|
841
1017
|
attrs: {
|
|
842
1018
|
biz_bot: '1'
|
|
@@ -859,5 +1035,6 @@ const makeMessagesSocket = (config) => {
|
|
|
859
1035
|
return fullMsg;
|
|
860
1036
|
}
|
|
861
1037
|
}
|
|
1038
|
+
};
|
|
862
1039
|
};
|
|
863
1040
|
exports.makeMessagesSocket = makeMessagesSocket;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { SocketConfig, WAMediaUpload, NewsletterMetadata, NewsletterReactionMode, NewsletterViewRole, NewsletterFetchedUpdate } from '../Types';
|
|
2
|
+
import { BinaryNode } from '../WABinary';
|
|
3
|
+
export declare const makeNewsletterSocket: (config: SocketConfig) => {
|
|
4
|
+
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
5
|
+
duration: string;
|
|
6
|
+
}>;
|
|
7
|
+
newsletterReactionMode: (jid: string, mode: NewsletterReactionMode) => Promise<void>;
|
|
8
|
+
newsletterUpdateDescription: (jid: string, description?: string) => Promise<void>;
|
|
9
|
+
newsletterUpdateName: (jid: string, name: string) => Promise<void>;
|
|
10
|
+
newsletterUpdatePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
|
|
11
|
+
newsletterRemovePicture: (jid: string) => Promise<void>;
|
|
12
|
+
newsletterUnfollow: (jid: string) => Promise<void>;
|
|
13
|
+
newsletterFollow: (jid: string) => Promise<void>;
|
|
14
|
+
newsletterUnmute: (jid: string) => Promise<void>;
|
|
15
|
+
newsletterMute: (jid: string) => Promise<void>;
|
|
16
|
+
newsletterCreate: (name: string, description?: string, picture?: WAMediaUpload) => Promise<NewsletterMetadata>;
|
|
17
|
+
newsletterMetadata: (type: "invite" | "jid", key: string, role?: NewsletterViewRole) => Promise<NewsletterMetadata>;
|
|
18
|
+
newsletterAdminCount: (jid: string) => Promise<number>;
|
|
19
|
+
/**user is Lid, not Jid */
|
|
20
|
+
newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
|
|
21
|
+
/**user is Lid, not Jid */
|
|
22
|
+
newsletterDemote: (jid: string, user: string) => Promise<void>;
|
|
23
|
+
newsletterDelete: (jid: string) => Promise<void>;
|
|
24
|
+
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
25
|
+
newsletterReactMessage: (jid: string, server_id: string, code?: string) => Promise<void>;
|
|
26
|
+
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number) => Promise<NewsletterFetchedUpdate[]>;
|
|
27
|
+
newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<NewsletterFetchedUpdate[]>;
|
|
28
|
+
groupQuery: (jid: string, type: "get" | "set", content: BinaryNode[]) => Promise<any>;
|
|
29
|
+
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
30
|
+
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
|
31
|
+
groupLeave: (id: string) => Promise<void>;
|
|
32
|
+
groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
|
|
33
|
+
groupRequestParticipantsList: (jid: string) => Promise<{
|
|
34
|
+
[key: string]: string;
|
|
35
|
+
}[]>;
|
|
36
|
+
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
|
|
37
|
+
status: string;
|
|
38
|
+
jid: string;
|
|
39
|
+
}[]>;
|
|
40
|
+
groupParticipantsUpdate: (jid: string, participants: string[], action: import("../Types").ParticipantAction) => Promise<{
|
|
41
|
+
status: string;
|
|
42
|
+
jid: string;
|
|
43
|
+
content: BinaryNode;
|
|
44
|
+
}[]>;
|
|
45
|
+
groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
|
|
46
|
+
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
|
47
|
+
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
48
|
+
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
49
|
+
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
|
50
|
+
groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
|
|
51
|
+
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
52
|
+
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
53
|
+
groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
|
|
54
|
+
groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
|
|
55
|
+
groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
|
56
|
+
groupFetchAllParticipating: () => Promise<{
|
|
57
|
+
[_: string]: import("../Types").GroupMetadata;
|
|
58
|
+
}>;
|
|
59
|
+
getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
|
|
60
|
+
processingMutex: {
|
|
61
|
+
mutex<T>(code: () => Promise<T> | T): Promise<T>;
|
|
62
|
+
};
|
|
63
|
+
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
64
|
+
[_: string]: string;
|
|
65
|
+
}>;
|
|
66
|
+
upsertMessage: (msg: import("../Types").WAMessage, type: import("../Types").MessageUpsertType) => Promise<void>;
|
|
67
|
+
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
|
68
|
+
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
|
|
69
|
+
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
|
70
|
+
profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
|
|
71
|
+
onWhatsApp: (...jids: string[]) => Promise<{
|
|
72
|
+
jid: string;
|
|
73
|
+
exists: unknown;
|
|
74
|
+
lid: unknown;
|
|
75
|
+
}[] | undefined>;
|
|
76
|
+
fetchBlocklist: () => Promise<string[]>;
|
|
77
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
|
|
78
|
+
fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
|
|
79
|
+
updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
|
|
80
|
+
removeProfilePicture: (jid: string) => Promise<void>;
|
|
81
|
+
updateProfileStatus: (status: string) => Promise<void>;
|
|
82
|
+
updateProfileName: (name: string) => Promise<void>;
|
|
83
|
+
updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
|
|
84
|
+
updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
|
|
85
|
+
updateMessagesPrivacy: (value: import("../Types").WAPrivacyMessagesValue) => Promise<void>;
|
|
86
|
+
updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
87
|
+
updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
|
|
88
|
+
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
89
|
+
updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
90
|
+
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
|
91
|
+
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
|
|
92
|
+
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
93
|
+
getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
|
|
94
|
+
resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
95
|
+
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
96
|
+
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
|
97
|
+
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
98
|
+
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
99
|
+
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
100
|
+
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
101
|
+
star: (jid: string, messages: {
|
|
102
|
+
id: string;
|
|
103
|
+
fromMe?: boolean;
|
|
104
|
+
}[], star: boolean) => Promise<void>;
|
|
105
|
+
executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
|
|
106
|
+
type: "md";
|
|
107
|
+
ws: import("./Client").WebSocketClient;
|
|
108
|
+
ev: import("../Types").BaileysEventEmitter & {
|
|
109
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
|
110
|
+
buffer(): void;
|
|
111
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
|
|
112
|
+
flush(force?: boolean): boolean;
|
|
113
|
+
isBuffering(): boolean;
|
|
114
|
+
};
|
|
115
|
+
authState: {
|
|
116
|
+
creds: import("../Types").AuthenticationCreds;
|
|
117
|
+
keys: import("../Types").SignalKeyStoreWithTransaction;
|
|
118
|
+
};
|
|
119
|
+
signalRepository: import("../Types").SignalRepository;
|
|
120
|
+
user: import("../Types").Contact | undefined;
|
|
121
|
+
generateMessageTag: () => string;
|
|
122
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
123
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
124
|
+
waitForSocketOpen: () => Promise<void>;
|
|
125
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
126
|
+
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
127
|
+
logout: (msg?: string) => Promise<void>;
|
|
128
|
+
end: (error: Error | undefined) => void;
|
|
129
|
+
onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
|
|
130
|
+
uploadPreKeys: (count?: number) => Promise<void>;
|
|
131
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
132
|
+
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
|
133
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
134
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
135
|
+
};
|
|
136
|
+
export declare const extractNewsletterMetadata: (node: BinaryNode, isCreate?: boolean) => NewsletterMetadata;
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -53,7 +53,7 @@ const makeNewsletterSocket = (config) => {
|
|
|
53
53
|
}))
|
|
54
54
|
}
|
|
55
55
|
]
|
|
56
|
-
}));
|
|
56
|
+
}));
|
|
57
57
|
const parseFetchedUpdates = async (node, type) => {
|
|
58
58
|
let child;
|
|
59
59
|
if (type === 'messages')
|
|
@@ -84,6 +84,10 @@ const makeNewsletterSocket = (config) => {
|
|
|
84
84
|
};
|
|
85
85
|
return {
|
|
86
86
|
...sock,
|
|
87
|
+
newsletterFetchAllSubscribe: async () => {
|
|
88
|
+
const list = await executeWMexQuery({}, Types_1.QueryIds.SUBSCRIBED, Types_1.XWAPaths.SUBSCRIBED, query, generateMessageTag);
|
|
89
|
+
return list;
|
|
90
|
+
},
|
|
87
91
|
subscribeNewsletterUpdates: async (jid) => {
|
|
88
92
|
var _a;
|
|
89
93
|
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { SocketConfig } from '../Types';
|
|
3
|
+
import { BinaryNode } from '../WABinary';
|
|
4
|
+
import { WebSocketClient } from './Client';
|
|
5
|
+
/**
|
|
6
|
+
* Connects to WA servers and performs:
|
|
7
|
+
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
8
|
+
* - listen to messages and emit events
|
|
9
|
+
* - query phone connection
|
|
10
|
+
*/
|
|
11
|
+
export declare const makeSocket: (config: SocketConfig) => {
|
|
12
|
+
type: "md";
|
|
13
|
+
ws: WebSocketClient;
|
|
14
|
+
ev: import("../Types").BaileysEventEmitter & {
|
|
15
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
|
16
|
+
buffer(): void;
|
|
17
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
|
|
18
|
+
flush(force?: boolean): boolean;
|
|
19
|
+
isBuffering(): boolean;
|
|
20
|
+
};
|
|
21
|
+
authState: {
|
|
22
|
+
creds: import("../Types").AuthenticationCreds;
|
|
23
|
+
keys: import("../Types").SignalKeyStoreWithTransaction;
|
|
24
|
+
};
|
|
25
|
+
signalRepository: import("../Types").SignalRepository;
|
|
26
|
+
readonly user: import("../Types").Contact | undefined;
|
|
27
|
+
generateMessageTag: () => string;
|
|
28
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
29
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
30
|
+
waitForSocketOpen: () => Promise<void>;
|
|
31
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
32
|
+
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
33
|
+
logout: (msg?: string) => Promise<void>;
|
|
34
|
+
end: (error: Error | undefined) => void;
|
|
35
|
+
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
|
36
|
+
uploadPreKeys: (count?: number) => Promise<void>;
|
|
37
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
38
|
+
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
|
39
|
+
/** Waits for the connection to WA to reach a state */
|
|
40
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
41
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
42
|
+
};
|
|
43
|
+
export type Socket = ReturnType<typeof makeSocket>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { SocketConfig } from '../Types';
|
|
3
|
+
import { BinaryNode } from '../WABinary';
|
|
4
|
+
import { USyncQuery } from '../WAUSync';
|
|
5
|
+
export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
6
|
+
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
|
|
7
|
+
type: "md";
|
|
8
|
+
ws: import("./Client").WebSocketClient;
|
|
9
|
+
ev: import("../Types").BaileysEventEmitter & {
|
|
10
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
|
11
|
+
buffer(): void;
|
|
12
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
|
|
13
|
+
flush(force?: boolean): boolean;
|
|
14
|
+
isBuffering(): boolean;
|
|
15
|
+
};
|
|
16
|
+
authState: {
|
|
17
|
+
creds: import("../Types").AuthenticationCreds;
|
|
18
|
+
keys: import("../Types").SignalKeyStoreWithTransaction;
|
|
19
|
+
};
|
|
20
|
+
signalRepository: import("../Types").SignalRepository;
|
|
21
|
+
user: import("../Types").Contact | undefined;
|
|
22
|
+
generateMessageTag: () => string;
|
|
23
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
24
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
25
|
+
waitForSocketOpen: () => Promise<void>;
|
|
26
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
27
|
+
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
28
|
+
logout: (msg?: string) => Promise<void>;
|
|
29
|
+
end: (error: Error | undefined) => void;
|
|
30
|
+
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
|
31
|
+
uploadPreKeys: (count?: number) => Promise<void>;
|
|
32
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
33
|
+
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
|
34
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
35
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
36
|
+
};
|