@ryuhan/baileys 1.0.1 → 1.0.4
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 → README.MD} +16 -30
- package/lib/Defaults/index.js +50 -35
- package/lib/Defaults/ryuhan-version.json +3 -0
- package/lib/Socket/chats.js +147 -87
- package/lib/Socket/messages-recv.js +127 -43
- package/lib/Socket/socket.js +17 -4
- package/lib/Store/make-in-memory-store.js +1 -1
- package/lib/Utils/browser-utils.js +35 -0
- package/lib/Utils/event-buffer.js +2 -2
- package/lib/Utils/generics.js +36 -10
- package/lib/Utils/identity-change-handler.js +52 -0
- package/lib/Utils/index.js +4 -1
- package/lib/Utils/message-retry-manager.js +135 -0
- package/lib/Utils/process-message.js +17 -7
- package/lib/Utils/{baileys-event-stream.js → ryuhan-event-stream.js} +1 -1
- package/lib/Utils/use-multi-file-auth-state.js +0 -2
- package/lib/Utils/validate-connection.js +77 -21
- package/lib/index.js +30 -2
- package/package.json +11 -10
- package/WAProto/index.d.ts +0 -55057
- package/WAProto/index.ts.ts +0 -53473
- package/WAProto/p.html +0 -1
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.d.ts +0 -51
- 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/index.d.ts +0 -2
- package/lib/Socket/Client/types.d.ts +0 -16
- package/lib/Socket/Client/websocket.d.ts +0 -13
- package/lib/Socket/business.d.ts +0 -172
- package/lib/Socket/chats.d.ts +0 -82
- package/lib/Socket/groups.d.ts +0 -124
- package/lib/Socket/index.d.ts +0 -172
- package/lib/Socket/messages-recv.d.ts +0 -161
- package/lib/Socket/messages-send.d.ts +0 -151
- package/lib/Socket/newsletter.d.ts +0 -136
- package/lib/Socket/socket.d.ts +0 -43
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Store/index.d.ts +0 -2
- 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 -103
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -109
- package/lib/Types/Contact.d.ts +0 -23
- package/lib/Types/Events.d.ts +0 -199
- package/lib/Types/GroupMetadata.d.ts +0 -64
- package/lib/Types/Label.d.ts +0 -35
- package/lib/Types/LabelAssociation.d.ts +0 -29
- package/lib/Types/Message.d.ts +0 -400
- package/lib/Types/Newsletter.d.ts +0 -79
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/Socket.d.ts +0 -119
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/index.d.ts +0 -64
- 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 -70
- package/lib/Utils/crypto.d.ts +0 -40
- package/lib/Utils/decode-wa-message.d.ts +0 -35
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -89
- package/lib/Utils/history.d.ts +0 -19
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -11
- 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 -120
- package/lib/Utils/messages.d.ts +0 -80
- package/lib/Utils/noise-handler.d.ts +0 -19
- package/lib/Utils/process-message.d.ts +0 -42
- package/lib/Utils/signal.d.ts +0 -33
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
- package/lib/Utils/validate-connection.d.ts +0 -10
- package/lib/WABinary/constants.d.ts +0 -27
- package/lib/WABinary/decode.d.ts +0 -6
- package/lib/WABinary/encode.d.ts +0 -2
- package/lib/WABinary/generic-utils.d.ts +0 -14
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -37
- package/lib/WABinary/jid-utils.js.bak +0 -83
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -8
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -2
- 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 -16
|
@@ -16,9 +16,9 @@ const WABinary_1 = require("../WABinary");
|
|
|
16
16
|
const groups_1 = require("./groups");
|
|
17
17
|
const messages_send_1 = require("./messages-send");
|
|
18
18
|
const makeMessagesRecvSocket = (config) => {
|
|
19
|
-
const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid } = config;
|
|
19
|
+
const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid, enableAutoSessionRecreation } = config;
|
|
20
20
|
const sock = (0, messages_send_1.makeMessagesSocket)(config);
|
|
21
|
-
const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, groupMetadata, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, createParticipantNodes, getUSyncDevices, sendPeerDataOperationMessage, } = sock;
|
|
21
|
+
const { ev, authState, ws, processingMutex, messageMutex, notificationMutex, receiptMutex, signalRepository, query, upsertMessage, resyncAppState, groupMetadata, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, createParticipantNodes, getUSyncDevices, sendPeerDataOperationMessage, messageRetryManager } = sock;
|
|
22
22
|
/** this mutex ensures that each retryRequest will wait for the previous one to finish */
|
|
23
23
|
const retryMutex = (0, make_mutex_1.makeMutex)();
|
|
24
24
|
const msgRetryCache = config.msgRetryCounterCache || new node_cache_1.default({
|
|
@@ -33,6 +33,8 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
33
33
|
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
34
34
|
useClones: false
|
|
35
35
|
});
|
|
36
|
+
// Debounce identity-change session refreshes per JID to avoid bursts
|
|
37
|
+
const identityAssertDebounce = config.identityAssertDebounceCache || new node_cache_1.default({ stdTTL: 5, useClones: false });
|
|
36
38
|
let sendActiveReceipts = false;
|
|
37
39
|
const sendMessageAck = async ({ tag, attrs, content }, errorCode) => {
|
|
38
40
|
const stanza = {
|
|
@@ -142,21 +144,83 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
142
144
|
const { fullMessage } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '');
|
|
143
145
|
const { key: msgKey } = fullMessage;
|
|
144
146
|
const msgId = msgKey.id;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
|
|
148
|
+
// Use new message retry manager if available
|
|
149
|
+
if (messageRetryManager) {
|
|
150
|
+
// Check if we've exceeded max retries using the new system
|
|
151
|
+
if (messageRetryManager.hasExceededMaxRetries(msgId)) {
|
|
152
|
+
logger.debug({ msgId }, 'reached retry limit with new retry manager, clearing');
|
|
153
|
+
messageRetryManager.markRetryFailed(msgId);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
// Increment retry count using new system
|
|
157
|
+
const retryCount = messageRetryManager.incrementRetryCount(msgId);
|
|
158
|
+
// Use the new retry count for the rest of the logic
|
|
159
|
+
const key = `${msgId}:${msgKey === null || msgKey === void 0 ? void 0 : msgKey.participant}`;
|
|
160
|
+
await msgRetryCache.set(key, retryCount);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
// Fallback to old system
|
|
164
|
+
const key = `${msgId}:${msgKey === null || msgKey === void 0 ? void 0 : msgKey.participant}`;
|
|
165
|
+
let retryCount = msgRetryCache.get(key) || 0;
|
|
166
|
+
if (retryCount >= maxMsgRetryCount) {
|
|
167
|
+
logger.debug({ retryCount, msgId }, 'reached retry limit, clearing');
|
|
168
|
+
msgRetryCache.del(key);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
retryCount += 1;
|
|
172
|
+
msgRetryCache.set(key, retryCount);
|
|
151
173
|
}
|
|
152
|
-
|
|
153
|
-
|
|
174
|
+
|
|
175
|
+
const key = `${msgId}:${msgKey === null || msgKey === void 0 ? void 0 : msgKey.participant}`;
|
|
176
|
+
const retryCount = (await msgRetryCache.get(key)) || 1;
|
|
154
177
|
const { account, signedPreKey, signedIdentityKey: identityKey } = authState.creds;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
178
|
+
const fromJid = node.attrs.from;
|
|
179
|
+
|
|
180
|
+
// Check if we should recreate session
|
|
181
|
+
let shouldRecreateSession = false;
|
|
182
|
+
let recreateReason = '';
|
|
183
|
+
if (enableAutoSessionRecreation && messageRetryManager && retryCount > 1) {
|
|
184
|
+
try {
|
|
185
|
+
// Check if we have a session with this JID
|
|
186
|
+
const sessionId = signalRepository.jidToSignalProtocolAddress(fromJid);
|
|
187
|
+
const hasSession = await signalRepository.validateSession(fromJid);
|
|
188
|
+
const result = messageRetryManager.shouldRecreateSession(fromJid, hasSession.exists);
|
|
189
|
+
shouldRecreateSession = result.recreate;
|
|
190
|
+
recreateReason = result.reason;
|
|
191
|
+
if (shouldRecreateSession) {
|
|
192
|
+
logger.debug({ fromJid, retryCount, reason: recreateReason }, 'recreating session for retry');
|
|
193
|
+
// Delete existing session to force recreation
|
|
194
|
+
await authState.keys.set({ session: { [sessionId]: null } });
|
|
195
|
+
forceIncludeKeys = true;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
logger.warn({ error, fromJid }, 'failed to check session recreation');
|
|
200
|
+
}
|
|
159
201
|
}
|
|
202
|
+
|
|
203
|
+
// Request phone resend on first retry
|
|
204
|
+
if (retryCount <= 2) {
|
|
205
|
+
if (messageRetryManager) {
|
|
206
|
+
// Schedule phone request with delay (like whatsmeow)
|
|
207
|
+
messageRetryManager.schedulePhoneRequest(msgId, async () => {
|
|
208
|
+
try {
|
|
209
|
+
const requestId = await requestPlaceholderResend(msgKey);
|
|
210
|
+
logger.debug(`sendRetryRequest: requested placeholder resend (${requestId}) for message ${msgId} (scheduled)`);
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
logger.warn({ error, msgId }, 'failed to send scheduled phone request');
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
// Fallback to immediate request
|
|
219
|
+
const msgId = await requestPlaceholderResend(msgKey);
|
|
220
|
+
logger.debug(`sendRetryRequest: requested placeholder resend for message ${msgId}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
160
224
|
const deviceIdentity = (0, Utils_1.encodeSignedDeviceIdentity)(account, true);
|
|
161
225
|
await authState.keys.transaction(async () => {
|
|
162
226
|
const receipt = {
|
|
@@ -173,7 +237,8 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
173
237
|
count: retryCount.toString(),
|
|
174
238
|
id: node.attrs.id,
|
|
175
239
|
t: node.attrs.t,
|
|
176
|
-
v: '1'
|
|
240
|
+
v: '1',
|
|
241
|
+
error: '0' // Add error field like blckrose
|
|
177
242
|
}
|
|
178
243
|
},
|
|
179
244
|
{
|
|
@@ -189,7 +254,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
189
254
|
if (node.attrs.participant) {
|
|
190
255
|
receipt.attrs.participant = node.attrs.participant;
|
|
191
256
|
}
|
|
192
|
-
if (retryCount > 1 || forceIncludeKeys) {
|
|
257
|
+
if (retryCount > 1 || forceIncludeKeys || shouldRecreateSession) {
|
|
193
258
|
const { update, preKeys } = await (0, Utils_1.getNextPreKeys)(authState, 1);
|
|
194
259
|
const [keyId] = Object.keys(preKeys);
|
|
195
260
|
const key = preKeys[+keyId];
|
|
@@ -223,35 +288,46 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
223
288
|
}
|
|
224
289
|
}
|
|
225
290
|
else {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
291
|
+
// Use improved identity change handler with debouncing
|
|
292
|
+
const result = await (0, Utils_1.handleIdentityChange)(node, {
|
|
293
|
+
meId: authState.creds.me === null || authState.creds.me === void 0 ? void 0 : authState.creds.me.id,
|
|
294
|
+
meLid: authState.creds.me === null || authState.creds.me === void 0 ? void 0 : authState.creds.me.lid,
|
|
295
|
+
validateSession: signalRepository.validateSession,
|
|
296
|
+
assertSessions,
|
|
297
|
+
debounceCache: identityAssertDebounce,
|
|
298
|
+
logger
|
|
299
|
+
});
|
|
300
|
+
if (result.action === 'no_identity_node') {
|
|
233
301
|
logger.info({ node }, 'unknown encrypt notification');
|
|
234
302
|
}
|
|
235
303
|
}
|
|
236
304
|
};
|
|
237
|
-
const handleGroupNotification = (
|
|
238
|
-
|
|
239
|
-
const
|
|
305
|
+
const handleGroupNotification = (fullNode, child, msg) => {
|
|
306
|
+
// TODO: Support PN/LID (Here is only LID now)
|
|
307
|
+
const actingParticipantLid = fullNode.attrs.participant;
|
|
308
|
+
const actingParticipantPn = fullNode.attrs.participant_pn;
|
|
309
|
+
const affectedParticipantLid = (0, WABinary_1.getBinaryNodeChild)(child, 'participant') === null || (0, WABinary_1.getBinaryNodeChild)(child, 'participant') === void 0 ? void 0 : (0, WABinary_1.getBinaryNodeChild)(child, 'participant').attrs.jid || actingParticipantLid;
|
|
310
|
+
const affectedParticipantPn = (0, WABinary_1.getBinaryNodeChild)(child, 'participant') === null || (0, WABinary_1.getBinaryNodeChild)(child, 'participant') === void 0 ? void 0 : (0, WABinary_1.getBinaryNodeChild)(child, 'participant').attrs.phone_number || actingParticipantPn;
|
|
240
311
|
switch (child === null || child === void 0 ? void 0 : child.tag) {
|
|
241
312
|
case 'create':
|
|
242
313
|
const metadata = (0, groups_1.extractGroupMetadata)(child);
|
|
243
314
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CREATE;
|
|
244
315
|
msg.messageStubParameters = [metadata.subject];
|
|
245
|
-
msg.key = { participant: metadata.owner };
|
|
246
|
-
ev.emit('chats.upsert', [
|
|
316
|
+
msg.key = { participant: metadata.owner, participantAlt: metadata.ownerPn };
|
|
317
|
+
ev.emit('chats.upsert', [
|
|
318
|
+
{
|
|
247
319
|
id: metadata.id,
|
|
248
320
|
name: metadata.subject,
|
|
249
|
-
conversationTimestamp: metadata.creation
|
|
250
|
-
}
|
|
251
|
-
|
|
321
|
+
conversationTimestamp: metadata.creation
|
|
322
|
+
}
|
|
323
|
+
]);
|
|
324
|
+
ev.emit('groups.upsert', [
|
|
325
|
+
{
|
|
252
326
|
...metadata,
|
|
253
|
-
author:
|
|
254
|
-
|
|
327
|
+
author: actingParticipantLid,
|
|
328
|
+
authorPn: actingParticipantPn
|
|
329
|
+
}
|
|
330
|
+
]);
|
|
255
331
|
break;
|
|
256
332
|
case 'ephemeral':
|
|
257
333
|
case 'not_ephemeral':
|
|
@@ -274,22 +350,31 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
274
350
|
case 'leave':
|
|
275
351
|
const stubType = `GROUP_PARTICIPANT_${child.tag.toUpperCase()}`;
|
|
276
352
|
msg.messageStubType = Types_1.WAMessageStubType[stubType];
|
|
277
|
-
const participants = (0, WABinary_1.getBinaryNodeChildren)(child, 'participant').map(
|
|
353
|
+
const participants = (0, WABinary_1.getBinaryNodeChildren)(child, 'participant').map(({ attrs }) => {
|
|
354
|
+
// TODO: Store LID MAPPINGS
|
|
355
|
+
return {
|
|
356
|
+
id: attrs.jid,
|
|
357
|
+
phoneNumber: (0, WABinary_1.isLidUser)(attrs.jid) && (0, WABinary_1.isPnUser)(attrs.phone_number) ? attrs.phone_number : undefined,
|
|
358
|
+
lid: (0, WABinary_1.isPnUser)(attrs.jid) && (0, WABinary_1.isLidUser)(attrs.lid) ? attrs.lid : undefined,
|
|
359
|
+
admin: (attrs.type || null)
|
|
360
|
+
};
|
|
361
|
+
});
|
|
278
362
|
if (participants.length === 1 &&
|
|
279
363
|
// if recv. "remove" message and sender removed themselves
|
|
280
364
|
// mark as left
|
|
281
|
-
(0, WABinary_1.areJidsSameUser)(participants[0],
|
|
365
|
+
((0, WABinary_1.areJidsSameUser)(participants[0].id, actingParticipantLid) ||
|
|
366
|
+
(0, WABinary_1.areJidsSameUser)(participants[0].id, actingParticipantPn)) &&
|
|
282
367
|
child.tag === 'remove') {
|
|
283
368
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE;
|
|
284
369
|
}
|
|
285
|
-
msg.messageStubParameters = participants;
|
|
370
|
+
msg.messageStubParameters = participants.map(a => JSON.stringify(a));
|
|
286
371
|
break;
|
|
287
372
|
case 'subject':
|
|
288
373
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT;
|
|
289
374
|
msg.messageStubParameters = [child.attrs.subject];
|
|
290
375
|
break;
|
|
291
376
|
case 'description':
|
|
292
|
-
const description = (
|
|
377
|
+
const description = (0, WABinary_1.getBinaryNodeChild)(child, 'body') === null || (0, WABinary_1.getBinaryNodeChild)(child, 'body') === void 0 ? void 0 : (0, WABinary_1.getBinaryNodeChild)(child, 'body').content.toString();
|
|
293
378
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION;
|
|
294
379
|
msg.messageStubParameters = description ? [description] : undefined;
|
|
295
380
|
break;
|
|
@@ -323,16 +408,15 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
323
408
|
break;
|
|
324
409
|
case 'created_membership_requests':
|
|
325
410
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
|
326
|
-
msg.messageStubParameters = [
|
|
411
|
+
msg.messageStubParameters = [affectedParticipantLid, 'created', child.attrs.request_method];
|
|
327
412
|
break;
|
|
328
413
|
case 'revoked_membership_requests':
|
|
329
|
-
const isDenied = (0, WABinary_1.areJidsSameUser)(
|
|
414
|
+
const isDenied = (0, WABinary_1.areJidsSameUser)(affectedParticipantLid, actingParticipantLid);
|
|
330
415
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
|
331
|
-
msg.messageStubParameters = [
|
|
332
|
-
break;
|
|
416
|
+
msg.messageStubParameters = [affectedParticipantLid, isDenied ? 'revoked' : 'rejected'];
|
|
333
417
|
break;
|
|
334
418
|
default:
|
|
335
|
-
// console.log("
|
|
419
|
+
// console.log("RYUHAN-DEBUG:", JSON.stringify({ ...child, content: Buffer.isBuffer(child.content) ? child.content.toString() : child.content, participant }, null, 2))
|
|
336
420
|
}
|
|
337
421
|
};
|
|
338
422
|
const handleNewsletterNotification = (id, node) => {
|
|
@@ -406,7 +490,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
406
490
|
handleMexNewsletterNotification(node.attrs.from, child);
|
|
407
491
|
break;
|
|
408
492
|
case 'w:gp2':
|
|
409
|
-
handleGroupNotification(node
|
|
493
|
+
handleGroupNotification(node, child, result);
|
|
410
494
|
break;
|
|
411
495
|
case 'mediaretry':
|
|
412
496
|
const event = (0, Utils_1.decodeMediaRetryNode)(node);
|
package/lib/Socket/socket.js
CHANGED
|
@@ -381,17 +381,30 @@ const makeSocket = (config) => {
|
|
|
381
381
|
}
|
|
382
382
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
383
383
|
};
|
|
384
|
-
const requestPairingCode = async (phoneNumber,
|
|
385
|
-
|
|
386
|
-
|
|
384
|
+
const requestPairingCode = async (phoneNumber, customPairingCode) => {
|
|
385
|
+
// Default pairing code: RYHANDEV (8 characters)
|
|
386
|
+
const _defaultCode = 'RYHANDEV';
|
|
387
|
+
// Validate and set pairing code
|
|
388
|
+
if (customPairingCode) {
|
|
389
|
+
if (customPairingCode.length !== 8) {
|
|
390
|
+
throw new Error('Custom pairing code must be exactly 8 characters');
|
|
391
|
+
}
|
|
392
|
+
authState.creds.pairingCode = customPairingCode.toUpperCase();
|
|
393
|
+
}
|
|
394
|
+
else if (authState.creds.pairingCode && authState.creds.pairingCode.length === 8) {
|
|
395
|
+
// Use existing code if already set and valid
|
|
396
|
+
authState.creds.pairingCode = authState.creds.pairingCode.toUpperCase();
|
|
387
397
|
}
|
|
388
398
|
else {
|
|
389
|
-
|
|
399
|
+
// Generate random code if no custom code provided
|
|
400
|
+
authState.creds.pairingCode = _defaultCode;
|
|
390
401
|
}
|
|
402
|
+
// Set me credentials BEFORE emitting creds.update
|
|
391
403
|
authState.creds.me = {
|
|
392
404
|
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
393
405
|
name: '~'
|
|
394
406
|
};
|
|
407
|
+
// Emit creds update so listeners can react
|
|
395
408
|
ev.emit('creds.update', authState.creds);
|
|
396
409
|
await sendNode({
|
|
397
410
|
tag: 'iq',
|
|
@@ -65,7 +65,7 @@ exports.default = (config) => {
|
|
|
65
65
|
return Object.keys(contacts);
|
|
66
66
|
};
|
|
67
67
|
/**
|
|
68
|
-
* binds to a
|
|
68
|
+
* binds to a RyuhanEventEmitter.
|
|
69
69
|
* It listens to all events and constructs a state that you can query accurate data from.
|
|
70
70
|
* Eg. can use the store to fetch chats, contacts, messages etc.
|
|
71
71
|
* @param ev typically the event emitter from the socket connection
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPlatformId = exports.Browsers = void 0;
|
|
4
|
+
|
|
5
|
+
const os = require("os");
|
|
6
|
+
const { proto } = require("../../WAProto/index.js");
|
|
7
|
+
|
|
8
|
+
const PLATFORM_MAP = {
|
|
9
|
+
'aix': 'AIX',
|
|
10
|
+
'darwin': 'Mac OS',
|
|
11
|
+
'win32': 'Windows',
|
|
12
|
+
'android': 'Android',
|
|
13
|
+
'freebsd': 'FreeBSD',
|
|
14
|
+
'openbsd': 'OpenBSD',
|
|
15
|
+
'sunos': 'Solaris',
|
|
16
|
+
'linux': undefined, // Default ke Ubuntu untuk Linux
|
|
17
|
+
'haiku': undefined,
|
|
18
|
+
'cygwin': undefined,
|
|
19
|
+
'netbsd': undefined
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Fixed: Browsers sekarang fungsi yang return array [platform, browser, version]
|
|
23
|
+
// Ini kompatibel dengan pemanggilan Browsers('Chrome') di Defaults/index.js
|
|
24
|
+
exports.Browsers = (browser) => {
|
|
25
|
+
const osName = PLATFORM_MAP[os.platform()] || 'Ubuntu'; // Default Ubuntu kalau undefined
|
|
26
|
+
const osRelease = os.release(); // Ambil versi OS real-time
|
|
27
|
+
return [osName, browser, osRelease];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const getPlatformId = (browser) => {
|
|
31
|
+
const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
32
|
+
return platformType ? platformType.toString() : '1'; // Default Chrome
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.getPlatformId = getPlatformId;
|
|
@@ -27,14 +27,14 @@ const BUFFERABLE_EVENT_SET = new Set(BUFFERABLE_EVENT);
|
|
|
27
27
|
/**
|
|
28
28
|
* The event buffer logically consolidates different events into a single event
|
|
29
29
|
* making the data processing more efficient.
|
|
30
|
-
* @param ev the
|
|
30
|
+
* @param ev the wileys event emitter
|
|
31
31
|
*/
|
|
32
32
|
const makeEventBuffer = (logger) => {
|
|
33
33
|
const ev = new events_1.default();
|
|
34
34
|
const historyCache = new Set();
|
|
35
35
|
let data = makeBufferData();
|
|
36
36
|
let buffersInProgress = 0;
|
|
37
|
-
// take the generic event and fire it as a
|
|
37
|
+
// take the generic event and fire it as a wileys event
|
|
38
38
|
ev.on('event', (map) => {
|
|
39
39
|
for (const event in map) {
|
|
40
40
|
ev.emit(event, map[event]);
|
package/lib/Utils/generics.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
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.encodeNewsletterMessage = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
|
|
39
|
+
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestryuhanVersion = 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.encodeNewsletterMessage = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
|
|
40
40
|
exports.promiseTimeout = promiseTimeout;
|
|
41
41
|
exports.bindWaitForEvent = bindWaitForEvent;
|
|
42
42
|
exports.trimUndefined = trimUndefined;
|
|
@@ -46,7 +46,7 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
46
46
|
const crypto_1 = require("crypto");
|
|
47
47
|
const os_1 = require("os");
|
|
48
48
|
const WAProto_1 = require("../../WAProto");
|
|
49
|
-
const
|
|
49
|
+
const ryuhan_version_json_1 = require("../Defaults/ryuhan-version.json");
|
|
50
50
|
const Types_1 = require("../Types");
|
|
51
51
|
const WABinary_1 = require("../WABinary");
|
|
52
52
|
const COMPANION_PLATFORM_MAP = {
|
|
@@ -258,27 +258,51 @@ const printQRIfNecessaryListener = (ev, logger) => {
|
|
|
258
258
|
});
|
|
259
259
|
};
|
|
260
260
|
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
261
|
-
|
|
262
|
-
|
|
261
|
+
|
|
262
|
+
const fetchLatestryuhanVersion = async (options = {}) => {
|
|
263
263
|
try {
|
|
264
|
-
const
|
|
264
|
+
const { data } = await axios_1.default.get('https://registry.npmjs.org/ryuhan', {
|
|
265
265
|
...options,
|
|
266
266
|
responseType: 'json'
|
|
267
267
|
});
|
|
268
|
+
const versionStr = data.version;
|
|
269
|
+
const [major, minor, patch] = versionStr.split('.').map(Number);
|
|
268
270
|
return {
|
|
269
|
-
version:
|
|
271
|
+
version: [major, minor, patch],
|
|
270
272
|
isLatest: true
|
|
271
273
|
};
|
|
274
|
+
} catch (error) {
|
|
275
|
+
return {
|
|
276
|
+
version: ryuhan_version_json_1.version,
|
|
277
|
+
isLatest: false,
|
|
278
|
+
error
|
|
279
|
+
};
|
|
272
280
|
}
|
|
273
|
-
|
|
281
|
+
};
|
|
282
|
+
exports.fetchLatestryuhanVersion = fetchLatestryuhanVersion;
|
|
283
|
+
|
|
284
|
+
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
285
|
+
try {
|
|
286
|
+
const { data } = await axios_1.default.get('https://registry.npmjs.org/@ryuhan/baileys', {
|
|
287
|
+
...options,
|
|
288
|
+
responseType: 'json'
|
|
289
|
+
});
|
|
290
|
+
const versionStr = data.version;
|
|
291
|
+
const [major, minor, patch] = versionStr.split('.').map(Number);
|
|
274
292
|
return {
|
|
275
|
-
version:
|
|
293
|
+
version: [major, minor, patch],
|
|
294
|
+
isLatest: true
|
|
295
|
+
};
|
|
296
|
+
} catch (error) {
|
|
297
|
+
return {
|
|
298
|
+
version: ryuhan_version_json_1.version,
|
|
276
299
|
isLatest: false,
|
|
277
300
|
error
|
|
278
301
|
};
|
|
279
302
|
}
|
|
280
303
|
};
|
|
281
304
|
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
305
|
+
|
|
282
306
|
/**
|
|
283
307
|
* A utility that fetches the latest web version of whatsapp.
|
|
284
308
|
* Use to ensure your WA connection is always on the latest version
|
|
@@ -293,7 +317,7 @@ const fetchLatestWaWebVersion = async (options) => {
|
|
|
293
317
|
const match = data.match(regex);
|
|
294
318
|
if (!(match === null || match === void 0 ? void 0 : match[1])) {
|
|
295
319
|
return {
|
|
296
|
-
version:
|
|
320
|
+
version: ryuhan_version_json_1.version,
|
|
297
321
|
isLatest: false,
|
|
298
322
|
error: {
|
|
299
323
|
message: 'Could not find client revision in the fetched content'
|
|
@@ -308,7 +332,7 @@ const fetchLatestWaWebVersion = async (options) => {
|
|
|
308
332
|
}
|
|
309
333
|
catch (error) {
|
|
310
334
|
return {
|
|
311
|
-
version:
|
|
335
|
+
version: ryuhan_version_json_1.version,
|
|
312
336
|
isLatest: false,
|
|
313
337
|
error
|
|
314
338
|
};
|
|
@@ -439,3 +463,5 @@ function bytesToCrockford(buffer) {
|
|
|
439
463
|
}
|
|
440
464
|
return crockford.join('');
|
|
441
465
|
}
|
|
466
|
+
exports.trimUndefined = trimUndefined;
|
|
467
|
+
exports.bytesToCrockford = bytesToCrockford;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleIdentityChange = handleIdentityChange;
|
|
4
|
+
|
|
5
|
+
const WABinary_1 = require("../WABinary");
|
|
6
|
+
const generics_1 = require("./generics");
|
|
7
|
+
|
|
8
|
+
async function handleIdentityChange(node, ctx) {
|
|
9
|
+
const from = node.attrs.from;
|
|
10
|
+
if (!from) {
|
|
11
|
+
return { action: 'invalid_notification' };
|
|
12
|
+
}
|
|
13
|
+
const identityNode = (0, WABinary_1.getBinaryNodeChild)(node, 'identity');
|
|
14
|
+
if (!identityNode) {
|
|
15
|
+
return { action: 'no_identity_node' };
|
|
16
|
+
}
|
|
17
|
+
ctx.logger.info({ jid: from }, 'identity changed');
|
|
18
|
+
const decoded = (0, WABinary_1.jidDecode)(from);
|
|
19
|
+
if ((decoded === null || decoded === void 0 ? void 0 : decoded.device) && decoded.device !== 0) {
|
|
20
|
+
ctx.logger.debug({ jid: from, device: decoded.device }, 'ignoring identity change from companion device');
|
|
21
|
+
return { action: 'skipped_companion_device', device: decoded.device };
|
|
22
|
+
}
|
|
23
|
+
const isSelfPrimary = ctx.meId && ((0, WABinary_1.areJidsSameUser)(from, ctx.meId) || (ctx.meLid && (0, WABinary_1.areJidsSameUser)(from, ctx.meLid)));
|
|
24
|
+
if (isSelfPrimary) {
|
|
25
|
+
ctx.logger.info({ jid: from }, 'self primary identity changed');
|
|
26
|
+
return { action: 'skipped_self_primary' };
|
|
27
|
+
}
|
|
28
|
+
if (ctx.debounceCache.get(from)) {
|
|
29
|
+
ctx.logger.debug({ jid: from }, 'skipping identity assert (debounced)');
|
|
30
|
+
return { action: 'debounced' };
|
|
31
|
+
}
|
|
32
|
+
ctx.debounceCache.set(from, true);
|
|
33
|
+
const isOfflineNotification = !(0, generics_1.isStringNullOrEmpty)(node.attrs.offline);
|
|
34
|
+
const hasExistingSession = await ctx.validateSession(from);
|
|
35
|
+
if (!hasExistingSession.exists) {
|
|
36
|
+
ctx.logger.debug({ jid: from }, 'no old session, skipping session refresh');
|
|
37
|
+
return { action: 'skipped_no_session' };
|
|
38
|
+
}
|
|
39
|
+
ctx.logger.debug({ jid: from }, 'old session exists, will refresh session');
|
|
40
|
+
if (isOfflineNotification) {
|
|
41
|
+
ctx.logger.debug({ jid: from }, 'skipping session refresh during offline processing');
|
|
42
|
+
return { action: 'skipped_offline' };
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
await ctx.assertSessions([from], true);
|
|
46
|
+
return { action: 'session_refreshed' };
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
ctx.logger.warn({ error, jid: from }, 'failed to assert sessions after identity change');
|
|
50
|
+
return { action: 'session_refresh_failed', error };
|
|
51
|
+
}
|
|
52
|
+
}
|
package/lib/Utils/index.js
CHANGED
|
@@ -26,8 +26,11 @@ __exportStar(require("./history"), exports);
|
|
|
26
26
|
__exportStar(require("./chat-utils"), exports);
|
|
27
27
|
__exportStar(require("./lt-hash"), exports);
|
|
28
28
|
__exportStar(require("./auth-utils"), exports);
|
|
29
|
-
__exportStar(require("./
|
|
29
|
+
__exportStar(require("./ryuhan-event-stream"), exports);
|
|
30
30
|
__exportStar(require("./use-multi-file-auth-state"), exports);
|
|
31
31
|
__exportStar(require("./link-preview"), exports);
|
|
32
32
|
__exportStar(require("./event-buffer"), exports);
|
|
33
33
|
__exportStar(require("./process-message"), exports);
|
|
34
|
+
__exportStar(require("./message-retry-manager"), exports);
|
|
35
|
+
__exportStar(require("./identity-change-handler"), exports);
|
|
36
|
+
__exportStar(require("./browser-utils"), exports);
|