@badzz88/baileys 8.5.4 → 8.5.6
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 +2 -2
- package/WAProto/fix-imports.js +69 -79
- package/WAProto/index.d.ts +15305 -87935
- package/WAProto/index.js +41109 -194076
- package/engine-requirements.js +15 -8
- package/package.json +23 -19
- package/src/Defaults/index.js +186 -0
- package/src/Signal/Group/ciphertext-message.js +15 -0
- package/src/Signal/Group/group-session-builder.js +86 -0
- package/src/Signal/Group/group_cipher.js +82 -0
- package/src/Signal/Group/index.js +140 -0
- package/src/Signal/Group/keyhelper.js +77 -0
- package/src/Signal/Group/sender-chain-key.js +29 -0
- package/src/Signal/Group/sender-key-distribution-message.js +66 -0
- package/src/Signal/Group/sender-key-message.js +69 -0
- package/src/Signal/Group/sender-key-name.js +51 -0
- package/src/Signal/Group/sender-key-record.js +44 -0
- package/src/Signal/Group/sender-key-state.js +87 -0
- package/src/Signal/Group/sender-message-key.js +29 -0
- package/src/Signal/libsignal.js +455 -0
- package/src/Signal/lid-mapping.js +273 -0
- package/src/Socket/Client/index.js +31 -0
- package/src/Socket/Client/types.js +13 -0
- package/src/Socket/Client/websocket.js +61 -0
- package/src/Socket/aigroups.js +221 -0
- package/src/Socket/business.js +411 -0
- package/src/Socket/chats.js +1449 -0
- package/src/Socket/communities.js +463 -0
- package/src/Socket/graphql.js +523 -0
- package/src/Socket/groups.js +516 -0
- package/src/Socket/index.js +31 -0
- package/src/Socket/interactive-handler.js +527 -0
- package/src/Socket/interop.js +339 -0
- package/src/Socket/luxu.js +349 -0
- package/src/Socket/managed-account.js +98 -0
- package/src/Socket/messages-recv.js +2685 -0
- package/src/Socket/messages-send.js +2047 -0
- package/src/Socket/mex.js +57 -0
- package/src/Socket/newsletter.js +455 -0
- package/src/Socket/privacy.js +125 -0
- package/src/Socket/registration.js +236 -0
- package/src/Socket/socket.js +983 -0
- package/src/Socket/text-router.js +65 -0
- package/src/Socket/username.js +130 -0
- package/src/Store/index.js +33 -0
- package/src/Store/keyed-db.js +118 -0
- package/src/Store/make-cache-manager-store.js +84 -0
- package/src/Store/make-in-memory-store.js +551 -0
- package/src/Store/make-ordered-dictionary.js +81 -0
- package/src/Store/object-repository.js +26 -0
- package/src/Types/Auth.js +31 -0
- package/src/Types/Bussines.js +2 -0
- package/src/Types/Call.js +2 -0
- package/src/Types/Chat.js +4 -0
- package/src/Types/Contact.js +2 -0
- package/src/Types/Events.js +2 -0
- package/src/Types/GroupMetadata.js +2 -0
- package/src/Types/Label.js +26 -0
- package/src/Types/LabelAssociation.js +8 -0
- package/src/Types/Message.js +93 -0
- package/src/Types/Mex.js +112 -0
- package/src/Types/Newsletter.js +109 -0
- package/src/Types/Product.js +2 -0
- package/src/Types/Signal.js +2 -0
- package/src/Types/Socket.js +2 -0
- package/src/Types/State.js +62 -0
- package/src/Types/USync.js +2 -0
- package/src/Types/index.js +56 -0
- package/src/Utils/auth-utils.js +254 -0
- package/src/Utils/browser-utils.js +112 -0
- package/src/Utils/business.js +240 -0
- package/src/Utils/chat-utils.js +1230 -0
- package/src/Utils/command-loader.d.ts +27 -0
- package/src/Utils/command-loader.js +89 -0
- package/src/Utils/companion-reg-client-utils.js +40 -0
- package/src/Utils/consumer-application.js +105 -0
- package/src/Utils/crypto.js +118 -0
- package/src/Utils/curve25519-js.js +242 -0
- package/src/Utils/decode-wa-message.js +529 -0
- package/src/Utils/event-buffer.js +580 -0
- package/src/Utils/generics.js +483 -0
- package/src/Utils/group-history.js +44 -0
- package/src/Utils/history.js +232 -0
- package/src/Utils/identity-change-handler.js +52 -0
- package/src/Utils/index.js +58 -0
- package/src/Utils/jid-display-normalization.js +195 -0
- package/src/Utils/link-preview.js +135 -0
- package/src/Utils/logger.js +8 -0
- package/src/Utils/lt-hash.js +25 -0
- package/src/Utils/make-mutex.js +36 -0
- package/src/Utils/message-composer.js +471 -0
- package/src/Utils/message-retry-manager.js +217 -0
- package/src/Utils/messages-media.js +843 -0
- package/src/Utils/messages.js +2817 -0
- package/src/Utils/meta-ai-msmsg.js +222 -0
- package/src/Utils/native-bridge.js +68 -0
- package/src/Utils/noise-handler.js +169 -0
- package/src/Utils/offline-node-processor.js +34 -0
- package/src/Utils/pre-key-manager.js +90 -0
- package/src/Utils/process-message.js +950 -0
- package/src/Utils/reporting-utils.js +261 -0
- package/src/Utils/session-pool.d.ts +14 -0
- package/src/Utils/session-pool.js +70 -0
- package/src/Utils/signal.js +217 -0
- package/src/Utils/stanza-ack.js +30 -0
- package/src/Utils/sticker.d.ts +13 -0
- package/src/Utils/sticker.js +123 -0
- package/src/Utils/sync-action-utils.js +45 -0
- package/src/Utils/tc-token-utils.js +158 -0
- package/src/Utils/use-multi-file-auth-state.js +111 -0
- package/src/Utils/validate-connection.js +209 -0
- package/src/Utils/view-once-cache.d.ts +12 -0
- package/src/Utils/view-once-cache.js +63 -0
- package/src/Utils/voip-rekey.js +22 -0
- package/src/WABinary/constants.js +1304 -0
- package/src/WABinary/decode.js +342 -0
- package/src/WABinary/encode.js +225 -0
- package/src/WABinary/generic-utils.js +238 -0
- package/src/WABinary/index.js +34 -0
- package/src/WABinary/jid-utils.js +351 -0
- package/src/WABinary/types.js +2 -0
- package/src/WAM/BinaryInfo.js +13 -0
- package/src/WAM/constants.js +39484 -0
- package/src/WAM/encode.js +149 -0
- package/src/WAM/index.js +32 -0
- package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
- package/src/WAUSync/Protocols/USyncBusinessProtocol.js +44 -0
- package/src/WAUSync/Protocols/USyncContactProtocol.js +55 -0
- package/src/WAUSync/Protocols/USyncDeviceProtocol.js +55 -0
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
- package/src/WAUSync/Protocols/USyncFeatureProtocol.js +54 -0
- package/src/WAUSync/Protocols/USyncLIDProtocol.js +32 -0
- package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +473 -0
- package/src/WAUSync/Protocols/USyncPictureProtocol.js +34 -0
- package/src/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
- package/src/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
- package/src/WAUSync/Protocols/USyncUsernameProtocol.js +28 -0
- package/src/WAUSync/Protocols/index.js +40 -0
- package/src/WAUSync/USyncQuery.js +126 -0
- package/src/WAUSync/USyncUser.js +50 -0
- package/src/WAUSync/index.js +32 -0
- package/src/antiban.js +4152 -0
- package/{lib → src}/index.js +51 -49
- package/lib/Defaults/index.js +0 -195
- package/lib/Signal/Group/ciphertext-message.js +0 -15
- package/lib/Signal/Group/group-session-builder.js +0 -92
- package/lib/Signal/Group/group_cipher.js +0 -89
- package/lib/Signal/Group/index.js +0 -136
- package/lib/Signal/Group/keyhelper.js +0 -73
- package/lib/Signal/Group/sender-chain-key.js +0 -32
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
- package/lib/Signal/Group/sender-key-message.js +0 -69
- package/lib/Signal/Group/sender-key-name.js +0 -50
- package/lib/Signal/Group/sender-key-record.js +0 -44
- package/lib/Signal/Group/sender-key-state.js +0 -97
- package/lib/Signal/Group/sender-message-key.js +0 -30
- package/lib/Signal/libsignal.js +0 -470
- package/lib/Signal/lid-mapping.js +0 -280
- package/lib/Socket/Client/index.js +0 -30
- package/lib/Socket/Client/types.js +0 -13
- package/lib/Socket/Client/websocket.js +0 -62
- package/lib/Socket/aigroups.js +0 -240
- package/lib/Socket/business.js +0 -414
- package/lib/Socket/chats.js +0 -2165
- package/lib/Socket/communities.js +0 -545
- package/lib/Socket/graphql.js +0 -863
- package/lib/Socket/groups.js +0 -685
- package/lib/Socket/index.js +0 -41
- package/lib/Socket/interactive-handler.js +0 -579
- package/lib/Socket/interop.js +0 -430
- package/lib/Socket/managed-account.js +0 -214
- package/lib/Socket/messages-recv.js +0 -3000
- package/lib/Socket/messages-send.js +0 -2155
- package/lib/Socket/mex.js +0 -47
- package/lib/Socket/newsletter.js +0 -814
- package/lib/Socket/privacy.js +0 -261
- package/lib/Socket/registration.js +0 -434
- package/lib/Socket/socket.js +0 -1074
- package/lib/Socket/username.js +0 -160
- package/lib/Store/index.js +0 -36
- package/lib/Store/make-cache-manager-store.js +0 -90
- package/lib/Store/make-in-memory-store.js +0 -488
- package/lib/Store/make-ordered-dictionary.js +0 -81
- package/lib/Store/object-repository.js +0 -29
- package/lib/Types/Auth.js +0 -38
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Call.js +0 -2
- package/lib/Types/Chat.js +0 -4
- package/lib/Types/Contact.js +0 -2
- package/lib/Types/Events.js +0 -2
- package/lib/Types/GroupMetadata.js +0 -2
- package/lib/Types/Label.js +0 -27
- package/lib/Types/LabelAssociation.js +0 -9
- package/lib/Types/Message.js +0 -95
- package/lib/Types/Newsletter.js +0 -152
- package/lib/Types/Product.js +0 -2
- package/lib/Types/Signal.js +0 -2
- package/lib/Types/Socket.js +0 -2
- package/lib/Types/State.js +0 -70
- package/lib/Types/USync.js +0 -2
- package/lib/Types/index.js +0 -55
- package/lib/Utils/auth-utils.js +0 -301
- package/lib/Utils/browser-utils.js +0 -114
- package/lib/Utils/business.js +0 -243
- package/lib/Utils/chat-utils.js +0 -1272
- package/lib/Utils/consumer-application.js +0 -107
- package/lib/Utils/crypto.js +0 -125
- package/lib/Utils/decode-wa-message.js +0 -793
- package/lib/Utils/event-buffer.js +0 -583
- package/lib/Utils/generics.js +0 -617
- package/lib/Utils/group-history.js +0 -51
- package/lib/Utils/history.js +0 -244
- package/lib/Utils/identity-change-handler.js +0 -52
- package/lib/Utils/index.js +0 -53
- package/lib/Utils/jid-display-normalization.js +0 -218
- package/lib/Utils/link-preview.js +0 -138
- package/lib/Utils/logger.js +0 -9
- package/lib/Utils/lt-hash.js +0 -6
- package/lib/Utils/make-mutex.js +0 -36
- package/lib/Utils/message-composer.js +0 -479
- package/lib/Utils/message-inspect.js +0 -393
- package/lib/Utils/message-retry-manager.js +0 -205
- package/lib/Utils/messages-media.js +0 -925
- package/lib/Utils/messages.js +0 -2482
- package/lib/Utils/meta-ai-msmsg.js +0 -122
- package/lib/Utils/noise-handler.js +0 -194
- package/lib/Utils/offline-node-processor.js +0 -37
- package/lib/Utils/pre-key-manager.js +0 -97
- package/lib/Utils/process-message.js +0 -1139
- package/lib/Utils/reporting-utils.js +0 -262
- package/lib/Utils/signal.js +0 -189
- package/lib/Utils/stanza-ack.js +0 -67
- package/lib/Utils/sync-action-utils.js +0 -51
- package/lib/Utils/tc-token-utils.js +0 -156
- package/lib/Utils/use-multi-file-auth-state.js +0 -137
- package/lib/Utils/validate-connection.js +0 -259
- package/lib/Utils/voip-rekey.js +0 -22
- package/lib/WABinary/constants.js +0 -1304
- package/lib/WABinary/decode.js +0 -377
- package/lib/WABinary/encode.js +0 -58
- package/lib/WABinary/generic-utils.js +0 -150
- package/lib/WABinary/index.js +0 -33
- package/lib/WABinary/jid-utils.js +0 -374
- package/lib/WABinary/types.js +0 -2
- package/lib/WAM/BinaryInfo.js +0 -13
- package/lib/WAM/constants.js +0 -39486
- package/lib/WAM/encode.js +0 -142
- package/lib/WAM/index.js +0 -31
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -55
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +0 -100
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -60
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -65
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -27
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +0 -72
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -31
- package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -865
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +0 -32
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -44
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -28
- package/lib/WAUSync/Protocols/index.js +0 -40
- package/lib/WAUSync/USyncBackoff.js +0 -26
- package/lib/WAUSync/USyncQuery.js +0 -204
- package/lib/WAUSync/USyncUser.js +0 -58
- package/lib/WAUSync/index.js +0 -32
- package/lib/antiban.js +0 -4391
- /package/{lib → src}/Defaults/phonenumber-mcc.json +0 -0
|
@@ -0,0 +1,1449 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) ||
|
|
3
|
+
function (mod) {
|
|
4
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
7
|
+
exports.makeChatsSocket = void 0;
|
|
8
|
+
const node_cache_1 = __importDefault(require('@cacheable/node-cache'));
|
|
9
|
+
const boom_1 = require('@hapi/boom');
|
|
10
|
+
const index_js_1 = require('../../WAProto/index.js');
|
|
11
|
+
const Defaults_1 = require('../Defaults');
|
|
12
|
+
const Types_1 = require('../Types');
|
|
13
|
+
const State_1 = require('../Types/State');
|
|
14
|
+
const Utils_1 = require('../Utils');
|
|
15
|
+
const make_mutex_1 = require('../Utils/make-mutex');
|
|
16
|
+
const process_message_1 = __importDefault(require('../Utils/process-message'));
|
|
17
|
+
const tc_token_utils_1 = require('../Utils/tc-token-utils');
|
|
18
|
+
const WABinary_1 = require('../WABinary');
|
|
19
|
+
const WAUSync_1 = require('../WAUSync');
|
|
20
|
+
const socket_js_1 = require('./socket.js');
|
|
21
|
+
const interop_js_1 = require('./interop.js');
|
|
22
|
+
const makeChatsSocket = config => {
|
|
23
|
+
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, getMessage } = config;
|
|
24
|
+
const sock = (0, interop_js_1.makeInteropSocket)((0, socket_js_1.makeSocket)(config));
|
|
25
|
+
const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, sendUnifiedSession, initInterop, fetchIntegrators, acceptInteropTOS, optInIntegrators, optOutIntegrators, resolveInteropUser, resolveInteropUsers, getReachabilitySettings, setReachabilitySettings, blockInteropUser, unblockInteropUser, reportInteropSpam, trustInteropContact, createInteropGroup, leaveInteropGroup, getInteropGroupAddPrivacy, INTEGRATOR_BIRDYCHAT, INTEGRATOR_HAIKET } = sock;
|
|
26
|
+
const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
|
|
27
|
+
let privacySettings;
|
|
28
|
+
const serverProps = {
|
|
29
|
+
privacyTokenOn1to1: true,
|
|
30
|
+
profilePicPrivacyToken: true,
|
|
31
|
+
lidTrustedTokenIssueToLid: false
|
|
32
|
+
};
|
|
33
|
+
let syncState = State_1.SyncState.Connecting;
|
|
34
|
+
const messageMutex = (0, make_mutex_1.makeMutex)();
|
|
35
|
+
const receiptMutex = (0, make_mutex_1.makeMutex)();
|
|
36
|
+
const appStatePatchMutex = (0, make_mutex_1.makeMutex)();
|
|
37
|
+
const notificationMutex = (0, make_mutex_1.makeMutex)();
|
|
38
|
+
let awaitingSyncTimeout;
|
|
39
|
+
const historySyncStatus = {
|
|
40
|
+
initialBootstrapComplete: false,
|
|
41
|
+
recentSyncComplete: false
|
|
42
|
+
};
|
|
43
|
+
let historySyncPausedTimeout;
|
|
44
|
+
const blockedCollections = new Set();
|
|
45
|
+
const placeholderResendCache = config.placeholderResendCache ||
|
|
46
|
+
new node_cache_1.default({
|
|
47
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
48
|
+
useClones: false
|
|
49
|
+
});
|
|
50
|
+
if (!config.placeholderResendCache) {
|
|
51
|
+
config.placeholderResendCache = placeholderResendCache;
|
|
52
|
+
}
|
|
53
|
+
const getAppStateSyncKey = async (keyId) => {
|
|
54
|
+
const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
|
|
55
|
+
return key;
|
|
56
|
+
};
|
|
57
|
+
const fetchPrivacySettings = async (force = false) => {
|
|
58
|
+
if (!privacySettings || force) {
|
|
59
|
+
const { content } = await query({
|
|
60
|
+
tag: 'iq',
|
|
61
|
+
attrs: {
|
|
62
|
+
xmlns: 'privacy',
|
|
63
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
64
|
+
type: 'get'
|
|
65
|
+
},
|
|
66
|
+
content: [{ tag: 'privacy', attrs: {} }]
|
|
67
|
+
});
|
|
68
|
+
privacySettings = (0, WABinary_1.reduceBinaryNodeToDictionary)(content?.[0], 'category');
|
|
69
|
+
}
|
|
70
|
+
return privacySettings;
|
|
71
|
+
};
|
|
72
|
+
const privacyQuery = async (name, value) => {
|
|
73
|
+
await query({
|
|
74
|
+
tag: 'iq',
|
|
75
|
+
attrs: {
|
|
76
|
+
xmlns: 'privacy',
|
|
77
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
78
|
+
type: 'set'
|
|
79
|
+
},
|
|
80
|
+
content: [
|
|
81
|
+
{
|
|
82
|
+
tag: 'privacy',
|
|
83
|
+
attrs: {},
|
|
84
|
+
content: [
|
|
85
|
+
{
|
|
86
|
+
tag: 'category',
|
|
87
|
+
attrs: { name, value }
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
const updateMessagesPrivacy = async (value) => {
|
|
95
|
+
await privacyQuery('messages', value);
|
|
96
|
+
};
|
|
97
|
+
const updateCallPrivacy = async (value) => {
|
|
98
|
+
await privacyQuery('calladd', value);
|
|
99
|
+
};
|
|
100
|
+
const updateLastSeenPrivacy = async (value) => {
|
|
101
|
+
await privacyQuery('last', value);
|
|
102
|
+
};
|
|
103
|
+
const updateOnlinePrivacy = async (value) => {
|
|
104
|
+
await privacyQuery('online', value);
|
|
105
|
+
};
|
|
106
|
+
const updateProfilePicturePrivacy = async (value) => {
|
|
107
|
+
await privacyQuery('profile', value);
|
|
108
|
+
};
|
|
109
|
+
const updateStatusPrivacy = async (value) => {
|
|
110
|
+
await privacyQuery('status', value);
|
|
111
|
+
};
|
|
112
|
+
const getStatusPrivacy = async () => {
|
|
113
|
+
const result = await query({
|
|
114
|
+
tag: 'iq',
|
|
115
|
+
attrs: {
|
|
116
|
+
xmlns: 'status',
|
|
117
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
118
|
+
type: 'get'
|
|
119
|
+
},
|
|
120
|
+
content: [{ tag: 'privacy', attrs: {} }]
|
|
121
|
+
});
|
|
122
|
+
const privacyNode = result?.content?.[0];
|
|
123
|
+
if (!privacyNode)
|
|
124
|
+
return null;
|
|
125
|
+
const lists = [];
|
|
126
|
+
for (const listNode of (privacyNode.content || [])) {
|
|
127
|
+
const { type, id, listname, emoji, selected, deleted } = listNode.attrs || {};
|
|
128
|
+
const members = (listNode.content || []).map(u => u.attrs?.jid).filter(Boolean);
|
|
129
|
+
lists.push({ type, id, listname, emoji, selected: selected === 'true', deleted: deleted === 'true', members });
|
|
130
|
+
}
|
|
131
|
+
return lists;
|
|
132
|
+
};
|
|
133
|
+
const setStatusPrivacy = async (type, jids = [], customLists = []) => {
|
|
134
|
+
const content = [];
|
|
135
|
+
const mainList = {
|
|
136
|
+
tag: 'list',
|
|
137
|
+
attrs: { type },
|
|
138
|
+
content: jids.map(jid => ({ tag: 'user', attrs: { jid }, content: [] }))
|
|
139
|
+
};
|
|
140
|
+
content.push(mainList);
|
|
141
|
+
for (const cl of customLists) {
|
|
142
|
+
const attrs = { type: 'customlist', id: cl.id, listname: cl.listname };
|
|
143
|
+
if (cl.emoji)
|
|
144
|
+
attrs.emoji = cl.emoji;
|
|
145
|
+
if (cl.selected)
|
|
146
|
+
attrs.selected = 'true';
|
|
147
|
+
if (cl.deleted)
|
|
148
|
+
attrs.deleted = 'true';
|
|
149
|
+
content.push({
|
|
150
|
+
tag: 'list',
|
|
151
|
+
attrs,
|
|
152
|
+
content: (cl.members || []).map(jid => ({ tag: 'user', attrs: { jid }, content: [] }))
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
await query({
|
|
156
|
+
tag: 'iq',
|
|
157
|
+
attrs: {
|
|
158
|
+
xmlns: 'status',
|
|
159
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
160
|
+
type: 'set'
|
|
161
|
+
},
|
|
162
|
+
content: [{ tag: 'privacy', attrs: {}, content }]
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
const updateReadReceiptsPrivacy = async (value) => {
|
|
166
|
+
await privacyQuery('readreceipts', value);
|
|
167
|
+
};
|
|
168
|
+
const updateGroupsAddPrivacy = async (value) => {
|
|
169
|
+
await privacyQuery('groupadd', value);
|
|
170
|
+
};
|
|
171
|
+
const updateDefaultDisappearingMode = async (duration) => {
|
|
172
|
+
await query({
|
|
173
|
+
tag: 'iq',
|
|
174
|
+
attrs: {
|
|
175
|
+
xmlns: 'disappearing_mode',
|
|
176
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
177
|
+
type: 'set'
|
|
178
|
+
},
|
|
179
|
+
content: [
|
|
180
|
+
{
|
|
181
|
+
tag: 'disappearing_mode',
|
|
182
|
+
attrs: {
|
|
183
|
+
duration: duration.toString()
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
const fetchBroadcastListQuota = async () => {
|
|
190
|
+
const result = await query({
|
|
191
|
+
tag: 'iq',
|
|
192
|
+
attrs: {
|
|
193
|
+
xmlns: 'w:biz',
|
|
194
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
195
|
+
type: 'get'
|
|
196
|
+
},
|
|
197
|
+
content: [{ tag: 'broadcast_list_quota', attrs: {}, content: [] }]
|
|
198
|
+
}, 32000);
|
|
199
|
+
const limitsNode = (0, WABinary_1.getBinaryNodeChild)(result, 'limits');
|
|
200
|
+
const timeframeNode = (0, WABinary_1.getBinaryNodeChild)(result, 'timeframe');
|
|
201
|
+
if (!limitsNode)
|
|
202
|
+
return null;
|
|
203
|
+
return {
|
|
204
|
+
messagesLeft: parseInt(limitsNode.attrs?.messages_left ?? (0, WABinary_1.getBinaryNodeChild)(limitsNode, 'messages_left')?.content ?? '0'),
|
|
205
|
+
totalLimit: parseInt(limitsNode.attrs?.total_limit ?? (0, WABinary_1.getBinaryNodeChild)(limitsNode, 'total_limit')?.content ?? '0'),
|
|
206
|
+
isHeavySender: (limitsNode.attrs?.is_heavy_sender ?? (0, WABinary_1.getBinaryNodeChild)(limitsNode, 'is_heavy_sender')?.content) === 'true',
|
|
207
|
+
startTs: parseInt(timeframeNode?.attrs?.start_ts_s ?? (0, WABinary_1.getBinaryNodeChild)(timeframeNode, 'start_ts_s')?.content ?? '0'),
|
|
208
|
+
endTs: parseInt(timeframeNode?.attrs?.end_ts_s ?? (0, WABinary_1.getBinaryNodeChild)(timeframeNode, 'end_ts_s')?.content ?? '0'),
|
|
209
|
+
resetTs: parseInt(timeframeNode?.attrs?.reset_ts_s ?? (0, WABinary_1.getBinaryNodeChild)(timeframeNode, 'reset_ts_s')?.content ?? '0')
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
const getBotListV2 = async () => {
|
|
213
|
+
const resp = await query({
|
|
214
|
+
tag: 'iq',
|
|
215
|
+
attrs: {
|
|
216
|
+
xmlns: 'bot',
|
|
217
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
218
|
+
type: 'get'
|
|
219
|
+
},
|
|
220
|
+
content: [
|
|
221
|
+
{
|
|
222
|
+
tag: 'bot',
|
|
223
|
+
attrs: {
|
|
224
|
+
v: '2'
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
]
|
|
228
|
+
});
|
|
229
|
+
const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
|
|
230
|
+
const botList = [];
|
|
231
|
+
for (const section of (0, WABinary_1.getBinaryNodeChildren)(botNode, 'section')) {
|
|
232
|
+
if (section.attrs.type === 'all') {
|
|
233
|
+
for (const bot of (0, WABinary_1.getBinaryNodeChildren)(section, 'bot')) {
|
|
234
|
+
botList.push({
|
|
235
|
+
jid: bot.attrs.jid,
|
|
236
|
+
personaId: bot.attrs['persona_id']
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return botList;
|
|
242
|
+
};
|
|
243
|
+
const getChatBlockingStatus = async () => {
|
|
244
|
+
const result = await query({
|
|
245
|
+
tag: 'iq',
|
|
246
|
+
attrs: {
|
|
247
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
248
|
+
xmlns: 'w:comms:chat',
|
|
249
|
+
type: 'get'
|
|
250
|
+
},
|
|
251
|
+
content: [{ tag: 'query', attrs: {}, content: [{ tag: 'blocking_status', attrs: {} }] }]
|
|
252
|
+
});
|
|
253
|
+
const blocking = (0, WABinary_1.getBinaryNodeChild)(result, 'blocking') ||
|
|
254
|
+
(0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(result, 'query'), 'blocking');
|
|
255
|
+
return blocking?.attrs?.status;
|
|
256
|
+
};
|
|
257
|
+
const updateChatBlockingStatus = async (action) => {
|
|
258
|
+
const result = await query({
|
|
259
|
+
tag: 'iq',
|
|
260
|
+
attrs: {
|
|
261
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
262
|
+
xmlns: 'w:comms:chat',
|
|
263
|
+
type: 'set'
|
|
264
|
+
},
|
|
265
|
+
content: [{ tag: 'blocking', attrs: { action } }]
|
|
266
|
+
});
|
|
267
|
+
const blocking = (0, WABinary_1.getBinaryNodeChild)(result, 'blocking');
|
|
268
|
+
return blocking?.attrs?.status;
|
|
269
|
+
};
|
|
270
|
+
const getUserDisclosures = async (t = 0) => {
|
|
271
|
+
const result = await query({
|
|
272
|
+
tag: 'iq',
|
|
273
|
+
attrs: { to: WABinary_1.S_WHATSAPP_NET, xmlns: 'tos', type: 'get' },
|
|
274
|
+
content: [{ tag: 'get_user_disclosures', attrs: { t: String(t) } }]
|
|
275
|
+
});
|
|
276
|
+
return (0, WABinary_1.getBinaryNodeChildren)(result, 'notice').map(n => ({ ...n.attrs }));
|
|
277
|
+
};
|
|
278
|
+
const getOptOutList = async () => {
|
|
279
|
+
return query({
|
|
280
|
+
tag: 'iq',
|
|
281
|
+
attrs: { to: WABinary_1.S_WHATSAPP_NET, xmlns: 'optoutlist', type: 'get' }
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
const getPushConfig = async () => {
|
|
285
|
+
const result = await query({
|
|
286
|
+
tag: 'iq',
|
|
287
|
+
attrs: { to: WABinary_1.S_WHATSAPP_NET, xmlns: 'urn:xmpp:whatsapp:push', type: 'get' },
|
|
288
|
+
content: [{ tag: 'settings', attrs: {} }]
|
|
289
|
+
});
|
|
290
|
+
return (0, WABinary_1.getBinaryNodeChild)(result, 'settings');
|
|
291
|
+
};
|
|
292
|
+
const setPushConfig = async (config) => {
|
|
293
|
+
await query({
|
|
294
|
+
tag: 'iq',
|
|
295
|
+
attrs: { to: WABinary_1.S_WHATSAPP_NET, xmlns: 'urn:xmpp:whatsapp:push', type: 'set' },
|
|
296
|
+
content: [{ tag: 'config', attrs: config }]
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
const fetchStatus = async (...jids) => {
|
|
300
|
+
const usyncQuery = new WAUSync_1.USyncQuery().withStatusProtocol();
|
|
301
|
+
for (const jid of jids) {
|
|
302
|
+
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
303
|
+
}
|
|
304
|
+
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
305
|
+
if (result) {
|
|
306
|
+
return result.list;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
const fetchDisappearingDuration = async (...jids) => {
|
|
310
|
+
const usyncQuery = new WAUSync_1.USyncQuery().withDisappearingModeProtocol();
|
|
311
|
+
for (const jid of jids) {
|
|
312
|
+
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
313
|
+
}
|
|
314
|
+
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
315
|
+
if (result) {
|
|
316
|
+
return result.list;
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
const updateProfilePicture = async (jid, content, dimensions) => {
|
|
320
|
+
let targetJid;
|
|
321
|
+
if (!jid) {
|
|
322
|
+
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');
|
|
323
|
+
}
|
|
324
|
+
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
325
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
targetJid = undefined;
|
|
329
|
+
}
|
|
330
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content, dimensions);
|
|
331
|
+
await query({
|
|
332
|
+
tag: 'iq',
|
|
333
|
+
attrs: {
|
|
334
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
335
|
+
type: 'set',
|
|
336
|
+
xmlns: 'w:profile:picture',
|
|
337
|
+
...(targetJid ? { target: targetJid } : {})
|
|
338
|
+
},
|
|
339
|
+
content: [
|
|
340
|
+
{
|
|
341
|
+
tag: 'picture',
|
|
342
|
+
attrs: { type: 'image' },
|
|
343
|
+
content: img
|
|
344
|
+
}
|
|
345
|
+
]
|
|
346
|
+
});
|
|
347
|
+
};
|
|
348
|
+
const removeProfilePicture = async (jid) => {
|
|
349
|
+
let targetJid;
|
|
350
|
+
if (!jid) {
|
|
351
|
+
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');
|
|
352
|
+
}
|
|
353
|
+
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
|
354
|
+
targetJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
targetJid = undefined;
|
|
358
|
+
}
|
|
359
|
+
await query({
|
|
360
|
+
tag: 'iq',
|
|
361
|
+
attrs: {
|
|
362
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
363
|
+
type: 'set',
|
|
364
|
+
xmlns: 'w:profile:picture',
|
|
365
|
+
...(targetJid ? { target: targetJid } : {})
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
const updateProfileStatus = async (status) => {
|
|
370
|
+
await query({
|
|
371
|
+
tag: 'iq',
|
|
372
|
+
attrs: {
|
|
373
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
374
|
+
type: 'set',
|
|
375
|
+
xmlns: 'status'
|
|
376
|
+
},
|
|
377
|
+
content: [
|
|
378
|
+
{
|
|
379
|
+
tag: 'status',
|
|
380
|
+
attrs: {},
|
|
381
|
+
content: Buffer.from(status, 'utf-8')
|
|
382
|
+
}
|
|
383
|
+
]
|
|
384
|
+
});
|
|
385
|
+
};
|
|
386
|
+
const updateProfileName = async (name) => {
|
|
387
|
+
await chatModify({ pushNameSetting: name }, '');
|
|
388
|
+
};
|
|
389
|
+
const fetchBlocklist = async () => {
|
|
390
|
+
const result = await query({
|
|
391
|
+
tag: 'iq',
|
|
392
|
+
attrs: {
|
|
393
|
+
xmlns: 'blocklist',
|
|
394
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
395
|
+
type: 'get'
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
const listNode = (0, WABinary_1.getBinaryNodeChild)(result, 'list');
|
|
399
|
+
return (0, WABinary_1.getBinaryNodeChildren)(listNode, 'item').map(n => n.attrs.jid);
|
|
400
|
+
};
|
|
401
|
+
const updateBlockStatus = async (jid, action) => {
|
|
402
|
+
await query({
|
|
403
|
+
tag: 'iq',
|
|
404
|
+
attrs: {
|
|
405
|
+
xmlns: 'blocklist',
|
|
406
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
407
|
+
type: 'set'
|
|
408
|
+
},
|
|
409
|
+
content: [
|
|
410
|
+
{
|
|
411
|
+
tag: 'item',
|
|
412
|
+
attrs: {
|
|
413
|
+
action,
|
|
414
|
+
jid
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
]
|
|
418
|
+
});
|
|
419
|
+
};
|
|
420
|
+
const getBusinessProfile = async (jid) => {
|
|
421
|
+
const results = await query({
|
|
422
|
+
tag: 'iq',
|
|
423
|
+
attrs: {
|
|
424
|
+
to: 's.whatsapp.net',
|
|
425
|
+
xmlns: 'w:biz',
|
|
426
|
+
type: 'get'
|
|
427
|
+
},
|
|
428
|
+
content: [
|
|
429
|
+
{
|
|
430
|
+
tag: 'business_profile',
|
|
431
|
+
attrs: { v: '244' },
|
|
432
|
+
content: [
|
|
433
|
+
{
|
|
434
|
+
tag: 'profile',
|
|
435
|
+
attrs: { jid }
|
|
436
|
+
}
|
|
437
|
+
]
|
|
438
|
+
}
|
|
439
|
+
]
|
|
440
|
+
});
|
|
441
|
+
const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
|
|
442
|
+
const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
|
|
443
|
+
if (profiles) {
|
|
444
|
+
const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
|
|
445
|
+
const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
|
|
446
|
+
const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
|
|
447
|
+
const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
|
|
448
|
+
const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
|
|
449
|
+
const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
|
|
450
|
+
const businessHoursConfig = businessHours
|
|
451
|
+
? (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config')
|
|
452
|
+
: undefined;
|
|
453
|
+
const websiteStr = website?.content?.toString();
|
|
454
|
+
return {
|
|
455
|
+
wid: profiles.attrs?.jid,
|
|
456
|
+
address: address?.content?.toString(),
|
|
457
|
+
description: description?.content?.toString() || '',
|
|
458
|
+
website: websiteStr ? [websiteStr] : [],
|
|
459
|
+
email: email?.content?.toString(),
|
|
460
|
+
category: category?.content?.toString(),
|
|
461
|
+
business_hours: {
|
|
462
|
+
timezone: businessHours?.attrs?.timezone,
|
|
463
|
+
business_config: businessHoursConfig?.map(({ attrs }) => attrs)
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
const cleanDirtyBits = async (type, fromTimestamp) => {
|
|
469
|
+
logger.info({ fromTimestamp }, 'clean dirty bits ' + type);
|
|
470
|
+
await sendNode({
|
|
471
|
+
tag: 'iq',
|
|
472
|
+
attrs: {
|
|
473
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
474
|
+
type: 'set',
|
|
475
|
+
xmlns: 'urn:xmpp:whatsapp:dirty',
|
|
476
|
+
id: generateMessageTag()
|
|
477
|
+
},
|
|
478
|
+
content: [
|
|
479
|
+
{
|
|
480
|
+
tag: 'clean',
|
|
481
|
+
attrs: {
|
|
482
|
+
type,
|
|
483
|
+
...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null)
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
]
|
|
487
|
+
});
|
|
488
|
+
};
|
|
489
|
+
const newAppStateChunkHandler = isInitialSync => {
|
|
490
|
+
return {
|
|
491
|
+
onMutation(mutation) {
|
|
492
|
+
;
|
|
493
|
+
(0, Utils_1.processSyncAction)(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
};
|
|
497
|
+
const resyncAppState = ev.createBufferedFunction(async (collections, isInitialSync) => {
|
|
498
|
+
const appStateSyncKeyCache = new Map();
|
|
499
|
+
const getCachedAppStateSyncKey = async (keyId) => {
|
|
500
|
+
if (appStateSyncKeyCache.has(keyId)) {
|
|
501
|
+
return appStateSyncKeyCache.get(keyId) ?? undefined;
|
|
502
|
+
}
|
|
503
|
+
const key = await getAppStateSyncKey(keyId);
|
|
504
|
+
appStateSyncKeyCache.set(keyId, key ?? null);
|
|
505
|
+
return key;
|
|
506
|
+
};
|
|
507
|
+
const initialVersionMap = {};
|
|
508
|
+
const globalMutationMap = {};
|
|
509
|
+
await authState.keys.transaction(async () => {
|
|
510
|
+
const collectionsToHandle = new Set(collections);
|
|
511
|
+
const attemptsMap = {};
|
|
512
|
+
const forceSnapshotCollections = new Set();
|
|
513
|
+
while (collectionsToHandle.size) {
|
|
514
|
+
const states = {};
|
|
515
|
+
const nodes = [];
|
|
516
|
+
for (const name of collectionsToHandle) {
|
|
517
|
+
const result = await authState.keys.get('app-state-sync-version', [name]);
|
|
518
|
+
let state = result[name];
|
|
519
|
+
if (state) {
|
|
520
|
+
if (typeof initialVersionMap[name] === 'undefined') {
|
|
521
|
+
initialVersionMap[name] = state.version;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
state = (0, Utils_1.newLTHashState)();
|
|
526
|
+
}
|
|
527
|
+
states[name] = state;
|
|
528
|
+
const shouldForceSnapshot = forceSnapshotCollections.has(name);
|
|
529
|
+
if (shouldForceSnapshot) {
|
|
530
|
+
forceSnapshotCollections.delete(name);
|
|
531
|
+
}
|
|
532
|
+
logger.info(`resyncing ${name} from v${state.version}${shouldForceSnapshot ? ' (forcing snapshot)' : ''}`);
|
|
533
|
+
nodes.push({
|
|
534
|
+
tag: 'collection',
|
|
535
|
+
attrs: {
|
|
536
|
+
name,
|
|
537
|
+
version: state.version.toString(),
|
|
538
|
+
return_snapshot: (shouldForceSnapshot || !state.version).toString()
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
const result = await query({
|
|
543
|
+
tag: 'iq',
|
|
544
|
+
attrs: {
|
|
545
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
546
|
+
xmlns: 'w:sync:app:state',
|
|
547
|
+
type: 'set'
|
|
548
|
+
},
|
|
549
|
+
content: [
|
|
550
|
+
{
|
|
551
|
+
tag: 'sync',
|
|
552
|
+
attrs: {},
|
|
553
|
+
content: nodes
|
|
554
|
+
}
|
|
555
|
+
]
|
|
556
|
+
});
|
|
557
|
+
const decoded = await (0, Utils_1.extractSyncdPatches)(result, config?.options);
|
|
558
|
+
for (const key in decoded) {
|
|
559
|
+
const name = key;
|
|
560
|
+
const { patches, hasMorePatches, snapshot } = decoded[name];
|
|
561
|
+
try {
|
|
562
|
+
if (snapshot) {
|
|
563
|
+
const { state: newState, mutationMap } = await (0, Utils_1.decodeSyncdSnapshot)(name, snapshot, getCachedAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
|
|
564
|
+
states[name] = newState;
|
|
565
|
+
Object.assign(globalMutationMap, mutationMap);
|
|
566
|
+
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
567
|
+
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
568
|
+
}
|
|
569
|
+
if (patches.length) {
|
|
570
|
+
const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getCachedAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
571
|
+
await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
|
|
572
|
+
logger.info(`synced ${name} to v${newState.version}`);
|
|
573
|
+
initialVersionMap[name] = newState.version;
|
|
574
|
+
Object.assign(globalMutationMap, mutationMap);
|
|
575
|
+
}
|
|
576
|
+
if (hasMorePatches) {
|
|
577
|
+
logger.info(`${name} has more patches...`);
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
collectionsToHandle.delete(name);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
catch (error) {
|
|
584
|
+
attemptsMap[name] = (attemptsMap[name] || 0) + 1;
|
|
585
|
+
const logData = {
|
|
586
|
+
name,
|
|
587
|
+
attempt: attemptsMap[name],
|
|
588
|
+
version: states[name].version,
|
|
589
|
+
statusCode: error.output?.statusCode,
|
|
590
|
+
errorType: error.name,
|
|
591
|
+
error: error.stack
|
|
592
|
+
};
|
|
593
|
+
if ((0, Utils_1.isMissingKeyError)(error) && attemptsMap[name] >= Utils_1.MAX_SYNC_ATTEMPTS) {
|
|
594
|
+
logger.warn(logData, `${name} blocked on missing key from v${states[name].version}, parking after ${attemptsMap[name]} attempts`);
|
|
595
|
+
blockedCollections.add(name);
|
|
596
|
+
collectionsToHandle.delete(name);
|
|
597
|
+
}
|
|
598
|
+
else if ((0, Utils_1.isMissingKeyError)(error)) {
|
|
599
|
+
logger.info(logData, `${name} blocked on missing key from v${states[name].version}, retrying with snapshot`);
|
|
600
|
+
forceSnapshotCollections.add(name);
|
|
601
|
+
}
|
|
602
|
+
else if ((0, Utils_1.isAppStateSyncIrrecoverable)(error, attemptsMap[name])) {
|
|
603
|
+
logger.warn(logData, `failed to sync ${name} from v${states[name].version}, giving up`);
|
|
604
|
+
collectionsToHandle.delete(name);
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
logger.info(logData, `failed to sync ${name} from v${states[name].version}, forcing snapshot retry`);
|
|
608
|
+
forceSnapshotCollections.add(name);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}, authState?.creds?.me?.id || 'resync-app-state');
|
|
614
|
+
const { onMutation } = newAppStateChunkHandler(isInitialSync);
|
|
615
|
+
for (const key in globalMutationMap) {
|
|
616
|
+
onMutation(globalMutationMap[key]);
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
|
|
620
|
+
const picAttrs = type === 'image' ? { type, query: 'url' } : { type };
|
|
621
|
+
const baseContent = [{ tag: 'picture', attrs: picAttrs }];
|
|
622
|
+
const normalizedJid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
623
|
+
const isUserJid = (0, WABinary_1.isPnUser)(normalizedJid) || (0, WABinary_1.isLidUser)(normalizedJid);
|
|
624
|
+
const me = authState.creds.me;
|
|
625
|
+
const isSelf = me &&
|
|
626
|
+
(normalizedJid === (0, WABinary_1.jidNormalizedUser)(me.id) ||
|
|
627
|
+
(me.lid && normalizedJid === (0, WABinary_1.jidNormalizedUser)(me.lid)));
|
|
628
|
+
let content = baseContent;
|
|
629
|
+
if (serverProps.profilePicPrivacyToken && isUserJid && !isSelf) {
|
|
630
|
+
content = await (0, tc_token_utils_1.buildTcTokenFromJid)({
|
|
631
|
+
authState,
|
|
632
|
+
jid: normalizedJid,
|
|
633
|
+
baseContent,
|
|
634
|
+
getLIDForPN
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
638
|
+
const result = await query({
|
|
639
|
+
tag: 'iq',
|
|
640
|
+
attrs: {
|
|
641
|
+
target: jid,
|
|
642
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
643
|
+
type: 'get',
|
|
644
|
+
xmlns: 'w:profile:picture'
|
|
645
|
+
},
|
|
646
|
+
content
|
|
647
|
+
}, timeoutMs);
|
|
648
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
|
|
649
|
+
return child?.attrs?.url;
|
|
650
|
+
};
|
|
651
|
+
const createCallLink = async (type, event, timeoutMs) => {
|
|
652
|
+
const result = await query({
|
|
653
|
+
tag: 'call',
|
|
654
|
+
attrs: {
|
|
655
|
+
id: generateMessageTag(),
|
|
656
|
+
to: '@call'
|
|
657
|
+
},
|
|
658
|
+
content: [
|
|
659
|
+
{
|
|
660
|
+
tag: 'link_create',
|
|
661
|
+
attrs: { media: type },
|
|
662
|
+
content: event ? [{ tag: 'event', attrs: { start_time: String(event.startTime) } }] : undefined
|
|
663
|
+
}
|
|
664
|
+
]
|
|
665
|
+
}, timeoutMs);
|
|
666
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'link_create');
|
|
667
|
+
return child?.attrs?.token;
|
|
668
|
+
};
|
|
669
|
+
const toggleCallLinkWaitingRoom = async (linkToken, enabled, media = 'audio') => {
|
|
670
|
+
const result = await query({
|
|
671
|
+
tag: 'call',
|
|
672
|
+
attrs: { id: generateMessageTag(), to: '@call' },
|
|
673
|
+
content: [
|
|
674
|
+
{
|
|
675
|
+
tag: 'waiting_room_toggle',
|
|
676
|
+
attrs: { enabled: enabled ? '1' : '0', 'link-token': linkToken, media }
|
|
677
|
+
}
|
|
678
|
+
]
|
|
679
|
+
});
|
|
680
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'waiting_room_toggle');
|
|
681
|
+
return child?.attrs;
|
|
682
|
+
};
|
|
683
|
+
const sendPresenceUpdate = async (type, toJid) => {
|
|
684
|
+
const me = authState.creds.me;
|
|
685
|
+
const isAvailableType = type === 'available';
|
|
686
|
+
if (isAvailableType || type === 'unavailable') {
|
|
687
|
+
if (!me.name) {
|
|
688
|
+
logger.warn('no name present, ignoring presence update request...');
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
ev.emit('connection.update', { isOnline: isAvailableType });
|
|
692
|
+
if (isAvailableType) {
|
|
693
|
+
void sendUnifiedSession();
|
|
694
|
+
}
|
|
695
|
+
await sendNode({
|
|
696
|
+
tag: 'presence',
|
|
697
|
+
attrs: {
|
|
698
|
+
name: me.name.replace(/@/g, ''),
|
|
699
|
+
type
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
else {
|
|
704
|
+
const { server } = (0, WABinary_1.jidDecode)(toJid);
|
|
705
|
+
const isLid = server === 'lid';
|
|
706
|
+
await sendNode({
|
|
707
|
+
tag: 'chatstate',
|
|
708
|
+
attrs: {
|
|
709
|
+
from: isLid ? me.lid : me.id,
|
|
710
|
+
to: toJid
|
|
711
|
+
},
|
|
712
|
+
content: [
|
|
713
|
+
{
|
|
714
|
+
tag: type === 'recording' ? 'composing' : type,
|
|
715
|
+
attrs: type === 'recording' ? { media: 'audio' } : {}
|
|
716
|
+
}
|
|
717
|
+
]
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
const presenceSubscribe = async (toJid) => {
|
|
722
|
+
const normalizedToJid = (0, WABinary_1.jidNormalizedUser)(toJid);
|
|
723
|
+
const isUserJid = (0, WABinary_1.isPnUser)(normalizedToJid) || (0, WABinary_1.isLidUser)(normalizedToJid);
|
|
724
|
+
const tcTokenContent = isUserJid
|
|
725
|
+
? await (0, tc_token_utils_1.buildTcTokenFromJid)({ authState, jid: normalizedToJid, getLIDForPN })
|
|
726
|
+
: undefined;
|
|
727
|
+
return sendNode({
|
|
728
|
+
tag: 'presence',
|
|
729
|
+
attrs: {
|
|
730
|
+
to: toJid,
|
|
731
|
+
id: generateMessageTag(),
|
|
732
|
+
type: 'subscribe'
|
|
733
|
+
},
|
|
734
|
+
content: tcTokenContent
|
|
735
|
+
});
|
|
736
|
+
};
|
|
737
|
+
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
738
|
+
let presence;
|
|
739
|
+
const jid = attrs.from;
|
|
740
|
+
const participant = attrs.participant || attrs.from;
|
|
741
|
+
if (shouldIgnoreJid(jid) && jid !== WABinary_1.S_WHATSAPP_NET) {
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
if (tag === 'presence') {
|
|
745
|
+
presence = {
|
|
746
|
+
lastKnownPresence: attrs.type === 'unavailable' ? 'unavailable' : 'available',
|
|
747
|
+
lastSeen: attrs.last && attrs.last !== 'deny' ? +attrs.last : undefined
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
else if (Array.isArray(content)) {
|
|
751
|
+
const [firstChild] = content;
|
|
752
|
+
let type = firstChild.tag;
|
|
753
|
+
if (type === 'paused') {
|
|
754
|
+
type = 'available';
|
|
755
|
+
}
|
|
756
|
+
if (firstChild.attrs?.media === 'audio') {
|
|
757
|
+
type = 'recording';
|
|
758
|
+
}
|
|
759
|
+
presence = { lastKnownPresence: type };
|
|
760
|
+
}
|
|
761
|
+
else {
|
|
762
|
+
logger.error({ tag, attrs, content }, 'recv invalid presence node');
|
|
763
|
+
}
|
|
764
|
+
if (presence) {
|
|
765
|
+
ev.emit('presence.update', { id: jid, presences: { [participant]: presence } });
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
const appPatch = async (patchCreate) => {
|
|
769
|
+
const name = patchCreate.type;
|
|
770
|
+
const myAppStateKeyId = authState.creds.myAppStateKeyId;
|
|
771
|
+
if (!myAppStateKeyId) {
|
|
772
|
+
throw new boom_1.Boom('App state key not present!', { statusCode: 400 });
|
|
773
|
+
}
|
|
774
|
+
let initial;
|
|
775
|
+
let encodeResult;
|
|
776
|
+
await appStatePatchMutex.mutex(async () => {
|
|
777
|
+
await authState.keys.transaction(async () => {
|
|
778
|
+
logger.debug({ patch: patchCreate }, 'applying app patch');
|
|
779
|
+
await resyncAppState([name], false);
|
|
780
|
+
const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name]);
|
|
781
|
+
initial = currentSyncVersion || (0, Utils_1.newLTHashState)();
|
|
782
|
+
encodeResult = await (0, Utils_1.encodeSyncdPatch)(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
|
|
783
|
+
const { patch, state } = encodeResult;
|
|
784
|
+
const node = {
|
|
785
|
+
tag: 'iq',
|
|
786
|
+
attrs: {
|
|
787
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
788
|
+
type: 'set',
|
|
789
|
+
xmlns: 'w:sync:app:state'
|
|
790
|
+
},
|
|
791
|
+
content: [
|
|
792
|
+
{
|
|
793
|
+
tag: 'sync',
|
|
794
|
+
attrs: {},
|
|
795
|
+
content: [
|
|
796
|
+
{
|
|
797
|
+
tag: 'collection',
|
|
798
|
+
attrs: {
|
|
799
|
+
name,
|
|
800
|
+
version: (state.version - 1).toString(),
|
|
801
|
+
return_snapshot: 'false'
|
|
802
|
+
},
|
|
803
|
+
content: [
|
|
804
|
+
{
|
|
805
|
+
tag: 'patch',
|
|
806
|
+
attrs: {},
|
|
807
|
+
content: index_js_1.proto.SyncdPatch.encode(patch).finish()
|
|
808
|
+
}
|
|
809
|
+
]
|
|
810
|
+
}
|
|
811
|
+
]
|
|
812
|
+
}
|
|
813
|
+
]
|
|
814
|
+
};
|
|
815
|
+
await query(node);
|
|
816
|
+
await authState.keys.set({ 'app-state-sync-version': { [name]: state } });
|
|
817
|
+
}, authState?.creds?.me?.id || 'app-patch');
|
|
818
|
+
});
|
|
819
|
+
if (config.emitOwnEvents) {
|
|
820
|
+
const { onMutation } = newAppStateChunkHandler(false);
|
|
821
|
+
const { mutationMap } = await (0, Utils_1.decodePatches)(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
822
|
+
for (const key in mutationMap) {
|
|
823
|
+
onMutation(mutationMap[key]);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
const fetchProps = async () => {
|
|
828
|
+
const resultNode = await query({
|
|
829
|
+
tag: 'iq',
|
|
830
|
+
attrs: {
|
|
831
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
832
|
+
xmlns: 'w',
|
|
833
|
+
type: 'get'
|
|
834
|
+
},
|
|
835
|
+
content: [
|
|
836
|
+
{
|
|
837
|
+
tag: 'props',
|
|
838
|
+
attrs: {
|
|
839
|
+
protocol: '2',
|
|
840
|
+
hash: authState?.creds?.lastPropHash || ''
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
]
|
|
844
|
+
});
|
|
845
|
+
const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
|
|
846
|
+
let props = {};
|
|
847
|
+
if (propsNode) {
|
|
848
|
+
if (propsNode.attrs?.hash) {
|
|
849
|
+
authState.creds.lastPropHash = propsNode?.attrs?.hash;
|
|
850
|
+
ev.emit('creds.update', authState.creds);
|
|
851
|
+
}
|
|
852
|
+
props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
|
|
853
|
+
}
|
|
854
|
+
const privacyTokenProp = props['10518'] ?? props['privacy_token_sending_on_all_1_on_1_messages'];
|
|
855
|
+
if (privacyTokenProp !== undefined) {
|
|
856
|
+
serverProps.privacyTokenOn1to1 = privacyTokenProp === 'true' || privacyTokenProp === '1';
|
|
857
|
+
}
|
|
858
|
+
const profilePicProp = props['9666'] ?? props['profile_scraping_privacy_token_in_photo_iq'];
|
|
859
|
+
if (profilePicProp !== undefined) {
|
|
860
|
+
serverProps.profilePicPrivacyToken = profilePicProp === 'true' || profilePicProp === '1';
|
|
861
|
+
}
|
|
862
|
+
const lidIssueProp = props['14303'] ?? props['lid_trusted_token_issue_to_lid'];
|
|
863
|
+
if (lidIssueProp !== undefined) {
|
|
864
|
+
serverProps.lidTrustedTokenIssueToLid = lidIssueProp === 'true' || lidIssueProp === '1';
|
|
865
|
+
}
|
|
866
|
+
logger.debug({ serverProps }, 'fetched props');
|
|
867
|
+
return props;
|
|
868
|
+
};
|
|
869
|
+
const chatModify = (mod, jid) => {
|
|
870
|
+
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
871
|
+
return appPatch(patch);
|
|
872
|
+
};
|
|
873
|
+
const updateDisableLinkPreviewsPrivacy = isPreviewsDisabled => {
|
|
874
|
+
return chatModify({
|
|
875
|
+
disableLinkPreviews: { isPreviewsDisabled }
|
|
876
|
+
}, '');
|
|
877
|
+
};
|
|
878
|
+
const star = (jid, messages, star) => {
|
|
879
|
+
return chatModify({
|
|
880
|
+
star: {
|
|
881
|
+
messages,
|
|
882
|
+
star
|
|
883
|
+
}
|
|
884
|
+
}, jid);
|
|
885
|
+
};
|
|
886
|
+
const addOrEditContact = (jid, contact) => {
|
|
887
|
+
return chatModify({
|
|
888
|
+
contact
|
|
889
|
+
}, jid);
|
|
890
|
+
};
|
|
891
|
+
const removeContact = jid => {
|
|
892
|
+
return chatModify({
|
|
893
|
+
contact: null
|
|
894
|
+
}, jid);
|
|
895
|
+
};
|
|
896
|
+
const addLabel = (jid, labels) => {
|
|
897
|
+
return chatModify({
|
|
898
|
+
addLabel: {
|
|
899
|
+
...labels
|
|
900
|
+
}
|
|
901
|
+
}, jid);
|
|
902
|
+
};
|
|
903
|
+
const addChatLabel = (jid, labelId) => {
|
|
904
|
+
return chatModify({
|
|
905
|
+
addChatLabel: {
|
|
906
|
+
labelId
|
|
907
|
+
}
|
|
908
|
+
}, jid);
|
|
909
|
+
};
|
|
910
|
+
const removeChatLabel = (jid, labelId) => {
|
|
911
|
+
return chatModify({
|
|
912
|
+
removeChatLabel: {
|
|
913
|
+
labelId
|
|
914
|
+
}
|
|
915
|
+
}, jid);
|
|
916
|
+
};
|
|
917
|
+
const addMessageLabel = (jid, messageId, labelId) => {
|
|
918
|
+
return chatModify({
|
|
919
|
+
addMessageLabel: {
|
|
920
|
+
messageId,
|
|
921
|
+
labelId
|
|
922
|
+
}
|
|
923
|
+
}, jid);
|
|
924
|
+
};
|
|
925
|
+
const removeMessageLabel = (jid, messageId, labelId) => {
|
|
926
|
+
return chatModify({
|
|
927
|
+
removeMessageLabel: {
|
|
928
|
+
messageId,
|
|
929
|
+
labelId
|
|
930
|
+
}
|
|
931
|
+
}, jid);
|
|
932
|
+
};
|
|
933
|
+
const addOrEditQuickReply = quickReply => {
|
|
934
|
+
return chatModify({
|
|
935
|
+
quickReply
|
|
936
|
+
}, '');
|
|
937
|
+
};
|
|
938
|
+
const removeQuickReply = timestamp => {
|
|
939
|
+
return chatModify({
|
|
940
|
+
quickReply: { timestamp, deleted: true }
|
|
941
|
+
}, '');
|
|
942
|
+
};
|
|
943
|
+
const renameAIThread = (jid, title) => {
|
|
944
|
+
return chatModify({ aiThreadRename: { title } }, jid);
|
|
945
|
+
};
|
|
946
|
+
const pinThreadMessage = (jid, messageId, pinned = true) => {
|
|
947
|
+
return chatModify({ threadPin: { pinned, messageId } }, jid);
|
|
948
|
+
};
|
|
949
|
+
const updatePrivateProcessingSetting = enabled => {
|
|
950
|
+
return chatModify({ privateProcessingSetting: enabled ? 'enabled' : 'disabled' }, '');
|
|
951
|
+
};
|
|
952
|
+
const updateBioPrivacy = async (value) => {
|
|
953
|
+
await privacyQuery('about', value);
|
|
954
|
+
};
|
|
955
|
+
const blockBot = async (botJid) => {
|
|
956
|
+
await query({
|
|
957
|
+
tag: 'iq',
|
|
958
|
+
attrs: {
|
|
959
|
+
xmlns: 'disappearing_mode',
|
|
960
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
961
|
+
type: 'set'
|
|
962
|
+
},
|
|
963
|
+
content: [
|
|
964
|
+
{
|
|
965
|
+
tag: 'block',
|
|
966
|
+
attrs: { jid: botJid }
|
|
967
|
+
}
|
|
968
|
+
]
|
|
969
|
+
});
|
|
970
|
+
};
|
|
971
|
+
const unblockBot = async (botJid) => {
|
|
972
|
+
await updateBlockStatus(botJid, 'unblock');
|
|
973
|
+
};
|
|
974
|
+
const muteContactStatus = (jid, muted = true) => {
|
|
975
|
+
return chatModify({ muteStatus: { muted } }, jid);
|
|
976
|
+
};
|
|
977
|
+
const toggleFavorite = (jid, isFavorite = true) => {
|
|
978
|
+
return chatModify({ favorite: { isFavorite } }, jid);
|
|
979
|
+
};
|
|
980
|
+
const reorderLabels = sortedLabelIds => {
|
|
981
|
+
return chatModify({ reorderLabel: { sortedLabelIds } }, '');
|
|
982
|
+
};
|
|
983
|
+
const deleteCallLog = (callId, jid = '') => {
|
|
984
|
+
return chatModify({ deleteCallLog: { callId } }, jid);
|
|
985
|
+
};
|
|
986
|
+
const setChatNote = (jid, note) => {
|
|
987
|
+
return chatModify({ noteEdit: { note } }, jid);
|
|
988
|
+
};
|
|
989
|
+
const deleteChatNote = jid => {
|
|
990
|
+
return chatModify({ noteEdit: { note: '', deleted: true } }, jid);
|
|
991
|
+
};
|
|
992
|
+
const markChatAsUnread = (jid, lastMessages) => {
|
|
993
|
+
return chatModify({ markAsUnread: true, lastMessages }, jid);
|
|
994
|
+
};
|
|
995
|
+
const setChatEphemeral = (jid, duration) => {
|
|
996
|
+
return chatModify({ setChatEphemeral: duration }, jid);
|
|
997
|
+
};
|
|
998
|
+
const silenceChat = (jid, silent = true, until = null) => {
|
|
999
|
+
return chatModify({ silenceChat: { silent, until } }, jid);
|
|
1000
|
+
};
|
|
1001
|
+
const fetchBotProfiles = async (jids) => {
|
|
1002
|
+
const { USyncQuery, USyncUser, USyncBotProfileProtocol } = require('../WAUSync');
|
|
1003
|
+
const q = new USyncQuery();
|
|
1004
|
+
q.protocols.push(new USyncBotProfileProtocol());
|
|
1005
|
+
for (const jid of jids) {
|
|
1006
|
+
q.withUser(new USyncUser().withId(jid));
|
|
1007
|
+
}
|
|
1008
|
+
const result = await sock.executeUSyncQuery(q);
|
|
1009
|
+
return result?.list || [];
|
|
1010
|
+
};
|
|
1011
|
+
const updateChatLock = (jid, locked) => {
|
|
1012
|
+
return chatModify({ chatLock: { locked } }, jid);
|
|
1013
|
+
};
|
|
1014
|
+
const updateChatWallpaper = (jid, wallpaper) => {
|
|
1015
|
+
if (!wallpaper) {
|
|
1016
|
+
return chatModify({ wallpaper: { remove: true } }, jid);
|
|
1017
|
+
}
|
|
1018
|
+
return chatModify({ wallpaper }, jid);
|
|
1019
|
+
};
|
|
1020
|
+
const updateChatMediaVisibility = (jid, visibility) => {
|
|
1021
|
+
return chatModify({ mediaVisibility: visibility }, jid);
|
|
1022
|
+
};
|
|
1023
|
+
const getBotProfile = async (botJid) => {
|
|
1024
|
+
const resp = await query({
|
|
1025
|
+
tag: 'iq',
|
|
1026
|
+
attrs: {
|
|
1027
|
+
xmlns: 'bot',
|
|
1028
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
1029
|
+
type: 'get'
|
|
1030
|
+
},
|
|
1031
|
+
content: [
|
|
1032
|
+
{
|
|
1033
|
+
tag: 'bot',
|
|
1034
|
+
attrs: { v: '2', jid: botJid }
|
|
1035
|
+
}
|
|
1036
|
+
]
|
|
1037
|
+
});
|
|
1038
|
+
const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
|
|
1039
|
+
if (!botNode)
|
|
1040
|
+
return null;
|
|
1041
|
+
return {
|
|
1042
|
+
jid: botNode.attrs.jid,
|
|
1043
|
+
personaId: botNode.attrs['persona_id'],
|
|
1044
|
+
name: botNode.attrs.name,
|
|
1045
|
+
description: botNode.attrs.description
|
|
1046
|
+
};
|
|
1047
|
+
};
|
|
1048
|
+
const fetchABProps = async (protocol = '2', hash = '', refreshId = null, group = null) => {
|
|
1049
|
+
const propAttrs = { protocol };
|
|
1050
|
+
if (hash)
|
|
1051
|
+
propAttrs.hash = hash;
|
|
1052
|
+
if (refreshId != null)
|
|
1053
|
+
propAttrs.refresh_id = String(refreshId);
|
|
1054
|
+
if (group != null)
|
|
1055
|
+
propAttrs.group = String(group);
|
|
1056
|
+
const result = await query({
|
|
1057
|
+
tag: 'iq',
|
|
1058
|
+
attrs: { to: WABinary_1.S_WHATSAPP_NET, xmlns: 'abt', type: 'get' },
|
|
1059
|
+
content: [{ tag: 'props', attrs: propAttrs }]
|
|
1060
|
+
});
|
|
1061
|
+
const propsNode = (0, WABinary_1.getBinaryNodeChild)(result, 'props');
|
|
1062
|
+
if (!propsNode)
|
|
1063
|
+
return {};
|
|
1064
|
+
return (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
|
|
1065
|
+
};
|
|
1066
|
+
const removeCompanionDevice = async (keyIndex, reason = 'user_initiated') => {
|
|
1067
|
+
await query({
|
|
1068
|
+
tag: 'iq',
|
|
1069
|
+
attrs: { to: WABinary_1.S_WHATSAPP_NET, xmlns: 'md', type: 'set' },
|
|
1070
|
+
content: [
|
|
1071
|
+
{
|
|
1072
|
+
tag: 'remove-companion-device',
|
|
1073
|
+
attrs: { platform: 'true', reason, id: String(keyIndex) }
|
|
1074
|
+
}
|
|
1075
|
+
]
|
|
1076
|
+
});
|
|
1077
|
+
};
|
|
1078
|
+
const updateKeyIndexList = async (ts, content) => {
|
|
1079
|
+
await query({
|
|
1080
|
+
tag: 'iq',
|
|
1081
|
+
attrs: { to: WABinary_1.S_WHATSAPP_NET, xmlns: 'md', type: 'set' },
|
|
1082
|
+
content: [
|
|
1083
|
+
{
|
|
1084
|
+
tag: 'key-index-list',
|
|
1085
|
+
attrs: { ts: String(ts) },
|
|
1086
|
+
content
|
|
1087
|
+
}
|
|
1088
|
+
]
|
|
1089
|
+
});
|
|
1090
|
+
};
|
|
1091
|
+
const fetchMediaConn = async (lastId = null) => {
|
|
1092
|
+
const attrs = {};
|
|
1093
|
+
if (lastId != null)
|
|
1094
|
+
attrs.last_id = String(lastId);
|
|
1095
|
+
const result = await query({
|
|
1096
|
+
tag: 'iq',
|
|
1097
|
+
attrs: { to: WABinary_1.S_WHATSAPP_NET, xmlns: 'w:m', type: 'set' },
|
|
1098
|
+
content: [{ tag: 'media_conn', attrs }]
|
|
1099
|
+
});
|
|
1100
|
+
return (0, WABinary_1.getBinaryNodeChild)(result, 'media_conn') || null;
|
|
1101
|
+
};
|
|
1102
|
+
const deleteBroadcastList = async (listId) => {
|
|
1103
|
+
await query({
|
|
1104
|
+
tag: 'iq',
|
|
1105
|
+
attrs: { to: WABinary_1.S_WHATSAPP_NET, xmlns: 'w:b', type: 'set' },
|
|
1106
|
+
content: [
|
|
1107
|
+
{
|
|
1108
|
+
tag: 'delete',
|
|
1109
|
+
attrs: {},
|
|
1110
|
+
content: [{ tag: 'list', attrs: { id: String(listId) } }]
|
|
1111
|
+
}
|
|
1112
|
+
]
|
|
1113
|
+
});
|
|
1114
|
+
};
|
|
1115
|
+
const fetchQRCode = async (code, addressingMode = null) => {
|
|
1116
|
+
const attrs = { code };
|
|
1117
|
+
if (addressingMode)
|
|
1118
|
+
attrs.addressing_mode = addressingMode;
|
|
1119
|
+
const result = await query({
|
|
1120
|
+
tag: 'iq',
|
|
1121
|
+
attrs: { to: WABinary_1.S_WHATSAPP_NET, xmlns: 'w:qr', type: 'get' },
|
|
1122
|
+
content: [{ tag: 'qr', attrs }]
|
|
1123
|
+
});
|
|
1124
|
+
return (0, WABinary_1.getBinaryNodeChild)(result, 'qr') || null;
|
|
1125
|
+
};
|
|
1126
|
+
const confirmDeviceLogout = async (id, approve = true) => {
|
|
1127
|
+
await query({
|
|
1128
|
+
tag: 'iq',
|
|
1129
|
+
attrs: {
|
|
1130
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
1131
|
+
xmlns: 'w:account_defence',
|
|
1132
|
+
type: 'set',
|
|
1133
|
+
smax_id: '87'
|
|
1134
|
+
},
|
|
1135
|
+
content: [
|
|
1136
|
+
{
|
|
1137
|
+
tag: 'device_logout',
|
|
1138
|
+
attrs: { approve: approve ? 'true' : 'false', id: String(id) }
|
|
1139
|
+
}
|
|
1140
|
+
]
|
|
1141
|
+
});
|
|
1142
|
+
};
|
|
1143
|
+
const executeInitQueries = async () => {
|
|
1144
|
+
await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings(), initInterop()]);
|
|
1145
|
+
};
|
|
1146
|
+
const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
|
|
1147
|
+
ev.emit('messages.upsert', { messages: [msg], type });
|
|
1148
|
+
if (!!msg.pushName) {
|
|
1149
|
+
let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
|
|
1150
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
1151
|
+
if (!msg.key.fromMe) {
|
|
1152
|
+
ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
|
|
1153
|
+
}
|
|
1154
|
+
if (msg.key.fromMe && msg.pushName && authState.creds.me?.name !== msg.pushName) {
|
|
1155
|
+
ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
|
|
1159
|
+
const shouldProcessHistoryMsg = historyMsg
|
|
1160
|
+
? shouldSyncHistoryMessage(historyMsg) && Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)
|
|
1161
|
+
: false;
|
|
1162
|
+
if (historyMsg && shouldProcessHistoryMsg) {
|
|
1163
|
+
const syncType = historyMsg.syncType;
|
|
1164
|
+
if (syncType === index_js_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP &&
|
|
1165
|
+
!historySyncStatus.initialBootstrapComplete) {
|
|
1166
|
+
historySyncStatus.initialBootstrapComplete = true;
|
|
1167
|
+
ev.emit('messaging-history.status', {
|
|
1168
|
+
syncType,
|
|
1169
|
+
status: 'complete',
|
|
1170
|
+
explicit: true
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
if (syncType === index_js_1.proto.HistorySync.HistorySyncType.RECENT &&
|
|
1174
|
+
historyMsg.progress === 100 &&
|
|
1175
|
+
!historySyncStatus.recentSyncComplete) {
|
|
1176
|
+
historySyncStatus.recentSyncComplete = true;
|
|
1177
|
+
clearTimeout(historySyncPausedTimeout);
|
|
1178
|
+
historySyncPausedTimeout = undefined;
|
|
1179
|
+
ev.emit('messaging-history.status', {
|
|
1180
|
+
syncType,
|
|
1181
|
+
status: 'complete',
|
|
1182
|
+
explicit: true
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
if (syncType === index_js_1.proto.HistorySync.HistorySyncType.RECENT && !historySyncStatus.recentSyncComplete) {
|
|
1186
|
+
clearTimeout(historySyncPausedTimeout);
|
|
1187
|
+
historySyncPausedTimeout = setTimeout(() => {
|
|
1188
|
+
if (!historySyncStatus.recentSyncComplete) {
|
|
1189
|
+
historySyncStatus.recentSyncComplete = true;
|
|
1190
|
+
ev.emit('messaging-history.status', {
|
|
1191
|
+
syncType: index_js_1.proto.HistorySync.HistorySyncType.RECENT,
|
|
1192
|
+
status: 'paused',
|
|
1193
|
+
explicit: false
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
historySyncPausedTimeout = undefined;
|
|
1197
|
+
}, Defaults_1.HISTORY_SYNC_PAUSED_TIMEOUT_MS);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
if (historyMsg && syncState === State_1.SyncState.AwaitingInitialSync) {
|
|
1201
|
+
if (awaitingSyncTimeout) {
|
|
1202
|
+
clearTimeout(awaitingSyncTimeout);
|
|
1203
|
+
awaitingSyncTimeout = undefined;
|
|
1204
|
+
}
|
|
1205
|
+
if (shouldProcessHistoryMsg) {
|
|
1206
|
+
syncState = State_1.SyncState.Syncing;
|
|
1207
|
+
logger.info('Transitioned to Syncing state');
|
|
1208
|
+
}
|
|
1209
|
+
else {
|
|
1210
|
+
syncState = State_1.SyncState.Online;
|
|
1211
|
+
logger.info('History sync skipped, transitioning to Online state and flushing buffer');
|
|
1212
|
+
ev.flush();
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
const doAppStateSync = async () => {
|
|
1216
|
+
if (syncState === State_1.SyncState.Syncing) {
|
|
1217
|
+
blockedCollections.clear();
|
|
1218
|
+
logger.info('Doing app state sync');
|
|
1219
|
+
await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
|
|
1220
|
+
syncState = State_1.SyncState.Online;
|
|
1221
|
+
logger.info('App state sync complete, transitioning to Online state and flushing buffer');
|
|
1222
|
+
ev.flush();
|
|
1223
|
+
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
1224
|
+
ev.emit('creds.update', { accountSyncCounter });
|
|
1225
|
+
}
|
|
1226
|
+
};
|
|
1227
|
+
await Promise.all([
|
|
1228
|
+
(async () => {
|
|
1229
|
+
if (shouldProcessHistoryMsg) {
|
|
1230
|
+
await doAppStateSync();
|
|
1231
|
+
}
|
|
1232
|
+
})(),
|
|
1233
|
+
(0, process_message_1.default)(msg, {
|
|
1234
|
+
signalRepository,
|
|
1235
|
+
shouldProcessHistoryMsg,
|
|
1236
|
+
placeholderResendCache,
|
|
1237
|
+
ev,
|
|
1238
|
+
creds: authState.creds,
|
|
1239
|
+
keyStore: authState.keys,
|
|
1240
|
+
logger,
|
|
1241
|
+
options: config.options,
|
|
1242
|
+
getMessage
|
|
1243
|
+
})
|
|
1244
|
+
]);
|
|
1245
|
+
if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === State_1.SyncState.Syncing) {
|
|
1246
|
+
logger.info('App state sync key arrived, triggering app state sync');
|
|
1247
|
+
await doAppStateSync();
|
|
1248
|
+
}
|
|
1249
|
+
});
|
|
1250
|
+
ws.on('CB:presence', handlePresenceUpdate);
|
|
1251
|
+
ws.on('CB:chatstate', handlePresenceUpdate);
|
|
1252
|
+
ws.on('CB:ib,,dirty', async (node) => {
|
|
1253
|
+
const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
|
|
1254
|
+
const type = attrs.type;
|
|
1255
|
+
switch (type) {
|
|
1256
|
+
case 'account_sync':
|
|
1257
|
+
if (attrs.timestamp) {
|
|
1258
|
+
let { lastAccountSyncTimestamp } = authState.creds;
|
|
1259
|
+
if (lastAccountSyncTimestamp) {
|
|
1260
|
+
await cleanDirtyBits('account_sync', lastAccountSyncTimestamp);
|
|
1261
|
+
}
|
|
1262
|
+
lastAccountSyncTimestamp = +attrs.timestamp;
|
|
1263
|
+
ev.emit('creds.update', { lastAccountSyncTimestamp });
|
|
1264
|
+
}
|
|
1265
|
+
break;
|
|
1266
|
+
case 'groups':
|
|
1267
|
+
break;
|
|
1268
|
+
default:
|
|
1269
|
+
logger.info({ node }, 'received unknown sync');
|
|
1270
|
+
break;
|
|
1271
|
+
}
|
|
1272
|
+
});
|
|
1273
|
+
ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
|
|
1274
|
+
if (connection === 'close') {
|
|
1275
|
+
blockedCollections.clear();
|
|
1276
|
+
clearTimeout(historySyncPausedTimeout);
|
|
1277
|
+
historySyncPausedTimeout = undefined;
|
|
1278
|
+
}
|
|
1279
|
+
if (connection === 'open') {
|
|
1280
|
+
if (fireInitQueries) {
|
|
1281
|
+
executeInitQueries().catch(error => onUnexpectedError(error, 'init queries'));
|
|
1282
|
+
}
|
|
1283
|
+
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable').catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
1284
|
+
}
|
|
1285
|
+
if (!receivedPendingNotifications || syncState !== State_1.SyncState.Connecting) {
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
historySyncStatus.initialBootstrapComplete = false;
|
|
1289
|
+
historySyncStatus.recentSyncComplete = false;
|
|
1290
|
+
clearTimeout(historySyncPausedTimeout);
|
|
1291
|
+
historySyncPausedTimeout = undefined;
|
|
1292
|
+
syncState = State_1.SyncState.AwaitingInitialSync;
|
|
1293
|
+
logger.info('Connection is now AwaitingInitialSync, buffering events');
|
|
1294
|
+
ev.buffer();
|
|
1295
|
+
const willSyncHistory = shouldSyncHistoryMessage(index_js_1.proto.Message.HistorySyncNotification.create({
|
|
1296
|
+
syncType: index_js_1.proto.HistorySync.HistorySyncType.RECENT
|
|
1297
|
+
}));
|
|
1298
|
+
if (!willSyncHistory) {
|
|
1299
|
+
logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.');
|
|
1300
|
+
syncState = State_1.SyncState.Online;
|
|
1301
|
+
setTimeout(() => ev.flush(), 0);
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
if (authState.creds.accountSyncCounter > 0) {
|
|
1305
|
+
logger.info('Reconnection with existing sync data, skipping history sync wait. Transitioning to Online.');
|
|
1306
|
+
syncState = State_1.SyncState.Online;
|
|
1307
|
+
setTimeout(() => ev.flush(), 0);
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
logger.info('First connection, awaiting history sync notification with a 20s timeout.');
|
|
1311
|
+
if (awaitingSyncTimeout) {
|
|
1312
|
+
clearTimeout(awaitingSyncTimeout);
|
|
1313
|
+
}
|
|
1314
|
+
awaitingSyncTimeout = setTimeout(() => {
|
|
1315
|
+
if (syncState === State_1.SyncState.AwaitingInitialSync) {
|
|
1316
|
+
logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
|
|
1317
|
+
syncState = State_1.SyncState.Online;
|
|
1318
|
+
ev.flush();
|
|
1319
|
+
const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
|
|
1320
|
+
ev.emit('creds.update', { accountSyncCounter });
|
|
1321
|
+
}
|
|
1322
|
+
}, 20000);
|
|
1323
|
+
});
|
|
1324
|
+
ev.on('creds.update', ({ myAppStateKeyId }) => {
|
|
1325
|
+
if (!myAppStateKeyId || blockedCollections.size === 0) {
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1328
|
+
if (syncState === State_1.SyncState.Syncing) {
|
|
1329
|
+
blockedCollections.clear();
|
|
1330
|
+
return;
|
|
1331
|
+
}
|
|
1332
|
+
const collections = [...blockedCollections];
|
|
1333
|
+
blockedCollections.clear();
|
|
1334
|
+
logger.info({ collections }, 'app state sync key arrived, re-syncing blocked collections');
|
|
1335
|
+
resyncAppState(collections, false).catch(error => onUnexpectedError(error, 'blocked collections resync'));
|
|
1336
|
+
});
|
|
1337
|
+
ev.on('lid-mapping.update', async ({ lid, pn }) => {
|
|
1338
|
+
try {
|
|
1339
|
+
await signalRepository.lidMapping.storeLIDPNMappings([{ lid, pn }]);
|
|
1340
|
+
}
|
|
1341
|
+
catch (error) {
|
|
1342
|
+
logger.warn({ lid, pn, error }, 'Failed to store LID-PN mapping');
|
|
1343
|
+
}
|
|
1344
|
+
});
|
|
1345
|
+
return {
|
|
1346
|
+
...sock,
|
|
1347
|
+
serverProps,
|
|
1348
|
+
createCallLink,
|
|
1349
|
+
toggleCallLinkWaitingRoom,
|
|
1350
|
+
getBotListV2,
|
|
1351
|
+
getChatBlockingStatus,
|
|
1352
|
+
updateChatBlockingStatus,
|
|
1353
|
+
getUserDisclosures,
|
|
1354
|
+
getOptOutList,
|
|
1355
|
+
getPushConfig,
|
|
1356
|
+
setPushConfig,
|
|
1357
|
+
messageMutex,
|
|
1358
|
+
receiptMutex,
|
|
1359
|
+
appStatePatchMutex,
|
|
1360
|
+
notificationMutex,
|
|
1361
|
+
fetchPrivacySettings,
|
|
1362
|
+
upsertMessage,
|
|
1363
|
+
appPatch,
|
|
1364
|
+
sendPresenceUpdate,
|
|
1365
|
+
presenceSubscribe,
|
|
1366
|
+
profilePictureUrl,
|
|
1367
|
+
fetchBlocklist,
|
|
1368
|
+
fetchStatus,
|
|
1369
|
+
fetchDisappearingDuration,
|
|
1370
|
+
updateProfilePicture,
|
|
1371
|
+
removeProfilePicture,
|
|
1372
|
+
updateProfileStatus,
|
|
1373
|
+
updateProfileName,
|
|
1374
|
+
updateBlockStatus,
|
|
1375
|
+
updateDisableLinkPreviewsPrivacy,
|
|
1376
|
+
updateCallPrivacy,
|
|
1377
|
+
updateMessagesPrivacy,
|
|
1378
|
+
updateLastSeenPrivacy,
|
|
1379
|
+
updateOnlinePrivacy,
|
|
1380
|
+
updateProfilePicturePrivacy,
|
|
1381
|
+
updateStatusPrivacy,
|
|
1382
|
+
getStatusPrivacy,
|
|
1383
|
+
setStatusPrivacy,
|
|
1384
|
+
updateReadReceiptsPrivacy,
|
|
1385
|
+
updateGroupsAddPrivacy,
|
|
1386
|
+
updateDefaultDisappearingMode,
|
|
1387
|
+
fetchBroadcastListQuota,
|
|
1388
|
+
getBusinessProfile,
|
|
1389
|
+
resyncAppState,
|
|
1390
|
+
chatModify,
|
|
1391
|
+
cleanDirtyBits,
|
|
1392
|
+
addOrEditContact,
|
|
1393
|
+
removeContact,
|
|
1394
|
+
addLabel,
|
|
1395
|
+
addChatLabel,
|
|
1396
|
+
removeChatLabel,
|
|
1397
|
+
addMessageLabel,
|
|
1398
|
+
removeMessageLabel,
|
|
1399
|
+
star,
|
|
1400
|
+
addOrEditQuickReply,
|
|
1401
|
+
removeQuickReply,
|
|
1402
|
+
renameAIThread,
|
|
1403
|
+
pinThreadMessage,
|
|
1404
|
+
updatePrivateProcessingSetting,
|
|
1405
|
+
updateBioPrivacy,
|
|
1406
|
+
blockBot,
|
|
1407
|
+
unblockBot,
|
|
1408
|
+
getBotProfile,
|
|
1409
|
+
muteContactStatus,
|
|
1410
|
+
toggleFavorite,
|
|
1411
|
+
reorderLabels,
|
|
1412
|
+
deleteCallLog,
|
|
1413
|
+
setChatNote,
|
|
1414
|
+
deleteChatNote,
|
|
1415
|
+
markChatAsUnread,
|
|
1416
|
+
setChatEphemeral,
|
|
1417
|
+
silenceChat,
|
|
1418
|
+
fetchBotProfiles,
|
|
1419
|
+
updateChatLock,
|
|
1420
|
+
updateChatWallpaper,
|
|
1421
|
+
updateChatMediaVisibility,
|
|
1422
|
+
fetchIntegrators,
|
|
1423
|
+
acceptInteropTOS,
|
|
1424
|
+
optInIntegrators,
|
|
1425
|
+
optOutIntegrators,
|
|
1426
|
+
resolveInteropUser,
|
|
1427
|
+
resolveInteropUsers,
|
|
1428
|
+
getReachabilitySettings,
|
|
1429
|
+
setReachabilitySettings,
|
|
1430
|
+
blockInteropUser,
|
|
1431
|
+
unblockInteropUser,
|
|
1432
|
+
reportInteropSpam,
|
|
1433
|
+
trustInteropContact,
|
|
1434
|
+
initInterop,
|
|
1435
|
+
createInteropGroup,
|
|
1436
|
+
leaveInteropGroup,
|
|
1437
|
+
getInteropGroupAddPrivacy,
|
|
1438
|
+
INTEGRATOR_BIRDYCHAT,
|
|
1439
|
+
INTEGRATOR_HAIKET,
|
|
1440
|
+
fetchABProps,
|
|
1441
|
+
removeCompanionDevice,
|
|
1442
|
+
updateKeyIndexList,
|
|
1443
|
+
fetchMediaConn,
|
|
1444
|
+
deleteBroadcastList,
|
|
1445
|
+
fetchQRCode,
|
|
1446
|
+
confirmDeviceLogout
|
|
1447
|
+
};
|
|
1448
|
+
};
|
|
1449
|
+
exports.makeChatsSocket = makeChatsSocket;
|