@d0v3riz/baileys 6.7.19 → 6.7.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1263 -4
- package/WAProto/GenerateStatics.sh +2 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/index.d.ts +3212 -122
- package/WAProto/index.js +9635 -299
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +1 -1
- package/lib/Defaults/index.js +16 -16
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +29 -39
- package/lib/Signal/libsignal.js +33 -20
- package/lib/Socket/Client/websocket.js +1 -1
- package/lib/Socket/business.d.ts +5 -5
- package/lib/Socket/business.js +5 -5
- package/lib/Socket/chats.d.ts +4 -4
- package/lib/Socket/chats.js +70 -70
- package/lib/Socket/groups.d.ts +6 -6
- package/lib/Socket/groups.js +39 -24
- package/lib/Socket/index.d.ts +5 -5
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +5 -5
- package/lib/Socket/messages-recv.js +73 -56
- package/lib/Socket/messages-send.d.ts +5 -5
- package/lib/Socket/messages-send.js +53 -46
- package/lib/Socket/socket.d.ts +3 -3
- package/lib/Socket/socket.js +22 -29
- package/lib/Socket/usync.d.ts +3 -3
- package/lib/Socket/usync.js +10 -15
- package/lib/Types/Auth.d.ts +1 -1
- package/lib/Types/Chat.d.ts +1 -1
- package/lib/Types/Chat.js +7 -1
- package/lib/Types/Contact.d.ts +4 -0
- package/lib/Types/Events.d.ts +1 -1
- package/lib/Types/GroupMetadata.d.ts +7 -3
- package/lib/Types/Message.d.ts +6 -1
- package/lib/Types/Socket.d.ts +3 -3
- package/lib/Utils/auth-utils.js +8 -9
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/business.js +9 -11
- package/lib/Utils/chat-utils.d.ts +4 -4
- package/lib/Utils/chat-utils.js +64 -69
- package/lib/Utils/crypto.js +4 -10
- package/lib/Utils/decode-wa-message.js +6 -2
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +9 -13
- package/lib/Utils/generics.d.ts +1 -1
- package/lib/Utils/generics.js +28 -30
- package/lib/Utils/history.js +10 -5
- package/lib/Utils/link-preview.js +5 -9
- package/lib/Utils/lt-hash.js +2 -2
- package/lib/Utils/make-mutex.js +1 -1
- package/lib/Utils/messages-media.js +40 -55
- package/lib/Utils/messages.d.ts +1 -1
- package/lib/Utils/messages.js +71 -61
- package/lib/Utils/process-message.d.ts +1 -1
- package/lib/Utils/process-message.js +25 -30
- package/lib/Utils/signal.js +9 -7
- package/lib/Utils/use-multi-file-auth-state.js +2 -3
- package/lib/Utils/validate-connection.js +17 -22
- package/lib/WABinary/constants.d.ts +4 -4
- package/lib/WABinary/constants.js +1271 -8
- package/lib/WABinary/decode.js +2 -1
- package/lib/WABinary/encode.js +2 -2
- package/lib/WABinary/generic-utils.js +1 -1
- package/lib/WABinary/jid-utils.js +8 -11
- package/lib/WAM/constants.js +2252 -2359
- package/lib/WAM/encode.js +5 -7
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -5
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -1
- package/lib/WAUSync/USyncQuery.js +17 -13
- package/package.json +11 -6
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
package/lib/Socket/business.js
CHANGED
|
@@ -27,7 +27,7 @@ const makeBusinessSocket = (config) => {
|
|
|
27
27
|
tag: 'height',
|
|
28
28
|
attrs: {},
|
|
29
29
|
content: Buffer.from('100')
|
|
30
|
-
}
|
|
30
|
+
}
|
|
31
31
|
];
|
|
32
32
|
if (cursor) {
|
|
33
33
|
queryParamNodes.push({
|
|
@@ -48,7 +48,7 @@ const makeBusinessSocket = (config) => {
|
|
|
48
48
|
tag: 'product_catalog',
|
|
49
49
|
attrs: {
|
|
50
50
|
jid,
|
|
51
|
-
|
|
51
|
+
allow_shop_source: 'true'
|
|
52
52
|
},
|
|
53
53
|
content: queryParamNodes
|
|
54
54
|
}
|
|
@@ -66,13 +66,13 @@ const makeBusinessSocket = (config) => {
|
|
|
66
66
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
67
67
|
type: 'get',
|
|
68
68
|
xmlns: 'w:biz:catalog',
|
|
69
|
-
|
|
69
|
+
smax_id: '35'
|
|
70
70
|
},
|
|
71
71
|
content: [
|
|
72
72
|
{
|
|
73
73
|
tag: 'collections',
|
|
74
74
|
attrs: {
|
|
75
|
-
|
|
75
|
+
biz_jid: jid
|
|
76
76
|
},
|
|
77
77
|
content: [
|
|
78
78
|
{
|
|
@@ -108,7 +108,7 @@ const makeBusinessSocket = (config) => {
|
|
|
108
108
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
109
109
|
type: 'get',
|
|
110
110
|
xmlns: 'fb:thrift_iq',
|
|
111
|
-
|
|
111
|
+
smax_id: '5'
|
|
112
112
|
},
|
|
113
113
|
content: [
|
|
114
114
|
{
|
package/lib/Socket/chats.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
|
40
40
|
updateGroupsAddPrivacy: (value: WAPrivacyGroupAddValue) => Promise<void>;
|
|
41
41
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
42
42
|
getBusinessProfile: (jid: string) => Promise<WABusinessProfile | void>;
|
|
43
|
-
resyncAppState: (collections: readonly ("
|
|
43
|
+
resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
44
44
|
chatModify: (mod: ChatModification, jid: string) => Promise<void>;
|
|
45
45
|
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
|
46
46
|
addLabel: (jid: string, labels: LabelActionBody) => Promise<void>;
|
|
@@ -56,9 +56,9 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
|
56
56
|
type: "md";
|
|
57
57
|
ws: import("./Client").WebSocketClient;
|
|
58
58
|
ev: import("../Types").BaileysEventEmitter & {
|
|
59
|
-
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (
|
|
59
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
60
60
|
buffer(): void;
|
|
61
|
-
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (
|
|
61
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
|
|
62
62
|
flush(force?: boolean): boolean;
|
|
63
63
|
isBuffering(): boolean;
|
|
64
64
|
};
|
|
@@ -79,7 +79,7 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
|
79
79
|
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
|
80
80
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
81
81
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
82
|
-
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
82
|
+
requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
|
|
83
83
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
84
84
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
85
85
|
};
|
package/lib/Socket/chats.js
CHANGED
|
@@ -17,18 +17,19 @@ const WAUSync_1 = require("../WAUSync");
|
|
|
17
17
|
const usync_1 = require("./usync");
|
|
18
18
|
const MAX_SYNC_ATTEMPTS = 2;
|
|
19
19
|
const makeChatsSocket = (config) => {
|
|
20
|
-
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage
|
|
20
|
+
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage } = config;
|
|
21
21
|
const sock = (0, usync_1.makeUSyncSocket)(config);
|
|
22
|
-
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError
|
|
22
|
+
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError } = sock;
|
|
23
23
|
let privacySettings;
|
|
24
24
|
let needToFlushWithAppStateSync = false;
|
|
25
25
|
let pendingAppStateSync = false;
|
|
26
26
|
/** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
|
|
27
27
|
const processingMutex = (0, make_mutex_1.makeMutex)();
|
|
28
|
-
const placeholderResendCache = config.placeholderResendCache ||
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
const placeholderResendCache = config.placeholderResendCache ||
|
|
29
|
+
new node_cache_1.default({
|
|
30
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
31
|
+
useClones: false
|
|
32
|
+
});
|
|
32
33
|
if (!config.placeholderResendCache) {
|
|
33
34
|
config.placeholderResendCache = placeholderResendCache;
|
|
34
35
|
}
|
|
@@ -46,9 +47,7 @@ const makeChatsSocket = (config) => {
|
|
|
46
47
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
47
48
|
type: 'get'
|
|
48
49
|
},
|
|
49
|
-
content: [
|
|
50
|
-
{ tag: 'privacy', attrs: {} }
|
|
51
|
-
]
|
|
50
|
+
content: [{ tag: 'privacy', attrs: {} }]
|
|
52
51
|
});
|
|
53
52
|
privacySettings = (0, WABinary_1.reduceBinaryNodeToDictionary)(content === null || content === void 0 ? void 0 : content[0], 'category');
|
|
54
53
|
}
|
|
@@ -63,7 +62,8 @@ const makeChatsSocket = (config) => {
|
|
|
63
62
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
64
63
|
type: 'set'
|
|
65
64
|
},
|
|
66
|
-
content: [
|
|
65
|
+
content: [
|
|
66
|
+
{
|
|
67
67
|
tag: 'privacy',
|
|
68
68
|
attrs: {},
|
|
69
69
|
content: [
|
|
@@ -72,7 +72,8 @@ const makeChatsSocket = (config) => {
|
|
|
72
72
|
attrs: { name, value }
|
|
73
73
|
}
|
|
74
74
|
]
|
|
75
|
-
}
|
|
75
|
+
}
|
|
76
|
+
]
|
|
76
77
|
});
|
|
77
78
|
};
|
|
78
79
|
const updateMessagesPrivacy = async (value) => {
|
|
@@ -107,12 +108,14 @@ const makeChatsSocket = (config) => {
|
|
|
107
108
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
108
109
|
type: 'set'
|
|
109
110
|
},
|
|
110
|
-
content: [
|
|
111
|
+
content: [
|
|
112
|
+
{
|
|
111
113
|
tag: 'disappearing_mode',
|
|
112
114
|
attrs: {
|
|
113
115
|
duration: duration.toString()
|
|
114
116
|
}
|
|
115
|
-
}
|
|
117
|
+
}
|
|
118
|
+
]
|
|
116
119
|
});
|
|
117
120
|
};
|
|
118
121
|
const getBotListV2 = async () => {
|
|
@@ -123,12 +126,14 @@ const makeChatsSocket = (config) => {
|
|
|
123
126
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
124
127
|
type: 'get'
|
|
125
128
|
},
|
|
126
|
-
content: [
|
|
129
|
+
content: [
|
|
130
|
+
{
|
|
127
131
|
tag: 'bot',
|
|
128
132
|
attrs: {
|
|
129
133
|
v: '2'
|
|
130
134
|
}
|
|
131
|
-
}
|
|
135
|
+
}
|
|
136
|
+
]
|
|
132
137
|
});
|
|
133
138
|
const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
|
|
134
139
|
const botList = [];
|
|
@@ -145,21 +150,18 @@ const makeChatsSocket = (config) => {
|
|
|
145
150
|
return botList;
|
|
146
151
|
};
|
|
147
152
|
const onWhatsApp = async (...jids) => {
|
|
148
|
-
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
149
|
-
.withContactProtocol()
|
|
150
|
-
.withLIDProtocol();
|
|
153
|
+
const usyncQuery = new WAUSync_1.USyncQuery().withContactProtocol().withLIDProtocol();
|
|
151
154
|
for (const jid of jids) {
|
|
152
155
|
const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
|
|
153
156
|
usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
|
|
154
157
|
}
|
|
155
158
|
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
156
159
|
if (results) {
|
|
157
|
-
return results.list.filter(
|
|
160
|
+
return results.list.filter(a => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
|
|
158
161
|
}
|
|
159
162
|
};
|
|
160
163
|
const fetchStatus = async (...jids) => {
|
|
161
|
-
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
162
|
-
.withStatusProtocol();
|
|
164
|
+
const usyncQuery = new WAUSync_1.USyncQuery().withStatusProtocol();
|
|
163
165
|
for (const jid of jids) {
|
|
164
166
|
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
165
167
|
}
|
|
@@ -169,8 +171,7 @@ const makeChatsSocket = (config) => {
|
|
|
169
171
|
}
|
|
170
172
|
};
|
|
171
173
|
const fetchDisappearingDuration = async (...jids) => {
|
|
172
|
-
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
173
|
-
.withDisappearingModeProtocol();
|
|
174
|
+
const usyncQuery = new WAUSync_1.USyncQuery().withDisappearingModeProtocol();
|
|
174
175
|
for (const jid of jids) {
|
|
175
176
|
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
176
177
|
}
|
|
@@ -256,8 +257,7 @@ const makeChatsSocket = (config) => {
|
|
|
256
257
|
}
|
|
257
258
|
});
|
|
258
259
|
const listNode = (0, WABinary_1.getBinaryNodeChild)(result, 'list');
|
|
259
|
-
return (0, WABinary_1.getBinaryNodeChildren)(listNode, 'item')
|
|
260
|
-
.map(n => n.attrs.jid);
|
|
260
|
+
return (0, WABinary_1.getBinaryNodeChildren)(listNode, 'item').map(n => n.attrs.jid);
|
|
261
261
|
};
|
|
262
262
|
const updateBlockStatus = async (jid, action) => {
|
|
263
263
|
await query({
|
|
@@ -287,14 +287,18 @@ const makeChatsSocket = (config) => {
|
|
|
287
287
|
xmlns: 'w:biz',
|
|
288
288
|
type: 'get'
|
|
289
289
|
},
|
|
290
|
-
content: [
|
|
290
|
+
content: [
|
|
291
|
+
{
|
|
291
292
|
tag: 'business_profile',
|
|
292
293
|
attrs: { v: '244' },
|
|
293
|
-
content: [
|
|
294
|
+
content: [
|
|
295
|
+
{
|
|
294
296
|
tag: 'profile',
|
|
295
297
|
attrs: { jid }
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
+
}
|
|
299
|
+
]
|
|
300
|
+
}
|
|
301
|
+
]
|
|
298
302
|
});
|
|
299
303
|
const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
|
|
300
304
|
const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
|
|
@@ -316,9 +320,9 @@ const makeChatsSocket = (config) => {
|
|
|
316
320
|
website: websiteStr ? [websiteStr] : [],
|
|
317
321
|
email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
|
|
318
322
|
category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
|
|
319
|
-
|
|
323
|
+
business_hours: {
|
|
320
324
|
timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
|
|
321
|
-
|
|
325
|
+
business_config: businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
|
|
322
326
|
}
|
|
323
327
|
};
|
|
324
328
|
}
|
|
@@ -331,14 +335,14 @@ const makeChatsSocket = (config) => {
|
|
|
331
335
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
332
336
|
type: 'set',
|
|
333
337
|
xmlns: 'urn:xmpp:whatsapp:dirty',
|
|
334
|
-
id: generateMessageTag()
|
|
338
|
+
id: generateMessageTag()
|
|
335
339
|
},
|
|
336
340
|
content: [
|
|
337
341
|
{
|
|
338
342
|
tag: 'clean',
|
|
339
343
|
attrs: {
|
|
340
344
|
type,
|
|
341
|
-
...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null)
|
|
345
|
+
...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null)
|
|
342
346
|
}
|
|
343
347
|
}
|
|
344
348
|
]
|
|
@@ -386,7 +390,7 @@ const makeChatsSocket = (config) => {
|
|
|
386
390
|
name,
|
|
387
391
|
version: state.version.toString(),
|
|
388
392
|
// return snapshot if being synced from scratch
|
|
389
|
-
|
|
393
|
+
return_snapshot: (!state.version).toString()
|
|
390
394
|
}
|
|
391
395
|
});
|
|
392
396
|
}
|
|
@@ -429,16 +433,17 @@ const makeChatsSocket = (config) => {
|
|
|
429
433
|
if (hasMorePatches) {
|
|
430
434
|
logger.info(`${name} has more patches...`);
|
|
431
435
|
}
|
|
432
|
-
else {
|
|
436
|
+
else {
|
|
437
|
+
// collection is done with sync
|
|
433
438
|
collectionsToHandle.delete(name);
|
|
434
439
|
}
|
|
435
440
|
}
|
|
436
441
|
catch (error) {
|
|
437
442
|
// if retry attempts overshoot
|
|
438
443
|
// or key not found
|
|
439
|
-
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
|
|
440
|
-
|
|
441
|
-
|
|
444
|
+
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
|
|
445
|
+
((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404 ||
|
|
446
|
+
error.name === 'TypeError';
|
|
442
447
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
443
448
|
await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
|
|
444
449
|
// increment number of retries
|
|
@@ -472,9 +477,7 @@ const makeChatsSocket = (config) => {
|
|
|
472
477
|
type: 'get',
|
|
473
478
|
xmlns: 'w:profile:picture'
|
|
474
479
|
},
|
|
475
|
-
content: [
|
|
476
|
-
{ tag: 'picture', attrs: { type, query: 'url' } }
|
|
477
|
-
]
|
|
480
|
+
content: [{ tag: 'picture', attrs: { type, query: 'url' } }]
|
|
478
481
|
}, timeoutMs);
|
|
479
482
|
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
|
|
480
483
|
return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
|
|
@@ -490,17 +493,19 @@ const makeChatsSocket = (config) => {
|
|
|
490
493
|
await sendNode({
|
|
491
494
|
tag: 'presence',
|
|
492
495
|
attrs: {
|
|
493
|
-
name: me.name,
|
|
496
|
+
name: me.name.replace(/@/g, ''),
|
|
494
497
|
type
|
|
495
498
|
}
|
|
496
499
|
});
|
|
497
500
|
}
|
|
498
501
|
else {
|
|
502
|
+
const { server } = (0, WABinary_1.jidDecode)(toJid);
|
|
503
|
+
const isLid = server === 'lid';
|
|
499
504
|
await sendNode({
|
|
500
505
|
tag: 'chatstate',
|
|
501
506
|
attrs: {
|
|
502
|
-
from: me.id,
|
|
503
|
-
to: toJid
|
|
507
|
+
from: isLid ? me.lid : me.id,
|
|
508
|
+
to: toJid
|
|
504
509
|
},
|
|
505
510
|
content: [
|
|
506
511
|
{
|
|
@@ -515,7 +520,7 @@ const makeChatsSocket = (config) => {
|
|
|
515
520
|
* @param toJid the jid to subscribe to
|
|
516
521
|
* @param tcToken token for subscription, use if present
|
|
517
522
|
*/
|
|
518
|
-
const presenceSubscribe = (toJid, tcToken) =>
|
|
523
|
+
const presenceSubscribe = (toJid, tcToken) => sendNode({
|
|
519
524
|
tag: 'presence',
|
|
520
525
|
attrs: {
|
|
521
526
|
to: toJid,
|
|
@@ -531,7 +536,7 @@ const makeChatsSocket = (config) => {
|
|
|
531
536
|
}
|
|
532
537
|
]
|
|
533
538
|
: undefined
|
|
534
|
-
})
|
|
539
|
+
});
|
|
535
540
|
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
536
541
|
var _a;
|
|
537
542
|
let presence;
|
|
@@ -597,7 +602,7 @@ const makeChatsSocket = (config) => {
|
|
|
597
602
|
attrs: {
|
|
598
603
|
name,
|
|
599
604
|
version: (state.version - 1).toString(),
|
|
600
|
-
|
|
605
|
+
return_snapshot: 'false'
|
|
601
606
|
},
|
|
602
607
|
content: [
|
|
603
608
|
{
|
|
@@ -617,7 +622,7 @@ const makeChatsSocket = (config) => {
|
|
|
617
622
|
});
|
|
618
623
|
if (config.emitOwnEvents) {
|
|
619
624
|
const { onMutation } = newAppStateChunkHandler(false);
|
|
620
|
-
const { mutationMap } = await (0, Utils_1.decodePatches)(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version }
|
|
625
|
+
const { mutationMap } = await (0, Utils_1.decodePatches)(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
621
626
|
for (const key in mutationMap) {
|
|
622
627
|
onMutation(mutationMap[key]);
|
|
623
628
|
}
|
|
@@ -631,19 +636,23 @@ const makeChatsSocket = (config) => {
|
|
|
631
636
|
attrs: {
|
|
632
637
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
633
638
|
xmlns: 'w',
|
|
634
|
-
type: 'get'
|
|
639
|
+
type: 'get'
|
|
635
640
|
},
|
|
636
641
|
content: [
|
|
637
|
-
{
|
|
642
|
+
{
|
|
643
|
+
tag: 'props',
|
|
644
|
+
attrs: {
|
|
638
645
|
protocol: '2',
|
|
639
646
|
hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
|
|
640
|
-
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
641
649
|
]
|
|
642
650
|
});
|
|
643
651
|
const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
|
|
644
652
|
let props = {};
|
|
645
653
|
if (propsNode) {
|
|
646
|
-
if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) {
|
|
654
|
+
if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) {
|
|
655
|
+
// on some clients, the hash is returning as undefined
|
|
647
656
|
authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
|
|
648
657
|
ev.emit('creds.update', authState.creds);
|
|
649
658
|
}
|
|
@@ -656,7 +665,7 @@ const makeChatsSocket = (config) => {
|
|
|
656
665
|
* modify a chat -- mark unread, read etc.
|
|
657
666
|
* lastMessages must be sorted in reverse chronologically
|
|
658
667
|
* requires the last messages till the last message received; required for archive & unread
|
|
659
|
-
|
|
668
|
+
*/
|
|
660
669
|
const chatModify = (mod, jid) => {
|
|
661
670
|
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
662
671
|
return appPatch(patch);
|
|
@@ -729,17 +738,13 @@ const makeChatsSocket = (config) => {
|
|
|
729
738
|
* help ensure parity with WA Web
|
|
730
739
|
* */
|
|
731
740
|
const executeInitQueries = async () => {
|
|
732
|
-
await Promise.all([
|
|
733
|
-
fetchProps(),
|
|
734
|
-
fetchBlocklist(),
|
|
735
|
-
fetchPrivacySettings(),
|
|
736
|
-
]);
|
|
741
|
+
await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
|
|
737
742
|
};
|
|
738
743
|
const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
|
|
739
744
|
var _a, _b, _c;
|
|
740
745
|
ev.emit('messages.upsert', { messages: [msg], type });
|
|
741
746
|
if (!!msg.pushName) {
|
|
742
|
-
let jid = msg.key.fromMe ? authState.creds.me.id :
|
|
747
|
+
let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
|
|
743
748
|
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
744
749
|
if (!msg.key.fromMe) {
|
|
745
750
|
ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
|
|
@@ -751,8 +756,7 @@ const makeChatsSocket = (config) => {
|
|
|
751
756
|
}
|
|
752
757
|
const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
|
|
753
758
|
const shouldProcessHistoryMsg = historyMsg
|
|
754
|
-
?
|
|
755
|
-
&& Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
|
|
759
|
+
? shouldSyncHistoryMessage(historyMsg) && Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)
|
|
756
760
|
: false;
|
|
757
761
|
if (historyMsg && !authState.creds.myAppStateKeyId) {
|
|
758
762
|
logger.warn('skipping app state sync, as myAppStateKeyId is not set');
|
|
@@ -760,8 +764,7 @@ const makeChatsSocket = (config) => {
|
|
|
760
764
|
}
|
|
761
765
|
await Promise.all([
|
|
762
766
|
(async () => {
|
|
763
|
-
if (historyMsg
|
|
764
|
-
&& authState.creds.myAppStateKeyId) {
|
|
767
|
+
if (historyMsg && authState.creds.myAppStateKeyId) {
|
|
765
768
|
pendingAppStateSync = false;
|
|
766
769
|
await doAppStateSync();
|
|
767
770
|
}
|
|
@@ -773,11 +776,10 @@ const makeChatsSocket = (config) => {
|
|
|
773
776
|
creds: authState.creds,
|
|
774
777
|
keyStore: authState.keys,
|
|
775
778
|
logger,
|
|
776
|
-
options: config.options
|
|
779
|
+
options: config.options
|
|
777
780
|
})
|
|
778
781
|
]);
|
|
779
|
-
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
|
|
780
|
-
&& pendingAppStateSync) {
|
|
782
|
+
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare) && pendingAppStateSync) {
|
|
781
783
|
await doAppStateSync();
|
|
782
784
|
pendingAppStateSync = false;
|
|
783
785
|
}
|
|
@@ -822,11 +824,9 @@ const makeChatsSocket = (config) => {
|
|
|
822
824
|
var _a;
|
|
823
825
|
if (connection === 'open') {
|
|
824
826
|
if (fireInitQueries) {
|
|
825
|
-
executeInitQueries()
|
|
826
|
-
.catch(error => onUnexpectedError(error, 'init queries'));
|
|
827
|
+
executeInitQueries().catch(error => onUnexpectedError(error, 'init queries'));
|
|
827
828
|
}
|
|
828
|
-
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
829
|
-
.catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
829
|
+
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable').catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
830
830
|
}
|
|
831
831
|
if (receivedPendingNotifications && // if we don't have the app state key
|
|
832
832
|
// we keep buffering events until we finally have
|
package/lib/Socket/groups.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { proto } from '../../WAProto';
|
|
2
|
-
import { GroupMetadata, ParticipantAction, SocketConfig } from '../Types';
|
|
2
|
+
import { GroupMetadata, ParticipantAction, SocketConfig, WAMessageKey } from '../Types';
|
|
3
3
|
import { BinaryNode } from '../WABinary';
|
|
4
4
|
export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
5
5
|
groupMetadata: (jid: string) => Promise<GroupMetadata>;
|
|
@@ -34,7 +34,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
34
34
|
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
35
35
|
* @param inviteMessage the message to accept
|
|
36
36
|
*/
|
|
37
|
-
groupAcceptInviteV4: (key: string |
|
|
37
|
+
groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
|
|
38
38
|
groupGetInviteInfo: (code: string) => Promise<GroupMetadata>;
|
|
39
39
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
40
40
|
groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
|
|
@@ -78,7 +78,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
78
78
|
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
|
|
79
79
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
80
80
|
getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
|
|
81
|
-
resyncAppState: (collections: readonly ("
|
|
81
|
+
resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
82
82
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
83
83
|
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
|
84
84
|
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
|
@@ -94,9 +94,9 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
94
94
|
type: "md";
|
|
95
95
|
ws: import("./Client").WebSocketClient;
|
|
96
96
|
ev: import("../Types").BaileysEventEmitter & {
|
|
97
|
-
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (
|
|
97
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
98
98
|
buffer(): void;
|
|
99
|
-
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (
|
|
99
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
|
|
100
100
|
flush(force?: boolean): boolean;
|
|
101
101
|
isBuffering(): boolean;
|
|
102
102
|
};
|
|
@@ -117,7 +117,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
117
117
|
onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
|
|
118
118
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
119
119
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
120
|
-
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
120
|
+
requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
|
|
121
121
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
122
122
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
123
123
|
};
|