@realvare/based 2.7.61 → 2.7.70
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 +25 -114
- package/WAProto/WAProto.proto +1073 -244
- package/WAProto/index.d.ts +16282 -8183
- package/WAProto/index.js +76605 -50628
- package/engine-requirements.js +10 -10
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +1 -1
- package/lib/Defaults/index.js +5 -5
- package/lib/Socket/chats.js +53 -16
- package/lib/Socket/groups.js +53 -9
- package/lib/Socket/messages-recv.js +1298 -1237
- package/lib/Socket/messages-send.js +350 -456
- package/lib/Socket/socket.js +1 -1
- package/lib/Socket/usync.js +57 -4
- package/lib/Store/make-in-memory-store.js +28 -15
- package/lib/Types/Message.d.ts +316 -6
- package/lib/Types/Message.js +1 -1
- package/lib/Utils/cache-manager.d.ts +16 -0
- package/lib/Utils/cache-manager.js +20 -4
- package/lib/Utils/chat-utils.js +17 -13
- package/lib/Utils/decode-wa-message.js +1 -11
- package/lib/Utils/event-buffer.js +103 -2
- package/lib/Utils/generics.js +4 -5
- package/lib/Utils/index.d.ts +5 -0
- package/lib/Utils/index.js +3 -0
- package/lib/Utils/jid-validation.d.ts +2 -0
- package/lib/Utils/jid-validation.js +36 -5
- package/lib/Utils/link-preview.js +38 -28
- package/lib/Utils/messages-media.js +21 -52
- package/lib/Utils/messages.js +540 -23
- package/lib/Utils/performance-config.d.ts +2 -0
- package/lib/Utils/performance-config.js +16 -7
- package/lib/Utils/process-message.js +124 -12
- package/lib/Utils/rate-limiter.js +15 -20
- package/lib/WABinary/jid-utils.js +257 -5
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +75 -5
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +59 -6
- package/lib/WAUSync/USyncQuery.js +64 -6
- package/lib/index.d.ts +1 -0
- package/lib/index.js +5 -2
- package/package.json +7 -13
- package/WAProto/index.ts.ts +0 -53473
package/lib/Socket/socket.js
CHANGED
package/lib/Socket/usync.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.makeUSyncSocket = void 0;
|
|
|
4
4
|
const boom_1 = require("@hapi/boom");
|
|
5
5
|
const WABinary_1 = require("../WABinary");
|
|
6
6
|
const socket_1 = require("./socket");
|
|
7
|
+
const retry_1 = require("../Utils/retry");
|
|
7
8
|
const makeUSyncSocket = (config) => {
|
|
8
9
|
const sock = (0, socket_1.makeSocket)(config);
|
|
9
10
|
const { generateMessageTag, query, } = sock;
|
|
@@ -11,9 +12,46 @@ const makeUSyncSocket = (config) => {
|
|
|
11
12
|
if (usyncQuery.protocols.length === 0) {
|
|
12
13
|
throw new boom_1.Boom('USyncQuery must have at least one protocol');
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
//
|
|
16
|
-
const validUsers =
|
|
15
|
+
|
|
16
|
+
// Validate users and filter out invalid ones
|
|
17
|
+
const validUsers = [];
|
|
18
|
+
const invalidUsers = [];
|
|
19
|
+
|
|
20
|
+
for (const user of usyncQuery.users) {
|
|
21
|
+
// Check if user has valid identifier (either id or phone)
|
|
22
|
+
if (user.id || user.phone) {
|
|
23
|
+
// Additional validation for JID format if id is provided
|
|
24
|
+
if (user.id) {
|
|
25
|
+
// Check if it's a valid JID format (user@server)
|
|
26
|
+
const decodedJid = (0, WABinary_1.jidDecode)(user.id);
|
|
27
|
+
if (decodedJid && decodedJid.user && decodedJid.server) {
|
|
28
|
+
validUsers.push(user);
|
|
29
|
+
} else {
|
|
30
|
+
invalidUsers.push(user);
|
|
31
|
+
}
|
|
32
|
+
} else if (user.phone && typeof user.phone === 'string' && user.phone.length > 0) {
|
|
33
|
+
validUsers.push(user);
|
|
34
|
+
} else {
|
|
35
|
+
invalidUsers.push(user);
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
invalidUsers.push(user);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Log warning for invalid users
|
|
43
|
+
if (invalidUsers.length > 0) {
|
|
44
|
+
config.logger?.warn({
|
|
45
|
+
invalidUsers: invalidUsers.map(u => ({ id: u.id, phone: u.phone })),
|
|
46
|
+
totalUsers: usyncQuery.users.length,
|
|
47
|
+
validUsers: validUsers.length
|
|
48
|
+
}, `Found ${invalidUsers.length} invalid users in USync query, they will be excluded`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Throw warning if no valid users found
|
|
52
|
+
if (validUsers.length === 0) {
|
|
53
|
+
throw new boom_1.Boom('No valid users found in USync query', { statusCode: 400 });
|
|
54
|
+
}
|
|
17
55
|
const userNodes = validUsers.map((user) => {
|
|
18
56
|
return {
|
|
19
57
|
tag: 'user',
|
|
@@ -59,7 +97,22 @@ const makeUSyncSocket = (config) => {
|
|
|
59
97
|
}
|
|
60
98
|
],
|
|
61
99
|
};
|
|
62
|
-
const result = await query(iq)
|
|
100
|
+
const result = await (0, retry_1.retryWithBackoff)(() => query(iq), {
|
|
101
|
+
retries: 2,
|
|
102
|
+
baseMs: 2000,
|
|
103
|
+
maxMs: 10000,
|
|
104
|
+
jitter: true,
|
|
105
|
+
timeoutPerAttemptMs: 15000,
|
|
106
|
+
shouldRetry: (err) => {
|
|
107
|
+
if (err.message.includes('WebSocket is not open')) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
var _a;
|
|
111
|
+
const status = ((_a = err.output) === null || _a === void 0 ? void 0 : _a.statusCode) || (err === null || err === void 0 ? void 0 : err.statusCode);
|
|
112
|
+
return !status || (status >= 500 || status === 408 || status === 429);
|
|
113
|
+
},
|
|
114
|
+
onRetry: (err, n) => sock.logger.warn({ err, attempt: n }, 'retrying usync query')
|
|
115
|
+
});
|
|
63
116
|
return usyncQuery.parseUSyncQueryResult(result);
|
|
64
117
|
};
|
|
65
118
|
return {
|
|
@@ -76,8 +76,17 @@ exports.default = (config) => {
|
|
|
76
76
|
});
|
|
77
77
|
ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
|
|
78
78
|
if (syncType === WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
// Handle ON_DEMAND sync as incremental updates without clearing existing data
|
|
80
|
+
const chatsAdded = chats.insertIfAbsent(...newChats).length;
|
|
81
|
+
logger.debug({ chatsAdded, syncType: 'ON_DEMAND' }, 'synced chats on-demand');
|
|
82
|
+
const oldContacts = contactsUpsert(newContacts);
|
|
83
|
+
// Process new messages without clearing existing ones
|
|
84
|
+
for (const msg of newMessages) {
|
|
85
|
+
const key = (0, Utils_1.getMessageKey)(msg);
|
|
86
|
+
messages[key.id] = msg;
|
|
87
|
+
}
|
|
88
|
+
logger.debug({ messagesAdded: newMessages.length, syncType: 'ON_DEMAND' }, 'synced messages on-demand');
|
|
89
|
+
return;
|
|
81
90
|
}
|
|
82
91
|
if (isLatest) {
|
|
83
92
|
chats.clear();
|
|
@@ -129,7 +138,10 @@ exports.default = (config) => {
|
|
|
129
138
|
Object.assign(contacts[contact.id], contact);
|
|
130
139
|
}
|
|
131
140
|
else {
|
|
132
|
-
|
|
141
|
+
// Create new contact if it doesn't exist or lookup failed
|
|
142
|
+
const newContact = { id: update.id, ...update };
|
|
143
|
+
contacts[update.id] = newContact;
|
|
144
|
+
logger.debug({ update }, 'created new contact from update');
|
|
133
145
|
}
|
|
134
146
|
}
|
|
135
147
|
});
|
|
@@ -146,7 +158,9 @@ exports.default = (config) => {
|
|
|
146
158
|
Object.assign(chat, update);
|
|
147
159
|
});
|
|
148
160
|
if (!result) {
|
|
149
|
-
|
|
161
|
+
// Create new chat if it doesn't exist
|
|
162
|
+
chats.upsert({ id: update.id, ...update });
|
|
163
|
+
logger.debug({ update }, 'created new chat from update');
|
|
150
164
|
}
|
|
151
165
|
}
|
|
152
166
|
});
|
|
@@ -169,7 +183,7 @@ exports.default = (config) => {
|
|
|
169
183
|
labelAssociations.delete(association);
|
|
170
184
|
break;
|
|
171
185
|
default:
|
|
172
|
-
|
|
186
|
+
logger.warn({ type }, `unknown operation type [${type}]`);
|
|
173
187
|
}
|
|
174
188
|
});
|
|
175
189
|
ev.on('presence.update', ({ id, presences: update }) => {
|
|
@@ -243,29 +257,28 @@ exports.default = (config) => {
|
|
|
243
257
|
Object.assign(groupMetadata[id], update);
|
|
244
258
|
}
|
|
245
259
|
else {
|
|
246
|
-
|
|
260
|
+
// Create new group metadata if it doesn't exist
|
|
261
|
+
groupMetadata[id] = { id, ...update };
|
|
262
|
+
logger.debug({ update }, 'created new group metadata from update');
|
|
247
263
|
}
|
|
248
264
|
}
|
|
249
265
|
});
|
|
250
266
|
ev.on('group-participants.update', ({ id, participants, action }) => {
|
|
251
267
|
const metadata = groupMetadata[id];
|
|
252
268
|
if (metadata) {
|
|
253
|
-
|
|
254
|
-
case 'add':
|
|
269
|
+
if (action === 'add') {
|
|
255
270
|
metadata.participants.push(...participants.map(id => ({ id, isAdmin: false, isSuperAdmin: false })));
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
case 'promote':
|
|
271
|
+
}
|
|
272
|
+
else if (action === 'demote' || action === 'promote') {
|
|
259
273
|
for (const participant of metadata.participants) {
|
|
260
274
|
if (participants.includes(participant.id)) {
|
|
261
275
|
participant.isAdmin = action === 'promote';
|
|
262
276
|
}
|
|
263
277
|
}
|
|
264
|
-
|
|
265
|
-
|
|
278
|
+
}
|
|
279
|
+
else if (action === 'remove') {
|
|
266
280
|
metadata.participants = metadata.participants.filter(p => !participants.includes(p.id));
|
|
267
|
-
|
|
268
|
-
}
|
|
281
|
+
}
|
|
269
282
|
}
|
|
270
283
|
});
|
|
271
284
|
ev.on('message-receipt.update', updates => {
|
package/lib/Types/Message.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export type WAMessageKey = proto.IMessageKey & {
|
|
|
18
18
|
senderPn?: string;
|
|
19
19
|
senderLid?: string;
|
|
20
20
|
participantLid?: string;
|
|
21
|
+
remoteLid?: string;
|
|
22
|
+
remoteJidNormalized?: string;
|
|
21
23
|
server_id?: string;
|
|
22
24
|
isViewOnce?: boolean;
|
|
23
25
|
};
|
|
@@ -31,6 +33,9 @@ export interface StickerPackMessage {
|
|
|
31
33
|
description?: string;
|
|
32
34
|
cover?: WAMediaUpload;
|
|
33
35
|
stickers: Sticker[];
|
|
36
|
+
stickerPackId?: string;
|
|
37
|
+
origin?: 0 | 1 | 2; // FIRST_PARTY = 0, THIRD_PARTY = 1, USER_CREATED = 2
|
|
38
|
+
caption?: string;
|
|
34
39
|
}
|
|
35
40
|
export interface Sticker {
|
|
36
41
|
sticker: WAMediaUpload;
|
|
@@ -102,6 +107,13 @@ type Interactiveable = {
|
|
|
102
107
|
title?: string;
|
|
103
108
|
subtitle?: string;
|
|
104
109
|
media?: boolean;
|
|
110
|
+
/** Footer with optional audio attachment */
|
|
111
|
+
footer?: string | {
|
|
112
|
+
text: string;
|
|
113
|
+
audio?: WAMediaUpload;
|
|
114
|
+
};
|
|
115
|
+
/** Product message in header */
|
|
116
|
+
headerProduct?: WASendableProduct;
|
|
105
117
|
};
|
|
106
118
|
type Shopable = {
|
|
107
119
|
shop?: proto.Message.InteractiveMessage.ShopMessage.Surface;
|
|
@@ -110,9 +122,26 @@ type Shopable = {
|
|
|
110
122
|
subtitle?: string;
|
|
111
123
|
media?: boolean;
|
|
112
124
|
};
|
|
125
|
+
type Collectionable = {
|
|
126
|
+
collection?: {
|
|
127
|
+
bizJid: string;
|
|
128
|
+
id: string;
|
|
129
|
+
messageVersion?: number;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
type Invoiceable = {
|
|
133
|
+
invoice?: {
|
|
134
|
+
note: string;
|
|
135
|
+
token: string;
|
|
136
|
+
attachmentType?: 0 | 1; // 0 = IMAGE, 1 = PDF
|
|
137
|
+
attachment?: WAMediaUpload;
|
|
138
|
+
};
|
|
139
|
+
};
|
|
113
140
|
type Cardsable = {
|
|
114
141
|
cards?: CarouselCard[];
|
|
115
142
|
subtitle?: string;
|
|
143
|
+
/** Carousel card type: 1 = HSCROLL_CARDS, 2 = ALBUM_IMAGE */
|
|
144
|
+
carouselCardType?: 1 | 2;
|
|
116
145
|
};
|
|
117
146
|
|
|
118
147
|
type CarouselCard = {
|
|
@@ -164,7 +193,7 @@ export type AnyMediaMessageContent = (({
|
|
|
164
193
|
image: WAMediaUpload;
|
|
165
194
|
caption?: string;
|
|
166
195
|
jpegThumbnail?: string;
|
|
167
|
-
} & Mentionable & Contextable & Buttonable & Templatable & Interactiveable & Shopable & Cardsable & WithDimensions) | ({
|
|
196
|
+
} & Mentionable & Contextable & Buttonable & Templatable & Interactiveable & Shopable & Collectionable & Invoiceable & Cardsable & WithDimensions) | ({
|
|
168
197
|
video: WAMediaUpload;
|
|
169
198
|
caption?: string;
|
|
170
199
|
gifPlayback?: boolean;
|
|
@@ -192,6 +221,7 @@ export type ButtonReplyInfo = {
|
|
|
192
221
|
displayText: string;
|
|
193
222
|
id: string;
|
|
194
223
|
index: number;
|
|
224
|
+
carouselCardIndex?: number; // For carousel button replies
|
|
195
225
|
};
|
|
196
226
|
export type GroupInviteInfo = {
|
|
197
227
|
inviteCode: string;
|
|
@@ -235,6 +265,96 @@ export type EventsInfo = {
|
|
|
235
265
|
startTime?: number;
|
|
236
266
|
messageSecret?: Uint8Array;
|
|
237
267
|
};
|
|
268
|
+
export type CommentInfo = {
|
|
269
|
+
message: proto.IMessage;
|
|
270
|
+
targetMessageKey: WAMessageKey;
|
|
271
|
+
};
|
|
272
|
+
export type QuestionInfo = {
|
|
273
|
+
text: string;
|
|
274
|
+
contextInfo?: proto.IContextInfo;
|
|
275
|
+
};
|
|
276
|
+
export type QuestionResponseInfo = {
|
|
277
|
+
key: WAMessageKey;
|
|
278
|
+
text: string;
|
|
279
|
+
};
|
|
280
|
+
export type StatusQuestionAnswerInfo = {
|
|
281
|
+
key: WAMessageKey;
|
|
282
|
+
text: string;
|
|
283
|
+
};
|
|
284
|
+
export type StatusQuotedInfo = {
|
|
285
|
+
type: proto.Message.StatusQuotedMessage.StatusQuotedMessageType;
|
|
286
|
+
text: string;
|
|
287
|
+
thumbnail?: Buffer;
|
|
288
|
+
originalStatusId?: WAMessageKey;
|
|
289
|
+
};
|
|
290
|
+
export type StatusStickerInteractionInfo = {
|
|
291
|
+
key: WAMessageKey;
|
|
292
|
+
stickerKey: string;
|
|
293
|
+
type: proto.Message.StatusStickerInteractionMessage.StatusStickerType;
|
|
294
|
+
};
|
|
295
|
+
export type PollMessageOptionsV4 = PollMessageOptions & { pollType: proto.Message.PollType; };
|
|
296
|
+
export type PollMessageOptionsV5 = PollMessageOptions & { pollType: proto.Message.PollType; };
|
|
297
|
+
export type PollResultSnapshotMessageV3 = {
|
|
298
|
+
pollCreationMessageKey: WAMessageKey;
|
|
299
|
+
pollResult?: {
|
|
300
|
+
vote: {
|
|
301
|
+
selectedOptions: Uint8Array[];
|
|
302
|
+
};
|
|
303
|
+
senderTimestampMs: number;
|
|
304
|
+
};
|
|
305
|
+
selectedOptions?: Uint8Array[];
|
|
306
|
+
contextInfo?: proto.IContextInfo;
|
|
307
|
+
pollType?: proto.Message.PollType;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
export type TemplateButton = proto.TemplateButton;
|
|
311
|
+
|
|
312
|
+
export type HydratedFourRowTemplateInfo = {
|
|
313
|
+
text?: string;
|
|
314
|
+
footer?: string;
|
|
315
|
+
header?: InteractiveMessageHeader;
|
|
316
|
+
buttons: TemplateButton[];
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
export type FourRowTemplateInfo = {
|
|
320
|
+
text?: string;
|
|
321
|
+
footer?: string;
|
|
322
|
+
header?: InteractiveMessageHeader;
|
|
323
|
+
buttons: TemplateButton[];
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
export type RichResponseInfo = {
|
|
327
|
+
messageType?: proto.AIRichResponseMessageType;
|
|
328
|
+
submessages?: proto.Message.AIRichResponseSubMessage[];
|
|
329
|
+
unifiedResponse?: proto.Message.AIRichResponseUnifiedResponse;
|
|
330
|
+
contextInfo?: proto.IContextInfo;
|
|
331
|
+
};
|
|
332
|
+
export type EventResponseInfo = {
|
|
333
|
+
response: proto.Message.EventResponseMessage.EventResponseType; // GOING = 1, NOT_GOING = 2, MAYBE = 3
|
|
334
|
+
timestampMs?: number;
|
|
335
|
+
extraGuestCount?: number;
|
|
336
|
+
};
|
|
337
|
+
export type StatusMentionInfo = {
|
|
338
|
+
quotedStatus: proto.IMessage;
|
|
339
|
+
};
|
|
340
|
+
export type GroupStatusInfo = {
|
|
341
|
+
message: proto.IMessage;
|
|
342
|
+
};
|
|
343
|
+
export type BotTaskInfo = {
|
|
344
|
+
message: proto.IMessage;
|
|
345
|
+
};
|
|
346
|
+
export type LimitSharingInfo = {
|
|
347
|
+
message: proto.IMessage;
|
|
348
|
+
};
|
|
349
|
+
export type StatusAddYoursInfo = {
|
|
350
|
+
message: proto.IMessage;
|
|
351
|
+
};
|
|
352
|
+
export type BotForwardedInfo = {
|
|
353
|
+
message: proto.IMessage;
|
|
354
|
+
};
|
|
355
|
+
export type EventCoverImageInfo = {
|
|
356
|
+
message: proto.IMessage;
|
|
357
|
+
};
|
|
238
358
|
export type OrderInfo = {
|
|
239
359
|
id: number;
|
|
240
360
|
thumbnail: string;
|
|
@@ -263,7 +383,15 @@ export type AnyRegularMessageContent = (({
|
|
|
263
383
|
text: string;
|
|
264
384
|
linkPreview?: WAUrlInfo | null;
|
|
265
385
|
} & Mentionable & Contextable & Buttonable & Templatable & Interactiveable & Shopable & Cardsable & Listable & Editable) | AnyMediaMessageContent | ({
|
|
386
|
+
template: FourRowTemplateInfo | HydratedFourRowTemplateInfo;
|
|
387
|
+
} & Mentionable & Contextable & Buttonable & Templatable & Interactiveable & Shopable & Cardsable & Listable & Editable) | ({
|
|
266
388
|
poll: PollMessageOptions;
|
|
389
|
+
} & Mentionable & Contextable & Buttonable & Templatable & Editable) | ({
|
|
390
|
+
pollV4: PollMessageOptionsV4;
|
|
391
|
+
} & Mentionable & Contextable & Buttonable & Templatable & Editable) | ({
|
|
392
|
+
pollV5: PollMessageOptionsV5;
|
|
393
|
+
} & Mentionable & Contextable & Buttonable & Templatable & Editable) | ({
|
|
394
|
+
pollResultSnapshotV3: PollResultSnapshotMessageV3;
|
|
267
395
|
} & Mentionable & Contextable & Buttonable & Templatable & Editable) | {
|
|
268
396
|
contacts: {
|
|
269
397
|
displayName?: string;
|
|
@@ -281,12 +409,17 @@ export type AnyRegularMessageContent = (({
|
|
|
281
409
|
} | {
|
|
282
410
|
listReply: Omit<proto.Message.IListResponseMessage, 'contextInfo'>;
|
|
283
411
|
} | {
|
|
284
|
-
pin: WAMessageKey
|
|
285
|
-
|
|
412
|
+
pin: WAMessageKey | {
|
|
413
|
+
key: WAMessageKey;
|
|
414
|
+
type?: 1 | 2; // 1 = PIN_FOR_ALL, 2 = UNPIN_FOR_ALL
|
|
415
|
+
time?: number; // Duration in seconds (24 hours = 86400, 7 days = 604800, 30 days = 2592000)
|
|
416
|
+
};
|
|
417
|
+
type?: 1 | 2; // 1 = PIN_FOR_ALL, 2 = UNPIN_FOR_ALL (only used if pin is WAMessageKey)
|
|
286
418
|
/**
|
|
287
|
-
* 24 hours, 7 days, 30 days
|
|
419
|
+
* Duration in seconds for pin (24 hours = 86400, 7 days = 604800, 30 days = 2592000)
|
|
420
|
+
* Only used when type = 1 (PIN_FOR_ALL)
|
|
288
421
|
*/
|
|
289
|
-
time?:
|
|
422
|
+
time?: number;
|
|
290
423
|
} | {
|
|
291
424
|
keep: WAMessageKey;
|
|
292
425
|
type: number;
|
|
@@ -300,6 +433,168 @@ export type AnyRegularMessageContent = (({
|
|
|
300
433
|
requestPayment: RequestPaymentInfo;
|
|
301
434
|
} | {
|
|
302
435
|
event: EventsInfo;
|
|
436
|
+
} | {
|
|
437
|
+
comment: CommentInfo;
|
|
438
|
+
} | {
|
|
439
|
+
question: QuestionInfo;
|
|
440
|
+
} | {
|
|
441
|
+
questionResponse: QuestionResponseInfo;
|
|
442
|
+
} | {
|
|
443
|
+
statusQuestionAnswer: StatusQuestionAnswerInfo;
|
|
444
|
+
} | {
|
|
445
|
+
statusQuoted: StatusQuotedInfo;
|
|
446
|
+
} | {
|
|
447
|
+
statusStickerInteraction: StatusStickerInteractionInfo;
|
|
448
|
+
} | {
|
|
449
|
+
richResponse: RichResponseInfo;
|
|
450
|
+
} | {
|
|
451
|
+
eventResponse: EventResponseInfo;
|
|
452
|
+
} | {
|
|
453
|
+
statusMention: StatusMentionInfo;
|
|
454
|
+
} | {
|
|
455
|
+
groupStatus: GroupStatusInfo;
|
|
456
|
+
} | {
|
|
457
|
+
botTask: BotTaskInfo;
|
|
458
|
+
} | {
|
|
459
|
+
limitSharing: LimitSharingInfo;
|
|
460
|
+
} | {
|
|
461
|
+
statusAddYours: StatusAddYoursInfo;
|
|
462
|
+
} | {
|
|
463
|
+
botForwarded: BotForwardedInfo;
|
|
464
|
+
} | {
|
|
465
|
+
eventCoverImage: EventCoverImageInfo;
|
|
466
|
+
} | {
|
|
467
|
+
bCall: {
|
|
468
|
+
sessionId: string;
|
|
469
|
+
mediaType?: 0 | 1 | 2; // UNKNOWN = 0, AUDIO = 1, VIDEO = 2
|
|
470
|
+
masterKey?: Uint8Array;
|
|
471
|
+
caption?: string;
|
|
472
|
+
};
|
|
473
|
+
} | {
|
|
474
|
+
callLog: {
|
|
475
|
+
isVideo?: boolean;
|
|
476
|
+
callOutcome?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7; // CONNECTED, MISSED, FAILED, etc.
|
|
477
|
+
durationSecs?: number;
|
|
478
|
+
callType?: 0 | 1 | 2; // REGULAR = 0, SCHEDULED_CALL = 1, VOICE_CHAT = 2
|
|
479
|
+
participants?: Array<{
|
|
480
|
+
jid: string;
|
|
481
|
+
callOutcome?: number;
|
|
482
|
+
}>;
|
|
483
|
+
};
|
|
484
|
+
} | {
|
|
485
|
+
encComment: {
|
|
486
|
+
targetMessageKey: WAMessageKey;
|
|
487
|
+
encPayload: Uint8Array;
|
|
488
|
+
encIv: Uint8Array;
|
|
489
|
+
};
|
|
490
|
+
} | {
|
|
491
|
+
encEventResponse: {
|
|
492
|
+
eventCreationMessageKey: WAMessageKey;
|
|
493
|
+
encPayload: Uint8Array;
|
|
494
|
+
encIv: Uint8Array;
|
|
495
|
+
};
|
|
496
|
+
} | {
|
|
497
|
+
messageHistoryBundle: {
|
|
498
|
+
mimetype?: string;
|
|
499
|
+
media?: WAMediaUpload;
|
|
500
|
+
contextInfo?: proto.IContextInfo;
|
|
501
|
+
messageHistoryMetadata?: {
|
|
502
|
+
historyReceivers?: string[];
|
|
503
|
+
oldestMessageTimestamp?: number;
|
|
504
|
+
messageCount?: number;
|
|
505
|
+
};
|
|
506
|
+
};
|
|
507
|
+
} | {
|
|
508
|
+
messageHistoryNotice: {
|
|
509
|
+
contextInfo?: proto.IContextInfo;
|
|
510
|
+
messageHistoryMetadata?: {
|
|
511
|
+
historyReceivers?: string[];
|
|
512
|
+
oldestMessageTimestamp?: number;
|
|
513
|
+
messageCount?: number;
|
|
514
|
+
};
|
|
515
|
+
};
|
|
516
|
+
} | {
|
|
517
|
+
inviteFollower: {
|
|
518
|
+
newsletterJid: string;
|
|
519
|
+
newsletterName: string;
|
|
520
|
+
thumbnail?: Buffer;
|
|
521
|
+
caption?: string;
|
|
522
|
+
contextInfo?: proto.IContextInfo;
|
|
523
|
+
};
|
|
524
|
+
} | {
|
|
525
|
+
placeholder: {
|
|
526
|
+
type?: 0; // MASK_LINKED_DEVICES = 0
|
|
527
|
+
};
|
|
528
|
+
} | {
|
|
529
|
+
secretEncrypted: {
|
|
530
|
+
targetMessageKey: WAMessageKey;
|
|
531
|
+
encPayload: Uint8Array;
|
|
532
|
+
encIv: Uint8Array;
|
|
533
|
+
secretEncType?: 0 | 1 | 2; // UNKNOWN = 0, EVENT_EDIT = 1, MESSAGE_EDIT = 2
|
|
534
|
+
};
|
|
535
|
+
} | {
|
|
536
|
+
statusNotification: {
|
|
537
|
+
responseMessageKey?: WAMessageKey;
|
|
538
|
+
originalMessageKey?: WAMessageKey;
|
|
539
|
+
type?: 0 | 1 | 2 | 3; // UNKNOWN = 0, STATUS_ADD_YOURS = 1, STATUS_RESHARE = 2, STATUS_QUESTION_ANSWER_RESHARE = 3
|
|
540
|
+
};
|
|
541
|
+
} | {
|
|
542
|
+
stickerSyncRMR: {
|
|
543
|
+
filehash?: string[];
|
|
544
|
+
rmrSource?: string;
|
|
545
|
+
requestTimestamp?: number;
|
|
546
|
+
};
|
|
547
|
+
} | {
|
|
548
|
+
sendPayment: {
|
|
549
|
+
requestMessageKey: WAMessageKey;
|
|
550
|
+
noteMessage?: proto.IMessage;
|
|
551
|
+
background?: proto.IPaymentBackground;
|
|
552
|
+
transactionData?: string;
|
|
553
|
+
};
|
|
554
|
+
} | {
|
|
555
|
+
declinePayment: {
|
|
556
|
+
key: WAMessageKey;
|
|
557
|
+
};
|
|
558
|
+
} | {
|
|
559
|
+
cancelPayment: {
|
|
560
|
+
key: WAMessageKey;
|
|
561
|
+
};
|
|
562
|
+
} | {
|
|
563
|
+
scheduledCallEdit: {
|
|
564
|
+
key: WAMessageKey;
|
|
565
|
+
editType?: 0 | 1; // UNKNOWN = 0, CANCEL = 1
|
|
566
|
+
};
|
|
567
|
+
} | {
|
|
568
|
+
pollResultSnapshot: {
|
|
569
|
+
name: string;
|
|
570
|
+
pollVotes?: Array<{
|
|
571
|
+
optionName: string;
|
|
572
|
+
optionVoteCount: number;
|
|
573
|
+
}>;
|
|
574
|
+
contextInfo?: proto.IContextInfo;
|
|
575
|
+
pollType?: 0 | 1; // POLL = 0, QUIZ = 1
|
|
576
|
+
};
|
|
577
|
+
} | {
|
|
578
|
+
pollUpdate: {
|
|
579
|
+
pollCreationMessageKey: WAMessageKey;
|
|
580
|
+
vote?: {
|
|
581
|
+
encPayload: Uint8Array;
|
|
582
|
+
encIv: Uint8Array;
|
|
583
|
+
};
|
|
584
|
+
metadata?: {};
|
|
585
|
+
senderTimestampMs?: number;
|
|
586
|
+
};
|
|
587
|
+
} | {
|
|
588
|
+
deviceSent: {
|
|
589
|
+
destinationJid: string;
|
|
590
|
+
message: AnyRegularMessageContent;
|
|
591
|
+
phash?: string;
|
|
592
|
+
};
|
|
593
|
+
} | {
|
|
594
|
+
chat: {
|
|
595
|
+
displayName: string;
|
|
596
|
+
id: string;
|
|
597
|
+
};
|
|
303
598
|
} | {
|
|
304
599
|
order: OrderInfo;
|
|
305
600
|
} | {
|
|
@@ -316,7 +611,22 @@ export type AnyRegularMessageContent = (({
|
|
|
316
611
|
} & Mentionable & Contextable & Interactiveable & Shopable & Cardsable & WithDimensions) | SharePhoneNumber | RequestPhoneNumber | ({
|
|
317
612
|
album: AlbumMedia[];
|
|
318
613
|
caption?: string;
|
|
319
|
-
} & Mentionable & Contextable & Editable) | {
|
|
614
|
+
} & Mentionable & Contextable & Editable) | {
|
|
615
|
+
stickerPack: StickerPackMessage;
|
|
616
|
+
} | {
|
|
617
|
+
interactiveResponse: {
|
|
618
|
+
body?: {
|
|
619
|
+
text: string;
|
|
620
|
+
format?: 0 | 1; // DEFAULT = 0, EXTENSIONS_1 = 1
|
|
621
|
+
};
|
|
622
|
+
nativeFlowResponse?: {
|
|
623
|
+
name: string;
|
|
624
|
+
paramsJson: string;
|
|
625
|
+
version?: number;
|
|
626
|
+
};
|
|
627
|
+
contextInfo?: proto.IContextInfo;
|
|
628
|
+
};
|
|
629
|
+
}) & ViewOnce;
|
|
320
630
|
export type AnyMessageContent = AnyRegularMessageContent | {
|
|
321
631
|
forward: WAMessage;
|
|
322
632
|
force?: boolean;
|
package/lib/Types/Message.js
CHANGED
|
@@ -4,4 +4,4 @@ exports.WAMessageStatus = exports.WAMessageStubType = exports.WAProto = void 0;
|
|
|
4
4
|
const WAProto_1 = require("../../WAProto");
|
|
5
5
|
Object.defineProperty(exports, "WAProto", { enumerable: true, get: function () { return WAProto_1.proto; } });
|
|
6
6
|
exports.WAMessageStubType = WAProto_1.proto.WebMessageInfo.StubType;
|
|
7
|
-
exports.WAMessageStatus = WAProto_1.proto.WebMessageInfo.Status;
|
|
7
|
+
exports.WAMessageStatus = WAProto_1.proto.WebMessageInfo.Status;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare const cacheManager: {
|
|
2
|
+
setMessageStore(msgStore: any): void;
|
|
3
|
+
startMemoryMonitoring(threshold: number): void;
|
|
4
|
+
evictLeastUsed(): void;
|
|
5
|
+
get(cacheName: string, key: string): any;
|
|
6
|
+
set(cacheName: string, key: string, value: any, ttl?: number): any;
|
|
7
|
+
setAsync<T>(cacheName: string, key: string, fetchData: () => Promise<T>, ttl?: number): Promise<any>;
|
|
8
|
+
del(cacheName: string, key: string): any;
|
|
9
|
+
getStats(cacheName: string): any;
|
|
10
|
+
on(event: 'bad_ack', callback: (key: any) => void): void;
|
|
11
|
+
cleanupBadAck(key: any): void;
|
|
12
|
+
shutdown(): void;
|
|
13
|
+
caches?: Record<string, any>;
|
|
14
|
+
};
|
|
15
|
+
export declare const CacheManager: typeof cacheManager;
|
|
16
|
+
export default cacheManager;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CacheManager = exports.default = void 0;
|
|
2
4
|
const NodeCache = require('node-cache');
|
|
3
5
|
const { getPerformanceConfig } = require('./performance-config');
|
|
4
6
|
|
|
@@ -59,8 +61,13 @@ class CacheManager {
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
async setAsync(cacheName, key, fetchData, ttl = undefined) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
try {
|
|
65
|
+
const value = await fetchData();
|
|
66
|
+
return this.set(cacheName, key, value, ttl);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
// If fetchData fails, don't cache the error
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
64
71
|
}
|
|
65
72
|
|
|
66
73
|
del(cacheName, key) {
|
|
@@ -68,7 +75,14 @@ class CacheManager {
|
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
getStats(cacheName) {
|
|
71
|
-
|
|
78
|
+
if (!this.caches || !this.caches[cacheName]) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
return this.caches[cacheName].getStats();
|
|
83
|
+
} catch (error) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
72
86
|
}
|
|
73
87
|
|
|
74
88
|
// Enhanced cleanup for bad ACK entries
|
|
@@ -94,4 +108,6 @@ class CacheManager {
|
|
|
94
108
|
}
|
|
95
109
|
}
|
|
96
110
|
|
|
97
|
-
|
|
111
|
+
const cacheManager = new CacheManager();
|
|
112
|
+
exports.default = cacheManager;
|
|
113
|
+
exports.CacheManager = cacheManager;
|