@periskope/baileys 6.7.18-alpha.1 → 6.7.18-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Defaults/index.d.ts +1 -1
- package/lib/Defaults/index.js +16 -16
- package/lib/Signal/libsignal.js +5 -5
- package/lib/Socket/Client/websocket.js +1 -1
- package/lib/Socket/business.d.ts +4 -4
- package/lib/Socket/business.js +5 -5
- package/lib/Socket/chats.d.ts +3 -3
- package/lib/Socket/chats.js +65 -67
- package/lib/Socket/groups.d.ts +5 -5
- package/lib/Socket/groups.js +38 -23
- package/lib/Socket/index.d.ts +4 -4
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +4 -4
- package/lib/Socket/messages-recv.js +73 -57
- package/lib/Socket/messages-send.d.ts +4 -4
- package/lib/Socket/messages-send.js +53 -46
- package/lib/Socket/socket.d.ts +2 -2
- package/lib/Socket/socket.js +16 -27
- package/lib/Socket/usync.d.ts +2 -2
- 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 +8 -3
- package/lib/Types/Message.d.ts +5 -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 +5 -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 +9 -10
- package/lib/Utils/lt-hash.js +2 -2
- package/lib/Utils/make-mutex.js +1 -1
- package/lib/Utils/messages-media.js +34 -46
- 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 +28 -33
- 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 +2 -2
- 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 -5
package/lib/Defaults/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare const DEF_TAG_PREFIX = "TAG:";
|
|
|
7
7
|
export declare const PHONE_CONNECTION_CB = "CB:Pong";
|
|
8
8
|
export declare const WA_DEFAULT_EPHEMERAL: number;
|
|
9
9
|
export declare const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
|
|
10
|
-
export declare const DICT_VERSION =
|
|
10
|
+
export declare const DICT_VERSION = 3;
|
|
11
11
|
export declare const KEY_BUNDLE_TYPE: Buffer<ArrayBuffer>;
|
|
12
12
|
export declare const NOISE_WA_HEADER: Buffer<ArrayBuffer>;
|
|
13
13
|
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
package/lib/Defaults/index.js
CHANGED
|
@@ -16,21 +16,21 @@ exports.DEF_TAG_PREFIX = 'TAG:';
|
|
|
16
16
|
exports.PHONE_CONNECTION_CB = 'CB:Pong';
|
|
17
17
|
exports.WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
|
|
18
18
|
exports.NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0';
|
|
19
|
-
exports.DICT_VERSION =
|
|
19
|
+
exports.DICT_VERSION = 3;
|
|
20
20
|
exports.KEY_BUNDLE_TYPE = Buffer.from([5]);
|
|
21
21
|
exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]); // last is "DICT_VERSION"
|
|
22
22
|
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
23
23
|
// export const URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g
|
|
24
24
|
exports.URL_REGEX = /\b((https?:\/\/|www\.)\S+)/gi;
|
|
25
25
|
exports.WA_CERT_DETAILS = {
|
|
26
|
-
SERIAL: 0
|
|
26
|
+
SERIAL: 0
|
|
27
27
|
};
|
|
28
28
|
exports.PROCESSABLE_HISTORY_TYPES = [
|
|
29
29
|
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
30
30
|
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
|
|
31
31
|
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
|
|
32
32
|
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
|
|
33
|
-
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND
|
|
33
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND
|
|
34
34
|
];
|
|
35
35
|
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
36
36
|
version: baileys_version_json_1.version,
|
|
@@ -57,7 +57,7 @@ exports.DEFAULT_CONNECTION_CONFIG = {
|
|
|
57
57
|
options: {},
|
|
58
58
|
appStateMacVerification: {
|
|
59
59
|
patch: false,
|
|
60
|
-
snapshot: false
|
|
60
|
+
snapshot: false
|
|
61
61
|
},
|
|
62
62
|
countryCode: 'US',
|
|
63
63
|
getMessage: async () => undefined,
|
|
@@ -73,18 +73,18 @@ exports.MEDIA_PATH_MAP = {
|
|
|
73
73
|
'thumbnail-link': '/mms/image',
|
|
74
74
|
'product-catalog-image': '/product/image',
|
|
75
75
|
'md-app-state': '',
|
|
76
|
-
'md-msg-hist': '/mms/md-app-state'
|
|
76
|
+
'md-msg-hist': '/mms/md-app-state'
|
|
77
77
|
};
|
|
78
78
|
exports.MEDIA_HKDF_KEY_MAPPING = {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
audio: 'Audio',
|
|
80
|
+
document: 'Document',
|
|
81
|
+
gif: 'Video',
|
|
82
|
+
image: 'Image',
|
|
83
|
+
ppic: '',
|
|
84
|
+
product: 'Image',
|
|
85
|
+
ptt: 'Audio',
|
|
86
|
+
sticker: 'Image',
|
|
87
|
+
video: 'Video',
|
|
88
88
|
'thumbnail-document': 'Document Thumbnail',
|
|
89
89
|
'thumbnail-image': 'Image Thumbnail',
|
|
90
90
|
'thumbnail-video': 'Video Thumbnail',
|
|
@@ -93,7 +93,7 @@ exports.MEDIA_HKDF_KEY_MAPPING = {
|
|
|
93
93
|
'md-app-state': 'App State',
|
|
94
94
|
'product-catalog-image': '',
|
|
95
95
|
'payment-bg-image': 'Payment Background',
|
|
96
|
-
|
|
96
|
+
ptv: 'Video'
|
|
97
97
|
};
|
|
98
98
|
exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
|
|
99
99
|
exports.MIN_PREKEY_COUNT = 5;
|
|
@@ -102,5 +102,5 @@ exports.DEFAULT_CACHE_TTLS = {
|
|
|
102
102
|
SIGNAL_STORE: 5 * 60, // 5 minutes
|
|
103
103
|
MSG_RETRY: 60 * 60, // 1 hour
|
|
104
104
|
CALL_OFFER: 5 * 60, // 5 minutes
|
|
105
|
-
USER_DEVICES: 5 * 60
|
|
105
|
+
USER_DEVICES: 5 * 60 // 5 minutes
|
|
106
106
|
};
|
package/lib/Signal/libsignal.js
CHANGED
|
@@ -89,7 +89,7 @@ function makeLibSignalRepository(auth) {
|
|
|
89
89
|
const ciphertext = await session.encrypt(data);
|
|
90
90
|
return {
|
|
91
91
|
ciphertext,
|
|
92
|
-
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize()
|
|
92
|
+
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize()
|
|
93
93
|
};
|
|
94
94
|
},
|
|
95
95
|
async injectE2ESession({ jid, session }) {
|
|
@@ -98,7 +98,7 @@ function makeLibSignalRepository(auth) {
|
|
|
98
98
|
},
|
|
99
99
|
jidToSignalProtocolAddress(jid) {
|
|
100
100
|
return jidToSignalProtocolAddress(jid).toString();
|
|
101
|
-
}
|
|
101
|
+
}
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
const jidToSignalProtocolAddress = (jid) => {
|
|
@@ -117,7 +117,7 @@ function signalStorage({ creds, keys }) {
|
|
|
117
117
|
}
|
|
118
118
|
},
|
|
119
119
|
storeSession: async (id, session) => {
|
|
120
|
-
await keys.set({
|
|
120
|
+
await keys.set({ session: { [id]: session.serialize() } });
|
|
121
121
|
},
|
|
122
122
|
isTrustedIdentity: () => {
|
|
123
123
|
return true;
|
|
@@ -149,12 +149,12 @@ function signalStorage({ creds, keys }) {
|
|
|
149
149
|
storeSenderKey: async (keyId, key) => {
|
|
150
150
|
await keys.set({ 'sender-key': { [keyId]: key.serialize() } });
|
|
151
151
|
},
|
|
152
|
-
getOurRegistrationId: () =>
|
|
152
|
+
getOurRegistrationId: () => creds.registrationId,
|
|
153
153
|
getOurIdentity: () => {
|
|
154
154
|
const { signedIdentityKey } = creds;
|
|
155
155
|
return {
|
|
156
156
|
privKey: Buffer.from(signedIdentityKey.private),
|
|
157
|
-
pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public)
|
|
157
|
+
pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public)
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
160
|
};
|
|
@@ -38,7 +38,7 @@ class WebSocketClient extends types_1.AbstractSocketClient {
|
|
|
38
38
|
headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
|
|
39
39
|
handshakeTimeout: this.config.connectTimeoutMs,
|
|
40
40
|
timeout: this.config.connectTimeoutMs,
|
|
41
|
-
agent: this.config.agent
|
|
41
|
+
agent: this.config.agent
|
|
42
42
|
});
|
|
43
43
|
this.socket.setMaxListeners(0);
|
|
44
44
|
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
|
package/lib/Socket/business.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
60
60
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
61
61
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
62
62
|
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
|
63
|
-
groupAcceptInviteV4: (key: string | import("../Types").
|
|
63
|
+
groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
|
|
64
64
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
65
65
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
66
66
|
groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
|
|
@@ -101,7 +101,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
101
101
|
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
|
|
102
102
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
103
103
|
getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
|
|
104
|
-
resyncAppState: (collections: readonly ("
|
|
104
|
+
resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
105
105
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
106
106
|
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
|
107
107
|
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
|
@@ -117,9 +117,9 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
117
117
|
type: "md";
|
|
118
118
|
ws: import("./Client").WebSocketClient;
|
|
119
119
|
ev: import("../Types").BaileysEventEmitter & {
|
|
120
|
-
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (
|
|
120
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
121
121
|
buffer(): void;
|
|
122
|
-
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (
|
|
122
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
|
|
123
123
|
flush(force?: boolean): boolean;
|
|
124
124
|
isBuffering(): boolean;
|
|
125
125
|
};
|
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
|
};
|
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;
|
|
@@ -500,7 +503,7 @@ const makeChatsSocket = (config) => {
|
|
|
500
503
|
tag: 'chatstate',
|
|
501
504
|
attrs: {
|
|
502
505
|
from: me.id,
|
|
503
|
-
to: toJid
|
|
506
|
+
to: toJid
|
|
504
507
|
},
|
|
505
508
|
content: [
|
|
506
509
|
{
|
|
@@ -515,7 +518,7 @@ const makeChatsSocket = (config) => {
|
|
|
515
518
|
* @param toJid the jid to subscribe to
|
|
516
519
|
* @param tcToken token for subscription, use if present
|
|
517
520
|
*/
|
|
518
|
-
const presenceSubscribe = (toJid, tcToken) =>
|
|
521
|
+
const presenceSubscribe = (toJid, tcToken) => sendNode({
|
|
519
522
|
tag: 'presence',
|
|
520
523
|
attrs: {
|
|
521
524
|
to: toJid,
|
|
@@ -531,7 +534,7 @@ const makeChatsSocket = (config) => {
|
|
|
531
534
|
}
|
|
532
535
|
]
|
|
533
536
|
: undefined
|
|
534
|
-
})
|
|
537
|
+
});
|
|
535
538
|
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
536
539
|
var _a;
|
|
537
540
|
let presence;
|
|
@@ -597,7 +600,7 @@ const makeChatsSocket = (config) => {
|
|
|
597
600
|
attrs: {
|
|
598
601
|
name,
|
|
599
602
|
version: (state.version - 1).toString(),
|
|
600
|
-
|
|
603
|
+
return_snapshot: 'false'
|
|
601
604
|
},
|
|
602
605
|
content: [
|
|
603
606
|
{
|
|
@@ -617,7 +620,7 @@ const makeChatsSocket = (config) => {
|
|
|
617
620
|
});
|
|
618
621
|
if (config.emitOwnEvents) {
|
|
619
622
|
const { onMutation } = newAppStateChunkHandler(false);
|
|
620
|
-
const { mutationMap } = await (0, Utils_1.decodePatches)(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version }
|
|
623
|
+
const { mutationMap } = await (0, Utils_1.decodePatches)(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
|
|
621
624
|
for (const key in mutationMap) {
|
|
622
625
|
onMutation(mutationMap[key]);
|
|
623
626
|
}
|
|
@@ -631,19 +634,23 @@ const makeChatsSocket = (config) => {
|
|
|
631
634
|
attrs: {
|
|
632
635
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
633
636
|
xmlns: 'w',
|
|
634
|
-
type: 'get'
|
|
637
|
+
type: 'get'
|
|
635
638
|
},
|
|
636
639
|
content: [
|
|
637
|
-
{
|
|
640
|
+
{
|
|
641
|
+
tag: 'props',
|
|
642
|
+
attrs: {
|
|
638
643
|
protocol: '2',
|
|
639
644
|
hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
|
|
640
|
-
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
641
647
|
]
|
|
642
648
|
});
|
|
643
649
|
const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
|
|
644
650
|
let props = {};
|
|
645
651
|
if (propsNode) {
|
|
646
|
-
if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) {
|
|
652
|
+
if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) {
|
|
653
|
+
// on some clients, the hash is returning as undefined
|
|
647
654
|
authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
|
|
648
655
|
ev.emit('creds.update', authState.creds);
|
|
649
656
|
}
|
|
@@ -656,7 +663,7 @@ const makeChatsSocket = (config) => {
|
|
|
656
663
|
* modify a chat -- mark unread, read etc.
|
|
657
664
|
* lastMessages must be sorted in reverse chronologically
|
|
658
665
|
* requires the last messages till the last message received; required for archive & unread
|
|
659
|
-
|
|
666
|
+
*/
|
|
660
667
|
const chatModify = (mod, jid) => {
|
|
661
668
|
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
662
669
|
return appPatch(patch);
|
|
@@ -729,17 +736,13 @@ const makeChatsSocket = (config) => {
|
|
|
729
736
|
* help ensure parity with WA Web
|
|
730
737
|
* */
|
|
731
738
|
const executeInitQueries = async () => {
|
|
732
|
-
await Promise.all([
|
|
733
|
-
fetchProps(),
|
|
734
|
-
fetchBlocklist(),
|
|
735
|
-
fetchPrivacySettings(),
|
|
736
|
-
]);
|
|
739
|
+
await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
|
|
737
740
|
};
|
|
738
741
|
const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
|
|
739
742
|
var _a, _b, _c;
|
|
740
743
|
ev.emit('messages.upsert', { messages: [msg], type });
|
|
741
744
|
if (!!msg.pushName) {
|
|
742
|
-
let jid = msg.key.fromMe ? authState.creds.me.id :
|
|
745
|
+
let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
|
|
743
746
|
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
744
747
|
if (!msg.key.fromMe) {
|
|
745
748
|
ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
|
|
@@ -751,8 +754,7 @@ const makeChatsSocket = (config) => {
|
|
|
751
754
|
}
|
|
752
755
|
const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
|
|
753
756
|
const shouldProcessHistoryMsg = historyMsg
|
|
754
|
-
?
|
|
755
|
-
&& Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
|
|
757
|
+
? shouldSyncHistoryMessage(historyMsg) && Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)
|
|
756
758
|
: false;
|
|
757
759
|
if (historyMsg && !authState.creds.myAppStateKeyId) {
|
|
758
760
|
logger.warn('skipping app state sync, as myAppStateKeyId is not set');
|
|
@@ -760,8 +762,7 @@ const makeChatsSocket = (config) => {
|
|
|
760
762
|
}
|
|
761
763
|
await Promise.all([
|
|
762
764
|
(async () => {
|
|
763
|
-
if (historyMsg
|
|
764
|
-
&& authState.creds.myAppStateKeyId) {
|
|
765
|
+
if (historyMsg && authState.creds.myAppStateKeyId) {
|
|
765
766
|
pendingAppStateSync = false;
|
|
766
767
|
await doAppStateSync();
|
|
767
768
|
}
|
|
@@ -777,8 +778,7 @@ const makeChatsSocket = (config) => {
|
|
|
777
778
|
getMessage: config.getMessage
|
|
778
779
|
})
|
|
779
780
|
]);
|
|
780
|
-
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
|
|
781
|
-
&& pendingAppStateSync) {
|
|
781
|
+
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare) && pendingAppStateSync) {
|
|
782
782
|
await doAppStateSync();
|
|
783
783
|
pendingAppStateSync = false;
|
|
784
784
|
}
|
|
@@ -823,11 +823,9 @@ const makeChatsSocket = (config) => {
|
|
|
823
823
|
var _a;
|
|
824
824
|
if (connection === 'open') {
|
|
825
825
|
if (fireInitQueries) {
|
|
826
|
-
executeInitQueries()
|
|
827
|
-
.catch(error => onUnexpectedError(error, 'init queries'));
|
|
826
|
+
executeInitQueries().catch(error => onUnexpectedError(error, 'init queries'));
|
|
828
827
|
}
|
|
829
|
-
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
830
|
-
.catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
828
|
+
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable').catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
831
829
|
}
|
|
832
830
|
if (receivedPendingNotifications && // if we don't have the app state key
|
|
833
831
|
// 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
|
};
|