@vinzsocket/baileys 2.8.10 → 2.8.20
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/lib/Defaults/index.js +75 -73
- package/lib/Signal/Group/ciphertext-message.js +9 -9
- package/lib/Signal/Group/group-session-builder.js +21 -21
- package/lib/Signal/Group/group_cipher.js +79 -81
- package/lib/Signal/Group/index.js +2 -2
- package/lib/Signal/Group/keyhelper.js +9 -9
- package/lib/Signal/Group/queue-job.js +43 -46
- package/lib/Signal/Group/sender-chain-key.js +24 -25
- package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
- package/lib/Signal/Group/sender-key-message.js +55 -60
- package/lib/Signal/Group/sender-key-name.js +38 -39
- package/lib/Signal/Group/sender-key-record.js +39 -41
- package/lib/Signal/Group/sender-key-state.js +85 -89
- package/lib/Signal/Group/sender-message-key.js +22 -22
- package/lib/Signal/libsignal.js +387 -292
- package/lib/Signal/lid-mapping.js +98 -93
- package/lib/Socket/Client/types.js +6 -6
- package/lib/Socket/Client/websocket.js +44 -44
- package/lib/Socket/business.js +350 -365
- package/lib/Socket/chats.js +1019 -914
- package/lib/Socket/communities.js +454 -376
- package/lib/Socket/groups.js +378 -310
- package/lib/Socket/index.js +11 -11
- package/lib/Socket/messages-recv.js +1355 -1182
- package/lib/Socket/messages-send.js +1224 -1081
- package/lib/Socket/mex.js +40 -34
- package/lib/Socket/newsletter.js +212 -169
- package/lib/Socket/socket.js +896 -757
- package/lib/Store/index.js +1 -1
- package/lib/Store/make-cache-manager-store.js +75 -79
- package/lib/Store/make-in-memory-store.js +450 -389
- package/lib/Store/make-ordered-dictionary.js +73 -76
- package/lib/Store/object-repository.js +24 -22
- package/lib/Types/Chat.js +1 -7
- package/lib/Types/Label.js +20 -20
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +2 -2
- package/lib/Types/Newsletter.js +24 -24
- package/lib/Types/Socket.js +1 -1
- package/lib/Types/State.js +8 -8
- package/lib/Types/index.js +10 -10
- package/lib/Utils/auth-utils.js +408 -401
- package/lib/Utils/baileys-event-stream.js +44 -35
- package/lib/Utils/business.js +200 -197
- package/lib/Utils/chat-utils.js +775 -708
- package/lib/Utils/crypto.js +97 -85
- package/lib/Utils/decode-wa-message.js +240 -227
- package/lib/Utils/event-buffer.js +547 -518
- package/lib/Utils/extended-messages.js +250 -203
- package/lib/Utils/generics.js +300 -289
- package/lib/Utils/history.js +76 -69
- package/lib/Utils/lid-resolver.js +47 -42
- package/lib/Utils/link-preview.js +75 -65
- package/lib/Utils/logger.js +3 -1
- package/lib/Utils/lt-hash.js +38 -34
- package/lib/Utils/make-mutex.js +32 -34
- package/lib/Utils/mention.js +79 -86
- package/lib/Utils/message-retry-manager.js +148 -136
- package/lib/Utils/messages-media.js +652 -562
- package/lib/Utils/messages.js +753 -707
- package/lib/Utils/noise-handler.js +156 -135
- package/lib/Utils/process-message.js +404 -341
- package/lib/Utils/signal.js +180 -118
- package/lib/Utils/use-multi-file-auth-state.js +87 -91
- package/lib/Utils/validate-connection.js +167 -142
- package/lib/WABinary/constants.js +28 -1293
- package/lib/WABinary/decode.js +220 -218
- package/lib/WABinary/encode.js +199 -201
- package/lib/WABinary/generic-utils.js +80 -77
- package/lib/WABinary/jid-utils.js +41 -35
- package/lib/WAM/BinaryInfo.js +7 -7
- package/lib/WAM/constants.js +1 -15241
- package/lib/WAM/encode.js +124 -131
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
- package/lib/WAUSync/USyncQuery.js +82 -84
- package/lib/WAUSync/USyncUser.js +20 -20
- package/package.json +5 -2
package/lib/Utils/mention.js
CHANGED
|
@@ -11,38 +11,31 @@ const mentionCache = new Map();
|
|
|
11
11
|
* @returns {string[]}
|
|
12
12
|
*/
|
|
13
13
|
export function normalizeMentions(mentions) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const cacheKey = JSON.stringify(mentions);
|
|
15
|
+
if (mentionCache.has(cacheKey)) {
|
|
16
|
+
return mentionCache.get(cacheKey);
|
|
17
|
+
}
|
|
18
|
+
if (!mentions) return [];
|
|
19
|
+
if (!Array.isArray(mentions)) mentions = [mentions];
|
|
20
|
+
const result = mentions.map(jid => {
|
|
21
|
+
if (typeof jid !== 'string') return null;
|
|
22
|
+
jid = jid.trim();
|
|
23
|
+
if (!jid) return null;
|
|
24
|
+
// Already has @s.whatsapp.net or @lid
|
|
25
|
+
if (jid.includes('@s.whatsapp.net') || jid.includes('@lid')) {
|
|
26
|
+
return jid;
|
|
17
27
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// Already has @s.whatsapp.net or @lid
|
|
30
|
-
if (jid.includes('@s.whatsapp.net') || jid.includes('@lid')) {
|
|
31
|
-
return jid;
|
|
32
|
-
}
|
|
33
|
-
// Has @ but not complete
|
|
34
|
-
if (jid.includes('@')) {
|
|
35
|
-
return jid;
|
|
36
|
-
}
|
|
37
|
-
// Plain number
|
|
38
|
-
return jid + '@s.whatsapp.net';
|
|
39
|
-
})
|
|
40
|
-
.filter(Boolean);
|
|
41
|
-
mentionCache.set(cacheKey, result);
|
|
42
|
-
// Simple cache size limit
|
|
43
|
-
if (mentionCache.size > 1000)
|
|
44
|
-
mentionCache.clear();
|
|
45
|
-
return result;
|
|
28
|
+
// Has @ but not complete
|
|
29
|
+
if (jid.includes('@')) {
|
|
30
|
+
return jid;
|
|
31
|
+
}
|
|
32
|
+
// Plain number
|
|
33
|
+
return jid + '@s.whatsapp.net';
|
|
34
|
+
}).filter(Boolean);
|
|
35
|
+
mentionCache.set(cacheKey, result);
|
|
36
|
+
// Simple cache size limit
|
|
37
|
+
if (mentionCache.size > 1000) mentionCache.clear();
|
|
38
|
+
return result;
|
|
46
39
|
}
|
|
47
40
|
/**
|
|
48
41
|
* Apply mentions into a message object (for use by custom content builders)
|
|
@@ -52,43 +45,39 @@ export function normalizeMentions(mentions) {
|
|
|
52
45
|
* @returns {object} msg
|
|
53
46
|
*/
|
|
54
47
|
export function applyMentions(msg, mentions, contextInfo = {}) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
48
|
+
const normalized = normalizeMentions(mentions);
|
|
49
|
+
if (normalized.length === 0) return msg;
|
|
50
|
+
// messageContextInfo
|
|
51
|
+
if (!msg.messageContextInfo) msg.messageContextInfo = {};
|
|
52
|
+
if (!msg.messageContextInfo.mentionedJid) msg.messageContextInfo.mentionedJid = [];
|
|
53
|
+
const existing = new Set(msg.messageContextInfo.mentionedJid);
|
|
54
|
+
for (const jid of normalized) {
|
|
55
|
+
if (!existing.has(jid)) {
|
|
56
|
+
msg.messageContextInfo.mentionedJid.push(jid);
|
|
57
|
+
existing.add(jid);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// contextInfo
|
|
61
|
+
if (contextInfo && typeof contextInfo === 'object') {
|
|
62
|
+
if (!contextInfo.mentionedJid) contextInfo.mentionedJid = [];
|
|
64
63
|
for (const jid of normalized) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
64
|
+
if (!contextInfo.mentionedJid.includes(jid)) {
|
|
65
|
+
contextInfo.mentionedJid.push(jid);
|
|
66
|
+
}
|
|
69
67
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (!contextInfo.mentionedJid.includes(jid)) {
|
|
76
|
-
contextInfo.mentionedJid.push(jid);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
68
|
+
}
|
|
69
|
+
// Extra for interactiveMessage
|
|
70
|
+
if (msg.interactiveMessage?.contextInfo) {
|
|
71
|
+
if (!msg.interactiveMessage.contextInfo.mentionedJid) {
|
|
72
|
+
msg.interactiveMessage.contextInfo.mentionedJid = [];
|
|
79
73
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
for (const jid of normalized) {
|
|
86
|
-
if (!msg.interactiveMessage.contextInfo.mentionedJid.includes(jid)) {
|
|
87
|
-
msg.interactiveMessage.contextInfo.mentionedJid.push(jid);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
74
|
+
for (const jid of normalized) {
|
|
75
|
+
if (!msg.interactiveMessage.contextInfo.mentionedJid.includes(jid)) {
|
|
76
|
+
msg.interactiveMessage.contextInfo.mentionedJid.push(jid);
|
|
77
|
+
}
|
|
90
78
|
}
|
|
91
|
-
|
|
79
|
+
}
|
|
80
|
+
return msg;
|
|
92
81
|
}
|
|
93
82
|
/**
|
|
94
83
|
* Build a "tag all" text block + mentionedJid list from a group's participants,
|
|
@@ -109,26 +98,30 @@ export function applyMentions(msg, mentions, contextInfo = {}) {
|
|
|
109
98
|
* @returns {{ text: string, mentions: string[] }}
|
|
110
99
|
*/
|
|
111
100
|
export function buildTagAllText(participants, options = {}) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
101
|
+
const {
|
|
102
|
+
getDisplayName = lidResolver.getDisplayName,
|
|
103
|
+
header = '',
|
|
104
|
+
footer = ''
|
|
105
|
+
} = options;
|
|
106
|
+
const lines = [];
|
|
107
|
+
const mentions = [];
|
|
108
|
+
for (const p of participants || []) {
|
|
109
|
+
// Prefer a real phone-number JID when WhatsApp actually disclosed one.
|
|
110
|
+
const realJid = p.jid && p.jid.endsWith('@s.whatsapp.net') ? p.jid : p.phoneNumber ? p.phoneNumber.includes('@') ? p.phoneNumber : `${p.phoneNumber}@s.whatsapp.net` : null;
|
|
111
|
+
const mentionJid = realJid || p.id; // what we actually tag/ping (lid is fine for this)
|
|
112
|
+
mentions.push(mentionJid);
|
|
113
|
+
if (realJid) {
|
|
114
|
+
// We know the real phone number — safe & useful to show it.
|
|
115
|
+
lines.push(`@${realJid.split('@')[0]}`);
|
|
116
|
+
} else {
|
|
117
|
+
// LID-only participant: don't print fake-looking digits.
|
|
118
|
+
const name = getDisplayName ? getDisplayName(p.id) : null;
|
|
119
|
+
lines.push(name ? `@${name}` : '@Member');
|
|
131
120
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
121
|
+
}
|
|
122
|
+
const body = [header, lines.join('\n'), footer].filter(Boolean).join('\n\n');
|
|
123
|
+
return {
|
|
124
|
+
text: body,
|
|
125
|
+
mentions
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -5,145 +5,157 @@ const RECENT_MESSAGES_SIZE = 512;
|
|
|
5
5
|
const RECREATE_SESSION_TIMEOUT = 60 * 60 * 1000; // 1 hour in milliseconds
|
|
6
6
|
const PHONE_REQUEST_DELAY = 3000;
|
|
7
7
|
export class MessageRetryManager {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
8
|
+
constructor(logger, maxMsgRetryCount) {
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
this.recentMessagesMap = new LRUCache({
|
|
11
|
+
max: RECENT_MESSAGES_SIZE
|
|
12
|
+
});
|
|
13
|
+
this.sessionRecreateHistory = new LRUCache({
|
|
14
|
+
ttl: RECREATE_SESSION_TIMEOUT * 2,
|
|
15
|
+
ttlAutopurge: true
|
|
16
|
+
});
|
|
17
|
+
this.retryCounters = new LRUCache({
|
|
18
|
+
ttl: 15 * 60 * 1000,
|
|
19
|
+
ttlAutopurge: true,
|
|
20
|
+
updateAgeOnGet: true
|
|
21
|
+
}); // 15 minutes TTL
|
|
22
|
+
this.pendingPhoneRequests = {};
|
|
23
|
+
this.maxMsgRetryCount = 5;
|
|
24
|
+
this.statistics = {
|
|
25
|
+
totalRetries: 0,
|
|
26
|
+
successfulRetries: 0,
|
|
27
|
+
failedRetries: 0,
|
|
28
|
+
mediaRetries: 0,
|
|
29
|
+
sessionRecreations: 0,
|
|
30
|
+
phoneRequests: 0
|
|
31
|
+
};
|
|
32
|
+
this.maxMsgRetryCount = maxMsgRetryCount;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Add a recent message to the cache for retry handling
|
|
36
|
+
*/
|
|
37
|
+
addRecentMessage(to, id, message) {
|
|
38
|
+
const key = {
|
|
39
|
+
to,
|
|
40
|
+
id
|
|
41
|
+
};
|
|
42
|
+
const keyStr = this.keyToString(key);
|
|
43
|
+
// Add new message
|
|
44
|
+
this.recentMessagesMap.set(keyStr, {
|
|
45
|
+
message,
|
|
46
|
+
timestamp: Date.now()
|
|
47
|
+
});
|
|
48
|
+
this.logger.debug(`Added message to retry cache: ${to}/${id}`);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get a recent message from the cache
|
|
52
|
+
*/
|
|
53
|
+
getRecentMessage(to, id) {
|
|
54
|
+
const key = {
|
|
55
|
+
to,
|
|
56
|
+
id
|
|
57
|
+
};
|
|
58
|
+
const keyStr = this.keyToString(key);
|
|
59
|
+
return this.recentMessagesMap.get(keyStr);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Check if a session should be recreated based on retry count and history
|
|
63
|
+
*/
|
|
64
|
+
shouldRecreateSession(jid, retryCount, hasSession) {
|
|
65
|
+
// If we don't have a session, always recreate
|
|
66
|
+
if (!hasSession) {
|
|
67
|
+
this.sessionRecreateHistory.set(jid, Date.now());
|
|
68
|
+
this.statistics.sessionRecreations++;
|
|
69
|
+
return {
|
|
70
|
+
reason: "we don't have a Signal session with them",
|
|
71
|
+
recreate: true
|
|
72
|
+
};
|
|
33
73
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// Add new message
|
|
41
|
-
this.recentMessagesMap.set(keyStr, {
|
|
42
|
-
message,
|
|
43
|
-
timestamp: Date.now()
|
|
44
|
-
});
|
|
45
|
-
this.logger.debug(`Added message to retry cache: ${to}/${id}`);
|
|
74
|
+
// Only consider recreation if retry count > 1
|
|
75
|
+
if (retryCount < 2) {
|
|
76
|
+
return {
|
|
77
|
+
reason: '',
|
|
78
|
+
recreate: false
|
|
79
|
+
};
|
|
46
80
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
81
|
+
const now = Date.now();
|
|
82
|
+
const prevTime = this.sessionRecreateHistory.get(jid);
|
|
83
|
+
// If no previous recreation or it's been more than an hour
|
|
84
|
+
if (!prevTime || now - prevTime > RECREATE_SESSION_TIMEOUT) {
|
|
85
|
+
this.sessionRecreateHistory.set(jid, now);
|
|
86
|
+
this.statistics.sessionRecreations++;
|
|
87
|
+
return {
|
|
88
|
+
reason: 'retry count > 1 and over an hour since last recreation',
|
|
89
|
+
recreate: true
|
|
90
|
+
};
|
|
54
91
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
this.statistics.failedRetries++;
|
|
119
|
-
this.retryCounters.delete(messageId);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Schedule a phone request with delay
|
|
123
|
-
*/
|
|
124
|
-
schedulePhoneRequest(messageId, callback, delay = PHONE_REQUEST_DELAY) {
|
|
125
|
-
// Cancel any existing request for this message
|
|
126
|
-
this.cancelPendingPhoneRequest(messageId);
|
|
127
|
-
this.pendingPhoneRequests[messageId] = setTimeout(() => {
|
|
128
|
-
delete this.pendingPhoneRequests[messageId];
|
|
129
|
-
this.statistics.phoneRequests++;
|
|
130
|
-
callback();
|
|
131
|
-
}, delay);
|
|
132
|
-
this.logger.debug(`Scheduled phone request for message ${messageId} with ${delay}ms delay`);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Cancel pending phone request
|
|
136
|
-
*/
|
|
137
|
-
cancelPendingPhoneRequest(messageId) {
|
|
138
|
-
const timeout = this.pendingPhoneRequests[messageId];
|
|
139
|
-
if (timeout) {
|
|
140
|
-
clearTimeout(timeout);
|
|
141
|
-
delete this.pendingPhoneRequests[messageId];
|
|
142
|
-
this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
keyToString(key) {
|
|
146
|
-
return `${key.to}:${key.id}`;
|
|
92
|
+
return {
|
|
93
|
+
reason: '',
|
|
94
|
+
recreate: false
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Increment retry counter for a message
|
|
99
|
+
*/
|
|
100
|
+
incrementRetryCount(messageId) {
|
|
101
|
+
this.retryCounters.set(messageId, (this.retryCounters.get(messageId) || 0) + 1);
|
|
102
|
+
this.statistics.totalRetries++;
|
|
103
|
+
return this.retryCounters.get(messageId);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get retry count for a message
|
|
107
|
+
*/
|
|
108
|
+
getRetryCount(messageId) {
|
|
109
|
+
return this.retryCounters.get(messageId) || 0;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Check if message has exceeded maximum retry attempts
|
|
113
|
+
*/
|
|
114
|
+
hasExceededMaxRetries(messageId) {
|
|
115
|
+
return this.getRetryCount(messageId) >= this.maxMsgRetryCount;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Mark retry as successful
|
|
119
|
+
*/
|
|
120
|
+
markRetrySuccess(messageId) {
|
|
121
|
+
this.statistics.successfulRetries++;
|
|
122
|
+
// Clean up retry counter for successful message
|
|
123
|
+
this.retryCounters.delete(messageId);
|
|
124
|
+
this.cancelPendingPhoneRequest(messageId);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Mark retry as failed
|
|
128
|
+
*/
|
|
129
|
+
markRetryFailed(messageId) {
|
|
130
|
+
this.statistics.failedRetries++;
|
|
131
|
+
this.retryCounters.delete(messageId);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Schedule a phone request with delay
|
|
135
|
+
*/
|
|
136
|
+
schedulePhoneRequest(messageId, callback, delay = PHONE_REQUEST_DELAY) {
|
|
137
|
+
// Cancel any existing request for this message
|
|
138
|
+
this.cancelPendingPhoneRequest(messageId);
|
|
139
|
+
this.pendingPhoneRequests[messageId] = setTimeout(() => {
|
|
140
|
+
delete this.pendingPhoneRequests[messageId];
|
|
141
|
+
this.statistics.phoneRequests++;
|
|
142
|
+
callback();
|
|
143
|
+
}, delay);
|
|
144
|
+
this.logger.debug(`Scheduled phone request for message ${messageId} with ${delay}ms delay`);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Cancel pending phone request
|
|
148
|
+
*/
|
|
149
|
+
cancelPendingPhoneRequest(messageId) {
|
|
150
|
+
const timeout = this.pendingPhoneRequests[messageId];
|
|
151
|
+
if (timeout) {
|
|
152
|
+
clearTimeout(timeout);
|
|
153
|
+
delete this.pendingPhoneRequests[messageId];
|
|
154
|
+
this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
|
|
147
155
|
}
|
|
156
|
+
}
|
|
157
|
+
keyToString(key) {
|
|
158
|
+
return `${key.to}:${key.id}`;
|
|
159
|
+
}
|
|
148
160
|
}
|
|
149
161
|
//# sourceMappingURL=message-retry-manager.js.map
|