@hbmodsofc/baileys 2.5.0 → 3.1.0
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/LICENSE +1 -1
- package/README.MD +220 -1198
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +5619 -0
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +97 -122
- package/lib/Defaults/phonenumber_mcc.json +223 -0
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +54 -5
- package/lib/Socket/business.js +8 -2
- package/lib/Socket/chats.js +455 -288
- package/lib/Socket/communities.js +441 -0
- package/lib/Socket/groups.js +38 -23
- package/lib/Socket/hbmods.js +374 -406
- package/lib/Socket/index.js +43 -11
- package/lib/Socket/messages-recv.js +24 -69
- package/lib/Socket/messages-send.js +391 -419
- package/lib/Socket/newsletter.js +104 -190
- package/lib/Socket/socket.js +40 -54
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.js +27 -15
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.js +18 -38
- package/lib/Types/index.js +2 -2
- package/lib/Utils/async-iterable.js +41 -0
- package/lib/Utils/audioToBuffer.js +29 -0
- package/lib/Utils/auth-utils.js +6 -13
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/browser-utils.js +35 -0
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.js +36 -35
- package/lib/Utils/crypto.js +71 -29
- package/lib/Utils/decode-wa-message.js +65 -56
- package/lib/Utils/event-buffer.js +13 -9
- package/lib/Utils/generics.js +88 -84
- package/lib/Utils/history.js +4 -6
- package/lib/Utils/index.js +3 -0
- package/lib/Utils/link-preview.js +34 -1
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/message-retry-manager.js +128 -0
- package/lib/Utils/messages-media.js +340 -246
- package/lib/Utils/messages.js +329 -192
- package/lib/Utils/noise-handler.js +18 -23
- package/lib/Utils/process-message.js +108 -25
- package/lib/Utils/resolveJid.js +52 -0
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/streamToBuffer.js +15 -0
- package/lib/Utils/use-multi-file-auth-state.js +3 -0
- package/lib/Utils/validate-connection.js +1 -3
- package/lib/WABinary/constants.js +1276 -13
- package/lib/WABinary/decode.js +26 -13
- package/lib/WABinary/encode.js +137 -152
- package/lib/WABinary/generic-utils.js +37 -125
- package/lib/WABinary/jid-utils.js +28 -5
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.js +1 -1
- package/package.json +112 -104
- package/lib/Defaults/index.d.ts +0 -53
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/business.d.ts +0 -171
- package/lib/Socket/chats.d.ts +0 -267
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/hbmods.d.ts +0 -254
- package/lib/Socket/index.d.ts +0 -173
- package/lib/Socket/messages-recv.d.ts +0 -161
- package/lib/Socket/messages-send.d.ts +0 -149
- package/lib/Socket/newsletter.d.ts +0 -134
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/socket.d.ts +0 -43
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -110
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -102
- package/lib/Types/Contact.d.ts +0 -19
- package/lib/Types/Events.d.ts +0 -157
- package/lib/Types/GroupMetadata.d.ts +0 -55
- package/lib/Types/Label.d.ts +0 -35
- package/lib/Types/LabelAssociation.d.ts +0 -29
- package/lib/Types/Message.d.ts +0 -273
- package/lib/Types/Newsletter.d.ts +0 -103
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/Socket.d.ts +0 -111
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/index.d.ts +0 -57
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -71
- package/lib/Utils/crypto.d.ts +0 -41
- package/lib/Utils/decode-wa-message.d.ts +0 -19
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/generics.js.bak +0 -433
- package/lib/Utils/history.d.ts +0 -15
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -4
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -116
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -21
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/Utils/validate-connection.js.bak +0 -237
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -17
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -17
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/USyncQuery.d.ts +0 -28
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -12
- /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageRetryManager = void 0;
|
|
4
|
+
|
|
5
|
+
const lru_cache_1 = require("lru-cache");
|
|
6
|
+
|
|
7
|
+
const RECENT_MESSAGES_SIZE = 512;
|
|
8
|
+
|
|
9
|
+
const RECREATE_SESSION_TIMEOUT = 60 * 60 * 1000;
|
|
10
|
+
|
|
11
|
+
const PHONE_REQUEST_DELAY = 3000;
|
|
12
|
+
|
|
13
|
+
class MessageRetryManager {
|
|
14
|
+
constructor(logger, maxMsgRetryCount) {
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
this.maxMsgRetryCount = maxMsgRetryCount;
|
|
17
|
+
this._recentMessagesMap = new lru_cache_1.LRUCache({
|
|
18
|
+
max: RECENT_MESSAGES_SIZE
|
|
19
|
+
});
|
|
20
|
+
this._sessionRecreateHistory = new lru_cache_1.LRUCache({
|
|
21
|
+
ttl: RECREATE_SESSION_TIMEOUT * 2,
|
|
22
|
+
ttlAutopurge: true
|
|
23
|
+
});
|
|
24
|
+
this._retryCounters = new lru_cache_1.LRUCache({
|
|
25
|
+
ttl: 15 * 60 * 1000,
|
|
26
|
+
ttlAutopurge: true,
|
|
27
|
+
updateAgeOnGet: true
|
|
28
|
+
});
|
|
29
|
+
this._pendingPhoneRequests = {};
|
|
30
|
+
this.statistics = {
|
|
31
|
+
totalRetries: 0,
|
|
32
|
+
successfulRetries: 0,
|
|
33
|
+
failedRetries: 0,
|
|
34
|
+
mediaRetries: 0,
|
|
35
|
+
sessionRecreations: 0,
|
|
36
|
+
phoneRequests: 0
|
|
37
|
+
};
|
|
38
|
+
this.maxMsgRetryCount = maxMsgRetryCount;
|
|
39
|
+
}
|
|
40
|
+
addRecentMessage(to, id, message) {
|
|
41
|
+
const key = { to, id };
|
|
42
|
+
const keyStr = this._keyToString(key);
|
|
43
|
+
this._recentMessagesMap.set(keyStr, {
|
|
44
|
+
message,
|
|
45
|
+
timestamp: Date.now()
|
|
46
|
+
});
|
|
47
|
+
this.logger.debug(`Added message to retry cache: ${to}/${id}`);
|
|
48
|
+
}
|
|
49
|
+
getRecentMessage(to, id) {
|
|
50
|
+
const key = { to, id };
|
|
51
|
+
const keyStr = this._keyToString(key);
|
|
52
|
+
return this._recentMessagesMap.get(keyStr);
|
|
53
|
+
}
|
|
54
|
+
shouldRecreateSession(jid, retryCount, hasSession) {
|
|
55
|
+
if (!hasSession) {
|
|
56
|
+
this._sessionRecreateHistory.set(jid, Date.now());
|
|
57
|
+
this.statistics.sessionRecreations++;
|
|
58
|
+
return {
|
|
59
|
+
reason: "we don't have a Signal session with them",
|
|
60
|
+
recreate: true
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (retryCount < 2) {
|
|
64
|
+
return { reason: '', recreate: false };
|
|
65
|
+
}
|
|
66
|
+
const now = Date.now();
|
|
67
|
+
const prevTime = this._sessionRecreateHistory.get(jid);
|
|
68
|
+
if (!prevTime || now - prevTime > RECREATE_SESSION_TIMEOUT) {
|
|
69
|
+
this._sessionRecreateHistory.set(jid, now);
|
|
70
|
+
this.statistics.sessionRecreations++;
|
|
71
|
+
return {
|
|
72
|
+
reason: 'retry count > 1 and over an hour since last recreation',
|
|
73
|
+
recreate: true
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return { reason: '', recreate: false };
|
|
77
|
+
}
|
|
78
|
+
incrementRetryCount(messageId) {
|
|
79
|
+
this._retryCounters.set(messageId, (this._retryCounters.get(messageId) || 0) + 1);
|
|
80
|
+
this.statistics.totalRetries++;
|
|
81
|
+
return this._retryCounters.get(messageId);
|
|
82
|
+
}
|
|
83
|
+
getRetryCount(messageId) {
|
|
84
|
+
return this._retryCounters.get(messageId) || 0;
|
|
85
|
+
}
|
|
86
|
+
hasExceededMaxRetries(messageId) {
|
|
87
|
+
return this.getRetryCount(messageId) >= this.maxMsgRetryCount;
|
|
88
|
+
}
|
|
89
|
+
markRetrySuccess(messageId) {
|
|
90
|
+
this.statistics.successfulRetries++;
|
|
91
|
+
this._retryCounters.delete(messageId);
|
|
92
|
+
this._cancelPendingPhoneRequest(messageId);
|
|
93
|
+
}
|
|
94
|
+
markRetryFailed(messageId) {
|
|
95
|
+
this.statistics.failedRetries++;
|
|
96
|
+
this._retryCounters.delete(messageId);
|
|
97
|
+
}
|
|
98
|
+
schedulePhoneRequest(messageId, callback, delay = PHONE_REQUEST_DELAY) {
|
|
99
|
+
this._cancelPendingPhoneRequest(messageId);
|
|
100
|
+
this._pendingPhoneRequests[messageId] = setTimeout(() => {
|
|
101
|
+
delete this._pendingPhoneRequests[messageId];
|
|
102
|
+
this.statistics.phoneRequests++;
|
|
103
|
+
callback();
|
|
104
|
+
}, delay);
|
|
105
|
+
this.logger.debug(`Scheduled phone request for message ${messageId} with ${delay}ms delay`);
|
|
106
|
+
}
|
|
107
|
+
cancelPendingPhoneRequest(messageId) {
|
|
108
|
+
const timeout = this._pendingPhoneRequests[messageId];
|
|
109
|
+
if (timeout) {
|
|
110
|
+
clearTimeout(timeout);
|
|
111
|
+
delete this._pendingPhoneRequests[messageId];
|
|
112
|
+
this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
_keyToString(key) {
|
|
116
|
+
return `${key.to}:${key.id}`;
|
|
117
|
+
}
|
|
118
|
+
_cancelPendingPhoneRequest(messageId) {
|
|
119
|
+
const timeout = this._pendingPhoneRequests[messageId];
|
|
120
|
+
if (timeout) {
|
|
121
|
+
clearTimeout(timeout);
|
|
122
|
+
delete this._pendingPhoneRequests[messageId];
|
|
123
|
+
this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
exports.MessageRetryManager = MessageRetryManager;
|