gifted-baileys 1.5.5 → 1.5.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 +6 -1642
- package/WAProto/WAProto.proto +969 -88
- package/WAProto/index.d.ts +13199 -1260
- package/WAProto/index.js +124901 -74525
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +284 -0
- package/{src → lib}/Defaults/index.js +7 -14
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +161 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/{src → lib}/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.d.ts +17 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +62 -0
- package/lib/Socket/business.d.ts +170 -0
- package/{src → lib}/Socket/business.js +28 -33
- package/lib/Socket/chats.d.ts +81 -0
- package/{src → lib}/Socket/chats.js +174 -176
- package/lib/Socket/groups.d.ts +115 -0
- package/{src → lib}/Socket/groups.js +80 -68
- package/lib/Socket/index.d.ts +172 -0
- package/{src → lib}/Socket/index.js +4 -1
- package/lib/Socket/messages-recv.d.ts +158 -0
- package/{src → lib}/Socket/messages-recv.js +378 -211
- package/lib/Socket/messages-send.d.ts +155 -0
- package/{src → lib}/Socket/messages-send.js +452 -177
- package/lib/Socket/newsletter.d.ts +132 -0
- package/{src → lib}/Socket/newsletter.js +107 -98
- package/lib/Socket/registration.d.ts +264 -0
- package/{src → lib}/Socket/registration.js +56 -48
- package/lib/Socket/socket.d.ts +44 -0
- package/{src → lib}/Socket/socket.js +77 -77
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/{src → lib}/Store/make-cache-manager-store.js +25 -34
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/{src → lib}/Store/make-in-memory-store.js +36 -32
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/{src → lib}/Store/object-repository.js +1 -1
- package/lib/Types/Auth.d.ts +109 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Chat.d.ts +107 -0
- package/{src/Types/Contact.ts → lib/Types/Contact.d.ts} +8 -9
- package/lib/Types/Events.d.ts +172 -0
- package/lib/Types/GroupMetadata.d.ts +56 -0
- package/lib/Types/Label.d.ts +46 -0
- package/{src/Types/LabelAssociation.ts → lib/Types/LabelAssociation.d.ts} +16 -22
- package/lib/Types/Message.d.ts +433 -0
- package/lib/Types/Newsletter.d.ts +92 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/{src/Types/Socket.ts → lib/Types/Socket.d.ts} +61 -68
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/{src → lib}/Utils/auth-utils.js +73 -90
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +22 -0
- package/{src → lib}/Utils/business.js +15 -43
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/{src → lib}/Utils/chat-utils.js +87 -94
- package/lib/Utils/crypto.d.ts +40 -0
- package/{src → lib}/Utils/crypto.js +4 -2
- package/lib/Utils/decode-wa-message.d.ts +36 -0
- package/lib/Utils/decode-wa-message.js +226 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/{src → lib}/Utils/event-buffer.js +4 -13
- package/lib/Utils/generics.d.ts +88 -0
- package/{src → lib}/Utils/generics.js +67 -86
- package/lib/Utils/history.d.ts +19 -0
- package/{src → lib}/Utils/history.js +13 -39
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/{src → lib}/Utils/link-preview.js +17 -54
- package/lib/Utils/logger.d.ts +2 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/{src → lib}/Utils/make-mutex.js +4 -13
- package/lib/Utils/messages-media.d.ts +113 -0
- package/{src → lib}/Utils/messages-media.js +193 -255
- package/lib/Utils/messages.d.ts +77 -0
- package/{src → lib}/Utils/messages.js +588 -118
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/{src → lib}/Utils/process-message.js +27 -30
- package/lib/Utils/signal.d.ts +33 -0
- package/{src → lib}/Utils/signal.js +25 -42
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/{src → lib}/Utils/use-multi-file-auth-state.js +27 -28
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/{src → lib}/Utils/validate-connection.js +40 -9
- 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/{src → lib}/WABinary/encode.js +16 -10
- package/lib/WABinary/generic-utils.d.ts +14 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -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/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.d.ts +26 -0
- package/lib/WAUSync/USyncQuery.js +79 -0
- package/lib/WAUSync/USyncUser.d.ts +10 -0
- package/lib/WAUSync/USyncUser.js +22 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/{src → lib}/index.js +1 -0
- package/package.json +26 -8
- package/LICENSE +0 -21
- package/src/Defaults/baileys-version.json +0 -3
- package/src/Defaults/index.ts +0 -131
- package/src/Signal/libsignal.js +0 -180
- package/src/Signal/libsignal.ts +0 -141
- package/src/Socket/Client/abstract-socket-client.ts +0 -19
- package/src/Socket/Client/index.ts +0 -3
- package/src/Socket/Client/mobile-socket-client.js +0 -78
- package/src/Socket/Client/mobile-socket-client.ts +0 -66
- package/src/Socket/Client/web-socket-client.js +0 -75
- package/src/Socket/Client/web-socket-client.ts +0 -57
- package/src/Socket/business.ts +0 -281
- package/src/Socket/chats.ts +0 -1030
- package/src/Socket/groups.ts +0 -356
- package/src/Socket/index.ts +0 -13
- package/src/Socket/messages-recv.ts +0 -985
- package/src/Socket/messages-send.ts +0 -871
- package/src/Socket/newsletter.ts +0 -282
- package/src/Socket/registration.ts +0 -250
- package/src/Socket/socket.ts +0 -777
- package/src/Store/index.ts +0 -3
- package/src/Store/make-cache-manager-store.ts +0 -100
- package/src/Store/make-in-memory-store.ts +0 -475
- package/src/Store/make-ordered-dictionary.ts +0 -86
- package/src/Store/object-repository.ts +0 -32
- package/src/Tests/test.app-state-sync.js +0 -204
- package/src/Tests/test.app-state-sync.ts +0 -207
- package/src/Tests/test.event-buffer.js +0 -270
- package/src/Tests/test.event-buffer.ts +0 -319
- package/src/Tests/test.key-store.js +0 -76
- package/src/Tests/test.key-store.ts +0 -92
- package/src/Tests/test.libsignal.js +0 -141
- package/src/Tests/test.libsignal.ts +0 -186
- package/src/Tests/test.media-download.js +0 -93
- package/src/Tests/test.media-download.ts +0 -76
- package/src/Tests/test.messages.js +0 -33
- package/src/Tests/test.messages.ts +0 -37
- package/src/Tests/utils.js +0 -34
- package/src/Tests/utils.ts +0 -36
- package/src/Types/Auth.ts +0 -113
- package/src/Types/Call.ts +0 -15
- package/src/Types/Chat.ts +0 -106
- package/src/Types/Events.ts +0 -93
- package/src/Types/GroupMetadata.ts +0 -53
- package/src/Types/Label.ts +0 -36
- package/src/Types/Message.ts +0 -288
- package/src/Types/Newsletter.ts +0 -98
- package/src/Types/Product.ts +0 -85
- package/src/Types/Signal.ts +0 -68
- package/src/Types/State.ts +0 -29
- package/src/Types/index.ts +0 -59
- package/src/Utils/auth-utils.ts +0 -222
- package/src/Utils/baileys-event-stream.js +0 -92
- package/src/Utils/baileys-event-stream.ts +0 -66
- package/src/Utils/business.ts +0 -275
- package/src/Utils/chat-utils.ts +0 -860
- package/src/Utils/crypto.ts +0 -131
- package/src/Utils/decode-wa-message.js +0 -211
- package/src/Utils/decode-wa-message.ts +0 -228
- package/src/Utils/event-buffer.ts +0 -613
- package/src/Utils/generics.ts +0 -434
- package/src/Utils/history.ts +0 -112
- package/src/Utils/index.ts +0 -17
- package/src/Utils/link-preview.ts +0 -122
- package/src/Utils/logger.ts +0 -3
- package/src/Utils/lt-hash.ts +0 -61
- package/src/Utils/make-mutex.ts +0 -44
- package/src/Utils/messages-media.ts +0 -847
- package/src/Utils/messages.ts +0 -956
- package/src/Utils/noise-handler.ts +0 -197
- package/src/Utils/process-message.ts +0 -414
- package/src/Utils/signal.ts +0 -177
- package/src/Utils/use-multi-file-auth-state.ts +0 -90
- package/src/Utils/validate-connection.ts +0 -238
- package/src/WABinary/constants.ts +0 -42
- package/src/WABinary/decode.ts +0 -265
- package/src/WABinary/encode.ts +0 -236
- package/src/WABinary/generic-utils.ts +0 -121
- package/src/WABinary/index.ts +0 -5
- package/src/WABinary/jid-utils.ts +0 -68
- package/src/WABinary/types.ts +0 -17
- package/src/WAM/BinaryInfo.ts +0 -12
- package/src/WAM/constants.ts +0 -15382
- package/src/WAM/encode.ts +0 -174
- package/src/WAM/index.ts +0 -3
- package/src/gifted +0 -1
- package/src/index.ts +0 -13
- /package/{src → lib}/Defaults/phonenumber-mcc.json +0 -0
- /package/{src → lib}/Socket/Client/abstract-socket-client.js +0 -0
- /package/{src → lib}/Store/index.js +0 -0
- /package/{src → lib}/Store/make-ordered-dictionary.js +0 -0
- /package/{src → lib}/Types/Auth.js +0 -0
- /package/{src → lib}/Types/Call.js +0 -0
- /package/{src → lib}/Types/Chat.js +0 -0
- /package/{src → lib}/Types/Contact.js +0 -0
- /package/{src → lib}/Types/Events.js +0 -0
- /package/{src → lib}/Types/GroupMetadata.js +0 -0
- /package/{src → lib}/Types/Label.js +0 -0
- /package/{src → lib}/Types/LabelAssociation.js +0 -0
- /package/{src → lib}/Types/Message.js +0 -0
- /package/{src → lib}/Types/Newsletter.js +0 -0
- /package/{src → lib}/Types/Product.js +0 -0
- /package/{src → lib}/Types/Signal.js +0 -0
- /package/{src → lib}/Types/Socket.js +0 -0
- /package/{src → lib}/Types/State.js +0 -0
- /package/{src/WABinary/types.js → lib/Types/USync.js} +0 -0
- /package/{src → lib}/Types/index.js +0 -0
- /package/{src → lib}/Utils/index.js +0 -0
- /package/{src → lib}/Utils/logger.js +0 -0
- /package/{src → lib}/Utils/lt-hash.js +0 -0
- /package/{src → lib}/Utils/noise-handler.js +0 -0
- /package/{src → lib}/WABinary/constants.js +0 -0
- /package/{src → lib}/WABinary/decode.js +0 -0
- /package/{src → lib}/WABinary/generic-utils.js +0 -0
- /package/{src → lib}/WABinary/index.js +0 -0
- /package/{src → lib}/WABinary/jid-utils.js +0 -0
- /package/{src → lib}/WAM/BinaryInfo.js +0 -0
- /package/{src → lib}/WAM/constants.js +0 -0
- /package/{src → lib}/WAM/encode.js +0 -0
- /package/{src → lib}/WAM/index.js +0 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decryptMessageNode = exports.NACK_REASONS = exports.MISSING_KEYS_ERROR_TEXT = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
|
|
4
|
+
exports.decodeMessageNode = decodeMessageNode;
|
|
5
|
+
const boom_1 = require("@hapi/boom");
|
|
6
|
+
const WAProto_1 = require("../../WAProto");
|
|
7
|
+
const WABinary_1 = require("../WABinary");
|
|
8
|
+
const generics_1 = require("./generics");
|
|
9
|
+
exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
|
10
|
+
exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
|
|
11
|
+
exports.NACK_REASONS = {
|
|
12
|
+
ParsingError: 487,
|
|
13
|
+
UnrecognizedStanza: 488,
|
|
14
|
+
UnrecognizedStanzaClass: 489,
|
|
15
|
+
UnrecognizedStanzaType: 490,
|
|
16
|
+
InvalidProtobuf: 491,
|
|
17
|
+
InvalidHostedCompanionStanza: 493,
|
|
18
|
+
MissingMessageSecret: 495,
|
|
19
|
+
SignalErrorOldCounter: 496,
|
|
20
|
+
MessageDeletedOnPeer: 499,
|
|
21
|
+
UnhandledError: 500,
|
|
22
|
+
UnsupportedAdminRevoke: 550,
|
|
23
|
+
UnsupportedLIDGroup: 551,
|
|
24
|
+
DBOperationFailed: 552
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Decode the received node as a message.
|
|
28
|
+
* @note this will only parse the message, not decrypt it
|
|
29
|
+
*/
|
|
30
|
+
function decodeMessageNode(stanza, meId, meLid) {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
let msgType;
|
|
33
|
+
let chatId;
|
|
34
|
+
let author;
|
|
35
|
+
const msgId = stanza.attrs.id;
|
|
36
|
+
const from = stanza.attrs.from;
|
|
37
|
+
const participant = stanza.attrs.participant;
|
|
38
|
+
const recipient = stanza.attrs.recipient;
|
|
39
|
+
const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
|
|
40
|
+
const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
|
|
41
|
+
if ((0, WABinary_1.isJidUser)(from)) {
|
|
42
|
+
if (recipient) {
|
|
43
|
+
if (!isMe(from)) {
|
|
44
|
+
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
|
45
|
+
}
|
|
46
|
+
chatId = recipient;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
chatId = from;
|
|
50
|
+
}
|
|
51
|
+
msgType = 'chat';
|
|
52
|
+
author = from;
|
|
53
|
+
}
|
|
54
|
+
else if ((0, WABinary_1.isLidUser)(from)) {
|
|
55
|
+
if (recipient) {
|
|
56
|
+
if (!isMeLid(from)) {
|
|
57
|
+
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
|
58
|
+
}
|
|
59
|
+
chatId = recipient;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
chatId = from;
|
|
63
|
+
}
|
|
64
|
+
msgType = 'chat';
|
|
65
|
+
author = from;
|
|
66
|
+
}
|
|
67
|
+
else if ((0, WABinary_1.isJidGroup)(from)) {
|
|
68
|
+
if (!participant) {
|
|
69
|
+
throw new boom_1.Boom('No participant in group message');
|
|
70
|
+
}
|
|
71
|
+
msgType = 'group';
|
|
72
|
+
author = participant;
|
|
73
|
+
chatId = from;
|
|
74
|
+
}
|
|
75
|
+
else if ((0, WABinary_1.isJidBroadcast)(from)) {
|
|
76
|
+
if (!participant) {
|
|
77
|
+
throw new boom_1.Boom('No participant in group message');
|
|
78
|
+
}
|
|
79
|
+
const isParticipantMe = isMe(participant);
|
|
80
|
+
if ((0, WABinary_1.isJidStatusBroadcast)(from)) {
|
|
81
|
+
msgType = isParticipantMe ? 'direct_peer_status' : 'other_status';
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast';
|
|
85
|
+
}
|
|
86
|
+
chatId = from;
|
|
87
|
+
author = participant;
|
|
88
|
+
}
|
|
89
|
+
else if ((0, WABinary_1.isJidNewsLetter)(from)) {
|
|
90
|
+
msgType = 'newsletter';
|
|
91
|
+
author = from;
|
|
92
|
+
chatId = from;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
throw new boom_1.Boom('Unknown message type', { data: stanza });
|
|
96
|
+
}
|
|
97
|
+
const fromMe = (0, WABinary_1.isJidNewsLetter)(from) ? !!((_a = stanza.attrs) === null || _a === void 0 ? void 0 : _a.is_sender) : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
|
|
98
|
+
const pushname = stanza.attrs.notify;
|
|
99
|
+
const key = {
|
|
100
|
+
remoteJid: chatId,
|
|
101
|
+
fromMe,
|
|
102
|
+
id: msgId,
|
|
103
|
+
participant
|
|
104
|
+
};
|
|
105
|
+
const fullMessage = {
|
|
106
|
+
key,
|
|
107
|
+
messageTimestamp: +stanza.attrs.t,
|
|
108
|
+
pushName: pushname,
|
|
109
|
+
broadcast: (0, WABinary_1.isJidBroadcast)(from)
|
|
110
|
+
};
|
|
111
|
+
if (msgType === 'newsletter') {
|
|
112
|
+
fullMessage.newsletterServerId = +((_b = stanza.attrs) === null || _b === void 0 ? void 0 : _b.server_id);
|
|
113
|
+
}
|
|
114
|
+
if (key.fromMe) {
|
|
115
|
+
fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK;
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
fullMessage,
|
|
119
|
+
author,
|
|
120
|
+
sender: msgType === 'chat' ? author : chatId
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
124
|
+
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
|
|
125
|
+
return {
|
|
126
|
+
fullMessage,
|
|
127
|
+
category: stanza.attrs.category,
|
|
128
|
+
author,
|
|
129
|
+
async decrypt() {
|
|
130
|
+
var _a;
|
|
131
|
+
let decryptables = 0;
|
|
132
|
+
if ((0, WABinary_1.isJidNewsLetter)(fullMessage.key.remoteJid)) {
|
|
133
|
+
const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
|
|
134
|
+
const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
|
|
135
|
+
if (msg.senderKeyDistributionMessage) {
|
|
136
|
+
//eslint-disable-next-line max-depth
|
|
137
|
+
try {
|
|
138
|
+
await repository.processSenderKeyDistributionMessage({
|
|
139
|
+
authorJid: author,
|
|
140
|
+
item: msg.senderKeyDistributionMessage
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
fullMessage.message = msg;
|
|
148
|
+
decryptables += 1;
|
|
149
|
+
}
|
|
150
|
+
else if (Array.isArray(stanza.content)) {
|
|
151
|
+
for (const { tag, attrs, content } of stanza.content) {
|
|
152
|
+
if (tag === 'verified_name' && content instanceof Uint8Array) {
|
|
153
|
+
const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content);
|
|
154
|
+
const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
155
|
+
fullMessage.verifiedBizName = details.verifiedName;
|
|
156
|
+
}
|
|
157
|
+
if (tag !== 'enc' && tag !== 'plaintext') {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (!(content instanceof Uint8Array)) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
decryptables += 1;
|
|
164
|
+
let msgBuffer;
|
|
165
|
+
try {
|
|
166
|
+
const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type;
|
|
167
|
+
switch (e2eType) {
|
|
168
|
+
case 'skmsg':
|
|
169
|
+
msgBuffer = await repository.decryptGroupMessage({
|
|
170
|
+
group: sender,
|
|
171
|
+
authorJid: author,
|
|
172
|
+
msg: content
|
|
173
|
+
});
|
|
174
|
+
break;
|
|
175
|
+
case 'pkmsg':
|
|
176
|
+
case 'msg':
|
|
177
|
+
const user = (0, WABinary_1.isJidUser)(sender) ? sender : author;
|
|
178
|
+
msgBuffer = await repository.decryptMessage({
|
|
179
|
+
jid: user,
|
|
180
|
+
type: e2eType,
|
|
181
|
+
ciphertext: content
|
|
182
|
+
});
|
|
183
|
+
break;
|
|
184
|
+
case 'plaintext':
|
|
185
|
+
msgBuffer = content;
|
|
186
|
+
break;
|
|
187
|
+
default:
|
|
188
|
+
throw new Error(`Unknown e2e type: ${e2eType}`);
|
|
189
|
+
}
|
|
190
|
+
let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
|
|
191
|
+
msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
|
|
192
|
+
if (msg.senderKeyDistributionMessage) {
|
|
193
|
+
//eslint-disable-next-line max-depth
|
|
194
|
+
try {
|
|
195
|
+
await repository.processSenderKeyDistributionMessage({
|
|
196
|
+
authorJid: author,
|
|
197
|
+
item: msg.senderKeyDistributionMessage
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (fullMessage.message) {
|
|
205
|
+
Object.assign(fullMessage.message, msg);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
fullMessage.message = msg;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
|
|
213
|
+
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
214
|
+
fullMessage.messageStubParameters = [err.message];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// if nothing was found to decrypt
|
|
219
|
+
if (!decryptables) {
|
|
220
|
+
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
221
|
+
fullMessage.messageStubParameters = [exports.NO_MESSAGE_FOUND_ERROR_TEXT];
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
exports.decryptMessageNode = decryptMessageNode;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Logger } from 'pino';
|
|
2
|
+
import { BaileysEventEmitter, BaileysEventMap } from '../Types';
|
|
3
|
+
/**
|
|
4
|
+
* A map that contains a list of all events that have been triggered
|
|
5
|
+
*
|
|
6
|
+
* Note, this can contain different type of events
|
|
7
|
+
* this can make processing events extremely efficient -- since everything
|
|
8
|
+
* can be done in a single transaction
|
|
9
|
+
*/
|
|
10
|
+
type BaileysEventData = Partial<BaileysEventMap>;
|
|
11
|
+
type BaileysBufferableEventEmitter = BaileysEventEmitter & {
|
|
12
|
+
/** Use to process events in a batch */
|
|
13
|
+
process(handler: (events: BaileysEventData) => void | Promise<void>): (() => void);
|
|
14
|
+
/**
|
|
15
|
+
* starts buffering events, call flush() to release them
|
|
16
|
+
* */
|
|
17
|
+
buffer(): void;
|
|
18
|
+
/** buffers all events till the promise completes */
|
|
19
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
|
|
20
|
+
/**
|
|
21
|
+
* flushes all buffered events
|
|
22
|
+
* @param force if true, will flush all data regardless of any pending buffers
|
|
23
|
+
* @returns returns true if the flush actually happened, otherwise false
|
|
24
|
+
*/
|
|
25
|
+
flush(force?: boolean): boolean;
|
|
26
|
+
/** is there an ongoing buffer */
|
|
27
|
+
isBuffering(): boolean;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The event buffer logically consolidates different events into a single event
|
|
31
|
+
* making the data processing more efficient.
|
|
32
|
+
* @param ev the baileys event emitter
|
|
33
|
+
*/
|
|
34
|
+
export declare const makeEventBuffer: (logger: Logger) => BaileysBufferableEventEmitter;
|
|
35
|
+
export {};
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -108,16 +99,16 @@ const makeEventBuffer = (logger) => {
|
|
|
108
99
|
buffer,
|
|
109
100
|
flush,
|
|
110
101
|
createBufferedFunction(work) {
|
|
111
|
-
return (...args) =>
|
|
102
|
+
return async (...args) => {
|
|
112
103
|
buffer();
|
|
113
104
|
try {
|
|
114
|
-
const result =
|
|
105
|
+
const result = await work(...args);
|
|
115
106
|
return result;
|
|
116
107
|
}
|
|
117
108
|
finally {
|
|
118
109
|
flush();
|
|
119
110
|
}
|
|
120
|
-
}
|
|
111
|
+
};
|
|
121
112
|
},
|
|
122
113
|
on: (...args) => ev.on(...args),
|
|
123
114
|
off: (...args) => ev.off(...args),
|
|
@@ -513,7 +504,7 @@ function concatChats(a, b) {
|
|
|
513
504
|
}
|
|
514
505
|
}
|
|
515
506
|
if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
|
|
516
|
-
b =
|
|
507
|
+
b = { ...b };
|
|
517
508
|
if (b.unreadCount >= 0) {
|
|
518
509
|
b.unreadCount = Math.max(b.unreadCount, 0) + Math.max(a.unreadCount, 0);
|
|
519
510
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { Logger } from 'pino';
|
|
3
|
+
import { proto } from '../../WAProto';
|
|
4
|
+
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, WACallUpdateType, WAVersion } from '../Types';
|
|
5
|
+
import { BinaryNode } from '../WABinary';
|
|
6
|
+
export declare const Browsers: BrowsersMap;
|
|
7
|
+
export declare const getPlatformId: (browser: string) => any;
|
|
8
|
+
export declare const BufferJSON: {
|
|
9
|
+
replacer: (k: any, value: any) => any;
|
|
10
|
+
reviver: (_: any, value: any) => any;
|
|
11
|
+
};
|
|
12
|
+
export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, meId?: string) => string;
|
|
13
|
+
export declare const writeRandomPadMax16: (msg: Uint8Array) => any;
|
|
14
|
+
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array<any>;
|
|
15
|
+
export declare const encodeWAMessage: (message: proto.IMessage) => any;
|
|
16
|
+
export declare const generateRegistrationId: () => number;
|
|
17
|
+
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array<ArrayBuffer>;
|
|
18
|
+
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
|
19
|
+
/** unix timestamp of a date in seconds */
|
|
20
|
+
export declare const unixTimestampSeconds: (date?: Date) => number;
|
|
21
|
+
export type DebouncedTimeout = ReturnType<typeof debouncedTimeout>;
|
|
22
|
+
export declare const debouncedTimeout: (intervalMs?: number, task?: () => void) => {
|
|
23
|
+
start: (newIntervalMs?: number, newTask?: () => void) => void;
|
|
24
|
+
cancel: () => void;
|
|
25
|
+
setTask: (newTask: () => void) => () => void;
|
|
26
|
+
setInterval: (newInterval: number) => number;
|
|
27
|
+
};
|
|
28
|
+
export declare const delay: (ms: number) => Promise<void>;
|
|
29
|
+
export declare const delayCancellable: (ms: number) => {
|
|
30
|
+
delay: Promise<void>;
|
|
31
|
+
cancel: () => void;
|
|
32
|
+
};
|
|
33
|
+
export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
|
|
34
|
+
export declare const generateMessageIDV2: (userId?: string) => string;
|
|
35
|
+
export declare const generateMessageID: () => string;
|
|
36
|
+
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
37
|
+
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
38
|
+
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
|
|
39
|
+
/**
|
|
40
|
+
* utility that fetches latest baileys version from the master branch.
|
|
41
|
+
* Use to ensure your WA connection is always on the latest version
|
|
42
|
+
*/
|
|
43
|
+
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
|
|
44
|
+
version: any;
|
|
45
|
+
isLatest: boolean;
|
|
46
|
+
error?: undefined;
|
|
47
|
+
} | {
|
|
48
|
+
version: WAVersion;
|
|
49
|
+
isLatest: boolean;
|
|
50
|
+
error: any;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* A utility that fetches the latest web version of whatsapp.
|
|
54
|
+
* Use to ensure your WA connection is always on the latest version
|
|
55
|
+
*/
|
|
56
|
+
export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<any>) => Promise<{
|
|
57
|
+
version: WAVersion;
|
|
58
|
+
isLatest: boolean;
|
|
59
|
+
error?: undefined;
|
|
60
|
+
} | {
|
|
61
|
+
version: WAVersion;
|
|
62
|
+
isLatest: boolean;
|
|
63
|
+
error: any;
|
|
64
|
+
}>;
|
|
65
|
+
/** unique message tag prefix for MD clients */
|
|
66
|
+
export declare const generateMdTagPrefix: () => string;
|
|
67
|
+
/**
|
|
68
|
+
* Given a type of receipt, returns what the new status of the message should be
|
|
69
|
+
* @param type type from receipt
|
|
70
|
+
*/
|
|
71
|
+
export declare const getStatusFromReceiptType: (type: string | undefined) => proto.WebMessageInfo.Status;
|
|
72
|
+
/**
|
|
73
|
+
* Stream errors generally provide a reason, map that to a baileys DisconnectReason
|
|
74
|
+
* @param reason the string reason given, eg. "conflict"
|
|
75
|
+
*/
|
|
76
|
+
export declare const getErrorCodeFromStreamError: (node: BinaryNode) => {
|
|
77
|
+
reason: string;
|
|
78
|
+
statusCode: number;
|
|
79
|
+
};
|
|
80
|
+
export declare const getCallStatusFromNode: ({ tag, attrs }: BinaryNode) => WACallUpdateType;
|
|
81
|
+
export declare const getCodeFromWSError: (error: Error) => number;
|
|
82
|
+
/**
|
|
83
|
+
* Is the given platform WA business
|
|
84
|
+
* @param platform AuthenticationCreds.platform
|
|
85
|
+
*/
|
|
86
|
+
export declare const isWABusinessPlatform: (platform: string) => platform is "smbi" | "smba";
|
|
87
|
+
export declare function trimUndefined(obj: any): any;
|
|
88
|
+
export declare function bytesToCrockford(buffer: Buffer): string;
|
|
@@ -1,51 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
4
|
};
|
|
47
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.Browsers = void 0;
|
|
6
|
+
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
|
|
49
7
|
exports.promiseTimeout = promiseTimeout;
|
|
50
8
|
exports.bindWaitForEvent = bindWaitForEvent;
|
|
51
9
|
exports.trimUndefined = trimUndefined;
|
|
@@ -58,20 +16,37 @@ const WAProto_1 = require("../../WAProto");
|
|
|
58
16
|
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
|
59
17
|
const Types_1 = require("../Types");
|
|
60
18
|
const WABinary_1 = require("../WABinary");
|
|
19
|
+
const COMPANION_PLATFORM_MAP = {
|
|
20
|
+
'Chrome': '49',
|
|
21
|
+
'Edge': '50',
|
|
22
|
+
'Firefox': '51',
|
|
23
|
+
'Opera': '53',
|
|
24
|
+
'Safari': '54'
|
|
25
|
+
};
|
|
61
26
|
const PLATFORM_MAP = {
|
|
62
27
|
'aix': 'AIX',
|
|
63
28
|
'darwin': 'Mac OS',
|
|
64
29
|
'win32': 'Windows',
|
|
65
|
-
'android': 'Android'
|
|
30
|
+
'android': 'Android',
|
|
31
|
+
'freebsd': 'FreeBSD',
|
|
32
|
+
'openbsd': 'OpenBSD',
|
|
33
|
+
'sunos': 'Solaris'
|
|
66
34
|
};
|
|
67
35
|
exports.Browsers = {
|
|
68
|
-
ubuntu: browser => ['Ubuntu', browser, '
|
|
69
|
-
macOS: browser => ['Mac OS', browser, '
|
|
70
|
-
baileys: browser => ['Baileys', browser, '
|
|
71
|
-
windows: browser => ['Windows', browser, '10.0.
|
|
36
|
+
ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
|
|
37
|
+
macOS: (browser) => ['Mac OS', browser, '14.4.1'],
|
|
38
|
+
baileys: (browser) => ['Baileys', browser, '6.5.0'],
|
|
39
|
+
windows: (browser) => ['Windows', browser, '10.0.22631'],
|
|
40
|
+
iOS: (browser) => ['iOS', browser, '18.2'],
|
|
41
|
+
linux: (browser) => ['Linux', browser, '6.12.6'],
|
|
72
42
|
/** The appropriate browser based on your OS & release */
|
|
73
|
-
appropriate: browser => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
43
|
+
appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
44
|
+
};
|
|
45
|
+
const getPlatformId = (browser) => {
|
|
46
|
+
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
47
|
+
return platformType ? platformType.toString().charCodeAt(0).toString() : '49'; //chrome
|
|
74
48
|
};
|
|
49
|
+
exports.getPlatformId = getPlatformId;
|
|
75
50
|
exports.BufferJSON = {
|
|
76
51
|
replacer: (k, value) => {
|
|
77
52
|
if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
|
|
@@ -171,28 +146,26 @@ const delayCancellable = (ms) => {
|
|
|
171
146
|
return { delay, cancel };
|
|
172
147
|
};
|
|
173
148
|
exports.delayCancellable = delayCancellable;
|
|
174
|
-
function promiseTimeout(ms, promise) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return p;
|
|
195
|
-
});
|
|
149
|
+
async function promiseTimeout(ms, promise) {
|
|
150
|
+
if (!ms) {
|
|
151
|
+
return new Promise(promise);
|
|
152
|
+
}
|
|
153
|
+
const stack = new Error().stack;
|
|
154
|
+
// Create a promise that rejects in <ms> milliseconds
|
|
155
|
+
const { delay, cancel } = (0, exports.delayCancellable)(ms);
|
|
156
|
+
const p = new Promise((resolve, reject) => {
|
|
157
|
+
delay
|
|
158
|
+
.then(() => reject(new boom_1.Boom('Timed Out', {
|
|
159
|
+
statusCode: Types_1.DisconnectReason.timedOut,
|
|
160
|
+
data: {
|
|
161
|
+
stack
|
|
162
|
+
}
|
|
163
|
+
})))
|
|
164
|
+
.catch(err => reject(err));
|
|
165
|
+
promise(resolve, reject);
|
|
166
|
+
})
|
|
167
|
+
.finally(cancel);
|
|
168
|
+
return p;
|
|
196
169
|
}
|
|
197
170
|
const generateMessageIDV2 = (userId) => {
|
|
198
171
|
const data = Buffer.alloc(8 + 20 + 16);
|
|
@@ -207,17 +180,17 @@ const generateMessageIDV2 = (userId) => {
|
|
|
207
180
|
const random = (0, crypto_1.randomBytes)(16);
|
|
208
181
|
random.copy(data, 28);
|
|
209
182
|
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
|
210
|
-
return '
|
|
183
|
+
return 'FTG-' + hash.toString('hex').toUpperCase().substring(0, 18);
|
|
211
184
|
};
|
|
212
185
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
213
186
|
// generate a random ID to attach to a message
|
|
214
|
-
const generateMessageID = () => '
|
|
187
|
+
const generateMessageID = () => 'FTG-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
|
215
188
|
exports.generateMessageID = generateMessageID;
|
|
216
189
|
function bindWaitForEvent(ev, event) {
|
|
217
|
-
return (check, timeoutMs) =>
|
|
190
|
+
return async (check, timeoutMs) => {
|
|
218
191
|
let listener;
|
|
219
192
|
let closeListener;
|
|
220
|
-
|
|
193
|
+
await (promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
221
194
|
closeListener = ({ connection, lastDisconnect }) => {
|
|
222
195
|
if (connection === 'close') {
|
|
223
196
|
reject((lastDisconnect === null || lastDisconnect === void 0 ? void 0 : lastDisconnect.error)
|
|
@@ -236,30 +209,34 @@ function bindWaitForEvent(ev, event) {
|
|
|
236
209
|
ev.off(event, listener);
|
|
237
210
|
ev.off('connection.update', closeListener);
|
|
238
211
|
}));
|
|
239
|
-
}
|
|
212
|
+
};
|
|
240
213
|
}
|
|
241
214
|
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
|
242
215
|
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
243
216
|
const printQRIfNecessaryListener = (ev, logger) => {
|
|
244
|
-
ev.on('connection.update',
|
|
217
|
+
ev.on('connection.update', async ({ qr }) => {
|
|
245
218
|
if (qr) {
|
|
246
|
-
const QR =
|
|
219
|
+
const QR = await import('qrcode-terminal')
|
|
220
|
+
.then(m => m.default || m)
|
|
247
221
|
.catch(() => {
|
|
248
222
|
logger.error('QR code terminal not added as dependency');
|
|
249
223
|
});
|
|
250
224
|
QR === null || QR === void 0 ? void 0 : QR.generate(qr, { small: true });
|
|
251
225
|
}
|
|
252
|
-
})
|
|
226
|
+
});
|
|
253
227
|
};
|
|
254
228
|
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
255
229
|
/**
|
|
256
230
|
* utility that fetches latest baileys version from the master branch.
|
|
257
231
|
* Use to ensure your WA connection is always on the latest version
|
|
258
232
|
*/
|
|
259
|
-
const fetchLatestBaileysVersion =
|
|
233
|
+
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
260
234
|
const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/baileys-version.json';
|
|
261
235
|
try {
|
|
262
|
-
const result =
|
|
236
|
+
const result = await axios_1.default.get(URL, {
|
|
237
|
+
...options,
|
|
238
|
+
responseType: 'json'
|
|
239
|
+
});
|
|
263
240
|
return {
|
|
264
241
|
version: result.data.version,
|
|
265
242
|
isLatest: true
|
|
@@ -272,15 +249,18 @@ const fetchLatestBaileysVersion = (...args_1) => __awaiter(void 0, [...args_1],
|
|
|
272
249
|
error
|
|
273
250
|
};
|
|
274
251
|
}
|
|
275
|
-
}
|
|
252
|
+
};
|
|
276
253
|
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
277
254
|
/**
|
|
278
255
|
* A utility that fetches the latest web version of whatsapp.
|
|
279
256
|
* Use to ensure your WA connection is always on the latest version
|
|
280
257
|
*/
|
|
281
|
-
const fetchLatestWaWebVersion = (options) =>
|
|
258
|
+
const fetchLatestWaWebVersion = async (options) => {
|
|
282
259
|
try {
|
|
283
|
-
const result =
|
|
260
|
+
const result = await axios_1.default.get('https://web.whatsapp.com/check-update?version=1&platform=web', {
|
|
261
|
+
...options,
|
|
262
|
+
responseType: 'json'
|
|
263
|
+
});
|
|
284
264
|
const version = result.data.currentVersion.split('.');
|
|
285
265
|
return {
|
|
286
266
|
version: [+version[0], +version[1], +version[2]],
|
|
@@ -294,7 +274,7 @@ const fetchLatestWaWebVersion = (options) => __awaiter(void 0, void 0, void 0, f
|
|
|
294
274
|
error
|
|
295
275
|
};
|
|
296
276
|
}
|
|
297
|
-
}
|
|
277
|
+
};
|
|
298
278
|
exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
299
279
|
/** unique message tag prefix for MD clients */
|
|
300
280
|
const generateMdTagPrefix = () => {
|
|
@@ -351,7 +331,8 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
351
331
|
status = 'timeout';
|
|
352
332
|
}
|
|
353
333
|
else {
|
|
354
|
-
|
|
334
|
+
//fired when accepted/rejected/timeout/caller hangs up
|
|
335
|
+
status = 'terminate';
|
|
355
336
|
}
|
|
356
337
|
break;
|
|
357
338
|
case 'reject':
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { proto } from '../../WAProto';
|
|
3
|
+
import { Chat, Contact } from '../Types';
|
|
4
|
+
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<proto.HistorySync>;
|
|
5
|
+
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
6
|
+
chats: Chat[];
|
|
7
|
+
contacts: Contact[];
|
|
8
|
+
messages: proto.IWebMessageInfo[];
|
|
9
|
+
syncType: proto.HistorySync.HistorySyncType;
|
|
10
|
+
progress: number | null | undefined;
|
|
11
|
+
};
|
|
12
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<{
|
|
13
|
+
chats: Chat[];
|
|
14
|
+
contacts: Contact[];
|
|
15
|
+
messages: proto.IWebMessageInfo[];
|
|
16
|
+
syncType: proto.HistorySync.HistorySyncType;
|
|
17
|
+
progress: number | null | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
|