@ryuhan/baileys 1.0.0 → 1.0.3
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 +105 -0
- package/lib/Defaults/index.js +47 -35
- package/lib/Defaults/ryuhan-version.json +3 -0
- package/lib/Socket/chats.js +131 -87
- package/lib/Socket/messages-recv.js +1 -1
- package/lib/Socket/socket.js +1 -1
- 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/index.js +3 -1
- package/lib/Utils/message-retry-manager.js +128 -0
- 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 +29 -16
- 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
package/lib/Socket/chats.js
CHANGED
|
@@ -15,24 +15,31 @@ const process_message_1 = __importDefault(require("../Utils/process-message"));
|
|
|
15
15
|
const WABinary_1 = require("../WABinary");
|
|
16
16
|
const WAUSync_1 = require("../WAUSync");
|
|
17
17
|
const usync_1 = require("./usync");
|
|
18
|
+
const chalk = require('chalk');
|
|
18
19
|
const MAX_SYNC_ATTEMPTS = 2;
|
|
20
|
+
const SyncState = {
|
|
21
|
+
Connecting: 'connecting',
|
|
22
|
+
AwaitingInitialSync: 'awaiting_initial_sync',
|
|
23
|
+
Syncing: 'syncing',
|
|
24
|
+
Online: 'online'
|
|
25
|
+
};
|
|
19
26
|
const makeChatsSocket = (config) => {
|
|
20
27
|
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
|
|
21
28
|
const sock = (0, usync_1.makeUSyncSocket)(config);
|
|
22
|
-
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, } = sock;
|
|
29
|
+
const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, } = sock;
|
|
23
30
|
let privacySettings;
|
|
31
|
+
let syncState = SyncState.Connecting;
|
|
24
32
|
let needToFlushWithAppStateSync = false;
|
|
25
33
|
let pendingAppStateSync = false;
|
|
26
|
-
|
|
34
|
+
let awaitingSyncTimeout;
|
|
27
35
|
const processingMutex = (0, make_mutex_1.makeMutex)();
|
|
28
36
|
const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
|
|
29
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
37
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
30
38
|
useClones: false
|
|
31
39
|
});
|
|
32
40
|
if (!config.placeholderResendCache) {
|
|
33
41
|
config.placeholderResendCache = placeholderResendCache;
|
|
34
42
|
}
|
|
35
|
-
/** helper function to fetch the given app state sync key */
|
|
36
43
|
const getAppStateSyncKey = async (keyId) => {
|
|
37
44
|
const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
|
|
38
45
|
return key;
|
|
@@ -54,7 +61,6 @@ const makeChatsSocket = (config) => {
|
|
|
54
61
|
}
|
|
55
62
|
return privacySettings;
|
|
56
63
|
};
|
|
57
|
-
/** helper function to run a privacy IQ query */
|
|
58
64
|
const privacyQuery = async (name, value) => {
|
|
59
65
|
await query({
|
|
60
66
|
tag: 'iq',
|
|
@@ -99,6 +105,9 @@ const makeChatsSocket = (config) => {
|
|
|
99
105
|
const updateGroupsAddPrivacy = async (value) => {
|
|
100
106
|
await privacyQuery('groupadd', value);
|
|
101
107
|
};
|
|
108
|
+
const updateDisableLinkPreviewsPrivacy = async (isPreviewsDisabled) => {
|
|
109
|
+
return chatModify({ disableLinkPreviews: { isPreviewsDisabled } }, '');
|
|
110
|
+
};
|
|
102
111
|
const updateDefaultDisappearingMode = async (duration) => {
|
|
103
112
|
await query({
|
|
104
113
|
tag: 'iq',
|
|
@@ -179,16 +188,15 @@ const makeChatsSocket = (config) => {
|
|
|
179
188
|
return result.list;
|
|
180
189
|
}
|
|
181
190
|
};
|
|
182
|
-
|
|
183
|
-
const updateProfilePicture = async (jid, content) => {
|
|
191
|
+
const updateProfilePicture = async (jid, content, dimensions) => {
|
|
184
192
|
let targetJid;
|
|
185
193
|
if (!jid) {
|
|
186
194
|
throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
187
195
|
}
|
|
188
196
|
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
189
|
-
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
197
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
190
198
|
}
|
|
191
|
-
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
199
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content, dimensions);
|
|
192
200
|
await query({
|
|
193
201
|
tag: 'iq',
|
|
194
202
|
attrs: {
|
|
@@ -206,14 +214,13 @@ const makeChatsSocket = (config) => {
|
|
|
206
214
|
]
|
|
207
215
|
});
|
|
208
216
|
};
|
|
209
|
-
/** remove the profile picture for yourself or a group */
|
|
210
217
|
const removeProfilePicture = async (jid) => {
|
|
211
218
|
let targetJid;
|
|
212
219
|
if (!jid) {
|
|
213
220
|
throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
|
214
221
|
}
|
|
215
222
|
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
216
|
-
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
223
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
217
224
|
}
|
|
218
225
|
await query({
|
|
219
226
|
tag: 'iq',
|
|
@@ -225,7 +232,6 @@ const makeChatsSocket = (config) => {
|
|
|
225
232
|
}
|
|
226
233
|
});
|
|
227
234
|
};
|
|
228
|
-
/** update the profile status for yourself */
|
|
229
235
|
const updateProfileStatus = async (status) => {
|
|
230
236
|
await query({
|
|
231
237
|
tag: 'iq',
|
|
@@ -352,18 +358,12 @@ const makeChatsSocket = (config) => {
|
|
|
352
358
|
};
|
|
353
359
|
};
|
|
354
360
|
const resyncAppState = ev.createBufferedFunction(async (collections, isInitialSync) => {
|
|
355
|
-
// we use this to determine which events to fire
|
|
356
|
-
// otherwise when we resync from scratch -- all notifications will fire
|
|
357
361
|
const initialVersionMap = {};
|
|
358
362
|
const globalMutationMap = {};
|
|
359
363
|
await authState.keys.transaction(async () => {
|
|
360
364
|
var _a;
|
|
361
365
|
const collectionsToHandle = new Set(collections);
|
|
362
|
-
// in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
|
|
363
366
|
const attemptsMap = {};
|
|
364
|
-
// keep executing till all collections are done
|
|
365
|
-
// sometimes a single patch request will not return all the patches (God knows why)
|
|
366
|
-
// so we fetch till they're all done (this is determined by the "has_more_patches" flag)
|
|
367
367
|
while (collectionsToHandle.size) {
|
|
368
368
|
const states = {};
|
|
369
369
|
const nodes = [];
|
|
@@ -385,7 +385,6 @@ const makeChatsSocket = (config) => {
|
|
|
385
385
|
attrs: {
|
|
386
386
|
name,
|
|
387
387
|
version: state.version.toString(),
|
|
388
|
-
// return snapshot if being synced from scratch
|
|
389
388
|
'return_snapshot': (!state.version).toString()
|
|
390
389
|
}
|
|
391
390
|
});
|
|
@@ -405,7 +404,6 @@ const makeChatsSocket = (config) => {
|
|
|
405
404
|
}
|
|
406
405
|
]
|
|
407
406
|
});
|
|
408
|
-
// extract from binary node
|
|
409
407
|
const decoded = await (0, Utils_1.extractSyncdPatches)(result, config === null || config === void 0 ? void 0 : config.options);
|
|
410
408
|
for (const key in decoded) {
|
|
411
409
|
const name = key;
|
|
@@ -418,7 +416,6 @@ const makeChatsSocket = (config) => {
|
|
|
418
416
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
419
417
|
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
420
418
|
}
|
|
421
|
-
// only process if there are syncd patches
|
|
422
419
|
if (patches.length) {
|
|
423
420
|
const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
424
421
|
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
@@ -429,22 +426,18 @@ const makeChatsSocket = (config) => {
|
|
|
429
426
|
if (hasMorePatches) {
|
|
430
427
|
logger.info(`${name} has more patches...`);
|
|
431
428
|
}
|
|
432
|
-
else {
|
|
429
|
+
else {
|
|
433
430
|
collectionsToHandle.delete(name);
|
|
434
431
|
}
|
|
435
432
|
}
|
|
436
433
|
catch (error) {
|
|
437
|
-
// if retry attempts overshoot
|
|
438
|
-
// or key not found
|
|
439
434
|
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
|
|
440
435
|
|| ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404
|
|
441
436
|
|| error.name === 'TypeError';
|
|
442
437
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
443
438
|
await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
|
|
444
|
-
// increment number of retries
|
|
445
439
|
attemptsMap[name] = (attemptsMap[name] || 0) + 1;
|
|
446
440
|
if (isIrrecoverableError) {
|
|
447
|
-
// stop retrying
|
|
448
441
|
collectionsToHandle.delete(name);
|
|
449
442
|
}
|
|
450
443
|
}
|
|
@@ -456,28 +449,56 @@ const makeChatsSocket = (config) => {
|
|
|
456
449
|
onMutation(globalMutationMap[key]);
|
|
457
450
|
}
|
|
458
451
|
});
|
|
459
|
-
/**
|
|
460
|
-
* fetch the profile picture of a user/group
|
|
461
|
-
* type = "preview" for a low res picture
|
|
462
|
-
* type = "image for the high res picture"
|
|
463
|
-
*/
|
|
464
452
|
const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
|
|
465
453
|
var _a;
|
|
466
454
|
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
455
|
+
try {
|
|
456
|
+
const result = await query({
|
|
457
|
+
tag: 'iq',
|
|
458
|
+
attrs: {
|
|
459
|
+
target: jid,
|
|
460
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
461
|
+
type: 'get',
|
|
462
|
+
xmlns: 'w:profile:picture'
|
|
463
|
+
},
|
|
464
|
+
content: [
|
|
465
|
+
{ tag: 'picture', attrs: { type, query: 'url' } }
|
|
466
|
+
]
|
|
467
|
+
}, timeoutMs);
|
|
468
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
|
|
469
|
+
return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
|
|
470
|
+
} catch (error) {
|
|
471
|
+
if (error.message?.includes('item-not-found') ||
|
|
472
|
+
error.output?.payload?.statusCode === 404 ||
|
|
473
|
+
error.statusCode === 404) {
|
|
474
|
+
logger.info(chalk.gray(`[INFO] Profile pic not found for ${jid}, using fallback`));
|
|
475
|
+
return {
|
|
476
|
+
eurl: undefined,
|
|
477
|
+
id: jid.split('@')[0],
|
|
478
|
+
status: null,
|
|
479
|
+
img: null
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
throw error;
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
const createCallLink = async (type, event, timeoutMs) => {
|
|
467
486
|
const result = await query({
|
|
468
|
-
tag: '
|
|
487
|
+
tag: 'call',
|
|
469
488
|
attrs: {
|
|
470
|
-
|
|
471
|
-
to:
|
|
472
|
-
type: 'get',
|
|
473
|
-
xmlns: 'w:profile:picture'
|
|
489
|
+
id: generateMessageTag(),
|
|
490
|
+
to: '@call'
|
|
474
491
|
},
|
|
475
492
|
content: [
|
|
476
|
-
{
|
|
493
|
+
{
|
|
494
|
+
tag: 'link_create',
|
|
495
|
+
attrs: { media: type },
|
|
496
|
+
content: event ? [{ tag: 'event', attrs: { start_time: String(event.startTime) } }] : undefined
|
|
497
|
+
}
|
|
477
498
|
]
|
|
478
499
|
}, timeoutMs);
|
|
479
|
-
const child = (0, WABinary_1.getBinaryNodeChild)(result, '
|
|
480
|
-
return
|
|
500
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'link_create');
|
|
501
|
+
return child?.attrs?.token;
|
|
481
502
|
};
|
|
482
503
|
const sendPresenceUpdate = async (type, toJid) => {
|
|
483
504
|
const me = authState.creds.me;
|
|
@@ -513,10 +534,6 @@ const makeChatsSocket = (config) => {
|
|
|
513
534
|
});
|
|
514
535
|
}
|
|
515
536
|
};
|
|
516
|
-
/**
|
|
517
|
-
* @param toJid the jid to subscribe to
|
|
518
|
-
* @param tcToken token for subscription, use if present
|
|
519
|
-
*/
|
|
520
537
|
const presenceSubscribe = (toJid, tcToken) => (sendNode({
|
|
521
538
|
tag: 'presence',
|
|
522
539
|
attrs: {
|
|
@@ -625,7 +642,6 @@ const makeChatsSocket = (config) => {
|
|
|
625
642
|
}
|
|
626
643
|
}
|
|
627
644
|
};
|
|
628
|
-
/** sending non-abt props may fix QR scan fail if server expects */
|
|
629
645
|
const fetchProps = async () => {
|
|
630
646
|
var _a, _b, _c;
|
|
631
647
|
const resultNode = await query({
|
|
@@ -645,7 +661,7 @@ const makeChatsSocket = (config) => {
|
|
|
645
661
|
const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
|
|
646
662
|
let props = {};
|
|
647
663
|
if (propsNode) {
|
|
648
|
-
if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) {
|
|
664
|
+
if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) {
|
|
649
665
|
authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
|
|
650
666
|
ev.emit('creds.update', authState.creds);
|
|
651
667
|
}
|
|
@@ -654,18 +670,10 @@ const makeChatsSocket = (config) => {
|
|
|
654
670
|
logger.debug('fetched props');
|
|
655
671
|
return props;
|
|
656
672
|
};
|
|
657
|
-
/**
|
|
658
|
-
* modify a chat -- mark unread, read etc.
|
|
659
|
-
* lastMessages must be sorted in reverse chronologically
|
|
660
|
-
* requires the last messages till the last message received; required for archive & unread
|
|
661
|
-
*/
|
|
662
673
|
const chatModify = (mod, jid) => {
|
|
663
674
|
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
664
675
|
return appPatch(patch);
|
|
665
676
|
};
|
|
666
|
-
/**
|
|
667
|
-
* Star or Unstar a message
|
|
668
|
-
*/
|
|
669
677
|
const star = (jid, messages, star) => {
|
|
670
678
|
return chatModify({
|
|
671
679
|
star: {
|
|
@@ -674,9 +682,15 @@ const makeChatsSocket = (config) => {
|
|
|
674
682
|
}
|
|
675
683
|
}, jid);
|
|
676
684
|
};
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
685
|
+
const addOrEditContact = (jid, contact) => {
|
|
686
|
+
return chatModify({ contact }, jid);
|
|
687
|
+
};
|
|
688
|
+
const removeContact = (jid) => {
|
|
689
|
+
return chatModify({ contact: null }, jid);
|
|
690
|
+
};
|
|
691
|
+
const addLabel = (jid, labels) => {
|
|
692
|
+
return chatModify({ addLabel: { ...labels } }, jid);
|
|
693
|
+
};
|
|
680
694
|
const addChatLabel = (jid, labelId) => {
|
|
681
695
|
return chatModify({
|
|
682
696
|
addChatLabel: {
|
|
@@ -684,9 +698,6 @@ const makeChatsSocket = (config) => {
|
|
|
684
698
|
}
|
|
685
699
|
}, jid);
|
|
686
700
|
};
|
|
687
|
-
/**
|
|
688
|
-
* Removes label for the chat
|
|
689
|
-
*/
|
|
690
701
|
const removeChatLabel = (jid, labelId) => {
|
|
691
702
|
return chatModify({
|
|
692
703
|
removeChatLabel: {
|
|
@@ -694,9 +705,6 @@ const makeChatsSocket = (config) => {
|
|
|
694
705
|
}
|
|
695
706
|
}, jid);
|
|
696
707
|
};
|
|
697
|
-
/**
|
|
698
|
-
* Adds label for the message
|
|
699
|
-
*/
|
|
700
708
|
const addMessageLabel = (jid, messageId, labelId) => {
|
|
701
709
|
return chatModify({
|
|
702
710
|
addMessageLabel: {
|
|
@@ -705,9 +713,6 @@ const makeChatsSocket = (config) => {
|
|
|
705
713
|
}
|
|
706
714
|
}, jid);
|
|
707
715
|
};
|
|
708
|
-
/**
|
|
709
|
-
* Removes label for the message
|
|
710
|
-
*/
|
|
711
716
|
const removeMessageLabel = (jid, messageId, labelId) => {
|
|
712
717
|
return chatModify({
|
|
713
718
|
removeMessageLabel: {
|
|
@@ -716,10 +721,6 @@ const makeChatsSocket = (config) => {
|
|
|
716
721
|
}
|
|
717
722
|
}, jid);
|
|
718
723
|
};
|
|
719
|
-
/**
|
|
720
|
-
* queries need to be fired on connection open
|
|
721
|
-
* help ensure parity with WA Web
|
|
722
|
-
* */
|
|
723
724
|
const executeInitQueries = async () => {
|
|
724
725
|
await Promise.all([
|
|
725
726
|
fetchProps(),
|
|
@@ -736,7 +737,6 @@ const makeChatsSocket = (config) => {
|
|
|
736
737
|
if (!msg.key.fromMe) {
|
|
737
738
|
ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
|
|
738
739
|
}
|
|
739
|
-
// update our pushname too
|
|
740
740
|
if (msg.key.fromMe && msg.pushName && ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.name) !== msg.pushName) {
|
|
741
741
|
ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
|
|
742
742
|
}
|
|
@@ -746,6 +746,31 @@ const makeChatsSocket = (config) => {
|
|
|
746
746
|
? (shouldSyncHistoryMessage(historyMsg)
|
|
747
747
|
&& Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
|
|
748
748
|
: false;
|
|
749
|
+
if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
|
|
750
|
+
if (awaitingSyncTimeout) {
|
|
751
|
+
clearTimeout(awaitingSyncTimeout);
|
|
752
|
+
awaitingSyncTimeout = undefined;
|
|
753
|
+
}
|
|
754
|
+
if (shouldProcessHistoryMsg) {
|
|
755
|
+
syncState = SyncState.Syncing;
|
|
756
|
+
logger.info('Transitioned to Syncing state');
|
|
757
|
+
} else {
|
|
758
|
+
syncState = SyncState.Online;
|
|
759
|
+
logger.info('History sync skipped, transitioning to Online state and flushing buffer');
|
|
760
|
+
ev.flush();
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
const doAppStateSync = async () => {
|
|
764
|
+
if (syncState === SyncState.Syncing) {
|
|
765
|
+
logger.info('Doing app state sync');
|
|
766
|
+
await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
|
|
767
|
+
syncState = SyncState.Online;
|
|
768
|
+
logger.info('App state sync complete, transitioning to Online state and flushing buffer');
|
|
769
|
+
ev.flush();
|
|
770
|
+
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
771
|
+
ev.emit('creds.update', { accountSyncCounter });
|
|
772
|
+
}
|
|
773
|
+
};
|
|
749
774
|
if (historyMsg && !authState.creds.myAppStateKeyId) {
|
|
750
775
|
logger.warn('skipping app state sync, as myAppStateKeyId is not set');
|
|
751
776
|
pendingAppStateSync = true;
|
|
@@ -759,6 +784,7 @@ const makeChatsSocket = (config) => {
|
|
|
759
784
|
}
|
|
760
785
|
})(),
|
|
761
786
|
(0, process_message_1.default)(msg, {
|
|
787
|
+
signalRepository,
|
|
762
788
|
shouldProcessHistoryMsg,
|
|
763
789
|
placeholderResendCache,
|
|
764
790
|
ev,
|
|
@@ -774,18 +800,6 @@ const makeChatsSocket = (config) => {
|
|
|
774
800
|
await doAppStateSync();
|
|
775
801
|
pendingAppStateSync = false;
|
|
776
802
|
}
|
|
777
|
-
async function doAppStateSync() {
|
|
778
|
-
if (!authState.creds.accountSyncCounter) {
|
|
779
|
-
logger.info('doing initial app state sync');
|
|
780
|
-
await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
|
|
781
|
-
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
782
|
-
ev.emit('creds.update', { accountSyncCounter });
|
|
783
|
-
if (needToFlushWithAppStateSync) {
|
|
784
|
-
logger.debug('flushing with app state sync');
|
|
785
|
-
ev.flush();
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
803
|
});
|
|
790
804
|
ws.on('CB:presence', handlePresenceUpdate);
|
|
791
805
|
ws.on('CB:chatstate', handlePresenceUpdate);
|
|
@@ -804,7 +818,6 @@ const makeChatsSocket = (config) => {
|
|
|
804
818
|
}
|
|
805
819
|
break;
|
|
806
820
|
case 'groups':
|
|
807
|
-
// handled in groups.ts
|
|
808
821
|
break;
|
|
809
822
|
default:
|
|
810
823
|
logger.info({ node }, 'received unknown sync');
|
|
@@ -821,16 +834,43 @@ const makeChatsSocket = (config) => {
|
|
|
821
834
|
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
822
835
|
.catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
823
836
|
}
|
|
824
|
-
if (receivedPendingNotifications &&
|
|
825
|
-
// we keep buffering events until we finally have
|
|
826
|
-
// the key and can sync the messages
|
|
837
|
+
if (receivedPendingNotifications &&
|
|
827
838
|
!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
|
|
828
839
|
ev.buffer();
|
|
829
840
|
needToFlushWithAppStateSync = true;
|
|
830
841
|
}
|
|
842
|
+
if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
syncState = SyncState.AwaitingInitialSync;
|
|
846
|
+
logger.info('Connection is now AwaitingInitialSync, buffering events');
|
|
847
|
+
ev.buffer();
|
|
848
|
+
const willSyncHistory = shouldSyncHistoryMessage(
|
|
849
|
+
WAProto_1.proto.Message.HistorySyncNotification.create({
|
|
850
|
+
syncType: WAProto_1.proto.HistorySync.HistorySyncType.RECENT
|
|
851
|
+
})
|
|
852
|
+
);
|
|
853
|
+
if (!willSyncHistory) {
|
|
854
|
+
logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.');
|
|
855
|
+
syncState = SyncState.Online;
|
|
856
|
+
setTimeout(() => ev.flush(), 0);
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
logger.info('History sync is enabled, awaiting notification with a 20s timeout.');
|
|
860
|
+
if (awaitingSyncTimeout) {
|
|
861
|
+
clearTimeout(awaitingSyncTimeout);
|
|
862
|
+
}
|
|
863
|
+
awaitingSyncTimeout = setTimeout(() => {
|
|
864
|
+
if (syncState === SyncState.AwaitingInitialSync) {
|
|
865
|
+
logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
|
|
866
|
+
syncState = SyncState.Online;
|
|
867
|
+
ev.flush();
|
|
868
|
+
}
|
|
869
|
+
}, 20000);
|
|
831
870
|
});
|
|
832
871
|
return {
|
|
833
872
|
...sock,
|
|
873
|
+
createCallLink,
|
|
834
874
|
getBotListV2,
|
|
835
875
|
processingMutex,
|
|
836
876
|
fetchPrivacySettings,
|
|
@@ -848,6 +888,7 @@ const makeChatsSocket = (config) => {
|
|
|
848
888
|
updateProfileStatus,
|
|
849
889
|
updateProfileName,
|
|
850
890
|
updateBlockStatus,
|
|
891
|
+
updateDisableLinkPreviewsPrivacy,
|
|
851
892
|
updateCallPrivacy,
|
|
852
893
|
updateMessagesPrivacy,
|
|
853
894
|
updateLastSeenPrivacy,
|
|
@@ -861,6 +902,9 @@ const makeChatsSocket = (config) => {
|
|
|
861
902
|
resyncAppState,
|
|
862
903
|
chatModify,
|
|
863
904
|
cleanDirtyBits,
|
|
905
|
+
addOrEditContact,
|
|
906
|
+
removeContact,
|
|
907
|
+
addLabel,
|
|
864
908
|
addChatLabel,
|
|
865
909
|
removeChatLabel,
|
|
866
910
|
addMessageLabel,
|
|
@@ -868,4 +912,4 @@ const makeChatsSocket = (config) => {
|
|
|
868
912
|
star
|
|
869
913
|
};
|
|
870
914
|
};
|
|
871
|
-
exports.makeChatsSocket = makeChatsSocket;
|
|
915
|
+
exports.makeChatsSocket = makeChatsSocket;
|
|
@@ -332,7 +332,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
332
332
|
break;
|
|
333
333
|
break;
|
|
334
334
|
default:
|
|
335
|
-
// console.log("
|
|
335
|
+
// console.log("RYUHAN-DEBUG:", JSON.stringify({ ...child, content: Buffer.isBuffer(child.content) ? child.content.toString() : child.content, participant }, null, 2))
|
|
336
336
|
}
|
|
337
337
|
};
|
|
338
338
|
const handleNewsletterNotification = (id, node) => {
|
package/lib/Socket/socket.js
CHANGED
|
@@ -381,7 +381,7 @@ 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, pairKey = "
|
|
384
|
+
const requestPairingCode = async (phoneNumber, pairKey = "RYHANDEV") => {
|
|
385
385
|
if (pairKey) {
|
|
386
386
|
authState.creds.pairingCode = pairKey.toUpperCase();
|
|
387
387
|
}
|
|
@@ -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;
|
package/lib/Utils/index.js
CHANGED
|
@@ -26,8 +26,10 @@ __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("./browser-utils"), exports);
|