@queenanya/baileys 7.4.10 → 7.4.14
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 +26 -26
- package/WAProto/index.js +97194 -67957
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +231 -1
- package/lib/Defaults/index.js +23 -11
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.js +3 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +2 -2
- package/lib/Socket/business.d.ts +28 -31
- package/lib/Socket/chats.d.ts +9 -17
- package/lib/Socket/chats.js +116 -115
- package/lib/Socket/groups.d.ts +10 -23
- package/lib/Socket/groups.js +1 -12
- package/lib/Socket/index.d.ts +38 -69
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +28 -30
- package/lib/Socket/messages-recv.js +180 -291
- package/lib/Socket/messages-send.d.ts +19 -25
- package/lib/Socket/messages-send.js +76 -110
- package/lib/Socket/newsletter.d.ts +13 -19
- package/lib/Socket/newsletter.js +54 -67
- package/lib/Socket/{communities.d.ts → registration.d.ts} +145 -94
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +1 -3
- package/lib/Socket/socket.js +17 -15
- package/lib/Store/make-cache-manager-store.d.ts +1 -2
- package/lib/Store/make-in-memory-store.js +11 -13
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +6 -1
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -15
- package/lib/Types/Contact.d.ts +1 -6
- package/lib/Types/Events.d.ts +2 -44
- package/lib/Types/GroupMetadata.d.ts +1 -3
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Message.d.ts +30 -37
- package/lib/Types/Newsletter.d.ts +13 -0
- package/lib/Types/Newsletter.js +15 -1
- package/lib/Types/Socket.d.ts +3 -10
- package/lib/Types/index.d.ts +0 -8
- package/lib/Utils/auth-utils.js +7 -1
- package/lib/Utils/chat-utils.d.ts +4 -5
- package/lib/Utils/chat-utils.js +20 -52
- package/lib/Utils/crypto.d.ts +1 -2
- package/lib/Utils/crypto.js +2 -4
- package/lib/Utils/decode-wa-message.d.ts +0 -1
- package/lib/Utils/decode-wa-message.js +14 -34
- package/lib/Utils/event-buffer.js +8 -14
- package/lib/Utils/generics.d.ts +13 -37
- package/lib/Utils/generics.js +18 -103
- package/lib/Utils/history.d.ts +2 -6
- package/lib/Utils/history.js +0 -3
- package/lib/Utils/index.d.ts +0 -1
- package/lib/Utils/index.js +0 -1
- package/lib/Utils/link-preview.js +1 -24
- package/lib/Utils/logger.d.ts +3 -1
- package/lib/Utils/make-mutex.js +0 -1
- package/lib/Utils/messages-media.d.ts +2 -3
- package/lib/Utils/messages-media.js +32 -17
- package/lib/Utils/messages.d.ts +0 -1
- package/lib/Utils/messages.js +72 -67
- package/lib/Utils/noise-handler.d.ts +3 -3
- package/lib/Utils/noise-handler.js +12 -7
- package/lib/Utils/process-message.d.ts +2 -3
- package/lib/Utils/process-message.js +21 -55
- package/lib/Utils/signal.js +16 -23
- package/lib/Utils/use-multi-file-auth-state.js +3 -17
- package/lib/Utils/validate-connection.d.ts +1 -0
- package/lib/Utils/validate-connection.js +44 -10
- package/lib/WABinary/constants.js +5 -5
- package/lib/WABinary/decode.d.ts +2 -3
- package/lib/WABinary/decode.js +4 -6
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +6 -8
- package/lib/WABinary/generic-utils.d.ts +0 -1
- package/lib/WABinary/jid-utils.d.ts +3 -3
- package/lib/WABinary/jid-utils.js +5 -5
- package/lib/WAM/BinaryInfo.d.ts +2 -3
- package/lib/WAM/constants.d.ts +2 -3
- package/lib/WAM/encode.d.ts +0 -1
- package/lib/WAM/encode.js +2 -2
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/package.json +36 -38
- package/lib/Socket/communities.js +0 -354
- package/lib/Socket/usync.d.ts +0 -38
- package/lib/Socket/usync.js +0 -70
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/USync.js +0 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/Protocols/index.js +0 -20
- package/lib/WAUSync/USyncQuery.d.ts +0 -26
- package/lib/WAUSync/USyncQuery.js +0 -79
- package/lib/WAUSync/USyncUser.d.ts +0 -10
- package/lib/WAUSync/USyncUser.js +0 -22
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/WAUSync/index.js +0 -19
- /package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +0 -0
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
package/lib/Socket/business.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
/// <reference types="long" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
1
|
/// <reference types="node" />
|
|
4
2
|
import { GetCatalogOptions, ProductCreate, ProductUpdate, SocketConfig } from '../Types';
|
|
5
3
|
import { BinaryNode } from '../WABinary';
|
|
6
4
|
export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
7
|
-
logger: import("pino").Logger<
|
|
5
|
+
logger: import("pino").Logger<import("pino").LoggerOptions>;
|
|
8
6
|
getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
|
|
9
7
|
getCatalog: ({ jid, limit, cursor }: GetCatalogOptions) => Promise<{
|
|
10
8
|
products: import("../Types").Product[];
|
|
@@ -20,28 +18,32 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
20
18
|
productUpdate: (productId: string, update: ProductUpdate) => Promise<import("../Types").Product>;
|
|
21
19
|
sendMessageAck: ({ tag, attrs, content }: BinaryNode) => Promise<void>;
|
|
22
20
|
sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
|
|
21
|
+
offerCall: (toJid: string, isVideo?: boolean) => Promise<{
|
|
22
|
+
id: string;
|
|
23
|
+
to: string;
|
|
24
|
+
}>;
|
|
23
25
|
rejectCall: (callId: string, callFrom: string) => Promise<void>;
|
|
24
|
-
fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | import("long").Long) => Promise<string>;
|
|
25
|
-
requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
|
|
26
26
|
getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
|
|
27
27
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
28
|
-
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache,
|
|
28
|
+
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
29
29
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
30
|
-
sendReceipts: (keys: import("../Types").
|
|
31
|
-
|
|
30
|
+
sendReceipts: (keys: import("../Types").WAProto.IMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
31
|
+
getButtonArgs: (message: import("../Types").WAProto.IMessage) => {
|
|
32
|
+
[key: string]: string;
|
|
33
|
+
};
|
|
34
|
+
readMessages: (keys: import("../Types").WAProto.IMessageKey[]) => Promise<void>;
|
|
32
35
|
refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
|
|
33
|
-
|
|
34
|
-
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
35
|
-
[_: string]: string;
|
|
36
|
-
}>;
|
|
37
|
-
sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
|
36
|
+
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
|
|
38
37
|
createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: {
|
|
39
38
|
[key: string]: string;
|
|
40
39
|
} | undefined) => Promise<{
|
|
41
40
|
nodes: BinaryNode[];
|
|
42
41
|
shouldIncludeDeviceIdentity: boolean;
|
|
43
42
|
}>;
|
|
44
|
-
|
|
43
|
+
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
|
44
|
+
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
45
|
+
[_: string]: string;
|
|
46
|
+
}>;
|
|
45
47
|
updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
|
|
46
48
|
sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
|
|
47
49
|
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
@@ -56,13 +58,14 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
56
58
|
newsletterFollow: (jid: string) => Promise<void>;
|
|
57
59
|
newsletterUnmute: (jid: string) => Promise<void>;
|
|
58
60
|
newsletterMute: (jid: string) => Promise<void>;
|
|
59
|
-
|
|
61
|
+
newsletterAction: (jid: string, type: "mute" | "follow" | "unfollow" | "unmute") => Promise<void>;
|
|
62
|
+
newsletterCreate: (name: string, description: string, reaction_codes: string) => Promise<import("../Types").NewsletterMetadata>;
|
|
60
63
|
newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
|
|
61
64
|
newsletterAdminCount: (jid: string) => Promise<number>;
|
|
62
65
|
newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
|
|
63
66
|
newsletterDemote: (jid: string, user: string) => Promise<void>;
|
|
64
67
|
newsletterDelete: (jid: string) => Promise<void>;
|
|
65
|
-
newsletterReactMessage: (jid: string,
|
|
68
|
+
newsletterReactMessage: (jid: string, serverId: string, code?: string | undefined) => Promise<void>;
|
|
66
69
|
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
|
67
70
|
newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
|
68
71
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
@@ -85,8 +88,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
85
88
|
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
|
86
89
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
87
90
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
88
|
-
|
|
89
|
-
groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
|
|
91
|
+
groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
|
|
90
92
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
91
93
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
92
94
|
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
@@ -104,34 +106,30 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
104
106
|
presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
|
|
105
107
|
profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
|
|
106
108
|
onWhatsApp: (...jids: string[]) => Promise<{
|
|
109
|
+
exists: boolean;
|
|
107
110
|
jid: string;
|
|
108
|
-
|
|
109
|
-
}[] | undefined>;
|
|
111
|
+
}[]>;
|
|
110
112
|
fetchBlocklist: () => Promise<string[]>;
|
|
111
|
-
fetchStatus: (
|
|
112
|
-
|
|
113
|
+
fetchStatus: (jid: string) => Promise<{
|
|
114
|
+
status: string | undefined;
|
|
115
|
+
setAt: Date;
|
|
116
|
+
} | undefined>;
|
|
113
117
|
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
|
114
|
-
updateProfilePictureFull: (jid: any, content: any) => Promise<void>;
|
|
115
|
-
updateProfilePictureFull2: (jid: any, content: any) => Promise<void>;
|
|
116
118
|
removeProfilePicture: (jid: string) => Promise<void>;
|
|
117
119
|
updateProfileStatus: (status: string) => Promise<void>;
|
|
118
120
|
updateProfileName: (name: string) => Promise<void>;
|
|
119
121
|
updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
|
|
120
|
-
updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
|
|
121
122
|
updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
122
123
|
updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
|
|
123
124
|
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
124
125
|
updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
125
126
|
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
|
126
|
-
updateGroupsAddPrivacy: (value: import("../Types").
|
|
127
|
+
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
127
128
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
128
129
|
getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
|
|
129
130
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
130
131
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
131
132
|
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
|
|
132
|
-
addOrEditContact: (jid: string, contact: import("../Types").ContactAction) => Promise<void>;
|
|
133
|
-
removeContact: (jid: string) => Promise<void>;
|
|
134
|
-
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
|
135
133
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
136
134
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
137
135
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
@@ -140,9 +138,8 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
140
138
|
id: string;
|
|
141
139
|
fromMe?: boolean | undefined;
|
|
142
140
|
}[], star: boolean) => Promise<void>;
|
|
143
|
-
executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
|
|
144
141
|
type: "md";
|
|
145
|
-
ws:
|
|
142
|
+
ws: any;
|
|
146
143
|
ev: import("../Types").BaileysEventEmitter & {
|
|
147
144
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
148
145
|
buffer(): void;
|
package/lib/Socket/chats.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
import { Boom } from '@hapi/boom';
|
|
4
3
|
import { proto } from '../../WAProto';
|
|
5
|
-
import { ChatModification,
|
|
6
|
-
import { LabelActionBody } from '../Types/Label';
|
|
4
|
+
import { ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAPatchCreate, WAPresence, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types';
|
|
7
5
|
import { BinaryNode } from '../WABinary';
|
|
8
|
-
import { USyncQuery } from '../WAUSync';
|
|
9
6
|
export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
10
7
|
processingMutex: {
|
|
11
8
|
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
|
@@ -19,34 +16,30 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
|
19
16
|
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
|
20
17
|
profilePictureUrl: (jid: string, type?: 'preview' | 'image', timeoutMs?: number) => Promise<string | undefined>;
|
|
21
18
|
onWhatsApp: (...jids: string[]) => Promise<{
|
|
19
|
+
exists: boolean;
|
|
22
20
|
jid: string;
|
|
23
|
-
|
|
24
|
-
}[] | undefined>;
|
|
21
|
+
}[]>;
|
|
25
22
|
fetchBlocklist: () => Promise<string[]>;
|
|
26
|
-
fetchStatus: (
|
|
27
|
-
|
|
23
|
+
fetchStatus: (jid: string) => Promise<{
|
|
24
|
+
status: string | undefined;
|
|
25
|
+
setAt: Date;
|
|
26
|
+
} | undefined>;
|
|
28
27
|
updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
|
|
29
|
-
updateProfilePictureFull: (jid: any, content: any) => Promise<void>;
|
|
30
|
-
updateProfilePictureFull2: (jid: any, content: any) => Promise<void>;
|
|
31
28
|
removeProfilePicture: (jid: string) => Promise<void>;
|
|
32
29
|
updateProfileStatus: (status: string) => Promise<void>;
|
|
33
30
|
updateProfileName: (name: string) => Promise<void>;
|
|
34
31
|
updateBlockStatus: (jid: string, action: 'block' | 'unblock') => Promise<void>;
|
|
35
|
-
updateCallPrivacy: (value: WAPrivacyCallValue) => Promise<void>;
|
|
36
32
|
updateLastSeenPrivacy: (value: WAPrivacyValue) => Promise<void>;
|
|
37
33
|
updateOnlinePrivacy: (value: WAPrivacyOnlineValue) => Promise<void>;
|
|
38
34
|
updateProfilePicturePrivacy: (value: WAPrivacyValue) => Promise<void>;
|
|
39
35
|
updateStatusPrivacy: (value: WAPrivacyValue) => Promise<void>;
|
|
40
36
|
updateReadReceiptsPrivacy: (value: WAReadReceiptsValue) => Promise<void>;
|
|
41
|
-
updateGroupsAddPrivacy: (value:
|
|
37
|
+
updateGroupsAddPrivacy: (value: WAPrivacyValue) => Promise<void>;
|
|
42
38
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
43
39
|
getBusinessProfile: (jid: string) => Promise<WABusinessProfile | void>;
|
|
44
40
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
45
41
|
chatModify: (mod: ChatModification, jid: string) => Promise<void>;
|
|
46
42
|
cleanDirtyBits: (type: 'account_sync' | 'groups', fromTimestamp?: number | string) => Promise<void>;
|
|
47
|
-
addOrEditContact: (jid: string, contact: ContactAction) => Promise<void>;
|
|
48
|
-
removeContact: (jid: string) => Promise<void>;
|
|
49
|
-
addLabel: (jid: string, labels: LabelActionBody) => Promise<void>;
|
|
50
43
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
51
44
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
52
45
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
@@ -55,9 +48,8 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
|
55
48
|
id: string;
|
|
56
49
|
fromMe?: boolean;
|
|
57
50
|
}[], star: boolean) => Promise<void>;
|
|
58
|
-
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
|
|
59
51
|
type: "md";
|
|
60
|
-
ws:
|
|
52
|
+
ws: any;
|
|
61
53
|
ev: import("../Types").BaileysEventEmitter & {
|
|
62
54
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
63
55
|
buffer(): void;
|
package/lib/Socket/chats.js
CHANGED
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.makeChatsSocket = void 0;
|
|
7
7
|
const boom_1 = require("@hapi/boom");
|
|
8
|
-
const node_cache_1 = __importDefault(require("node-cache"));
|
|
9
8
|
const WAProto_1 = require("../../WAProto");
|
|
10
9
|
const Defaults_1 = require("../Defaults");
|
|
11
10
|
const Types_1 = require("../Types");
|
|
@@ -13,25 +12,17 @@ const Utils_1 = require("../Utils");
|
|
|
13
12
|
const make_mutex_1 = require("../Utils/make-mutex");
|
|
14
13
|
const process_message_1 = __importDefault(require("../Utils/process-message"));
|
|
15
14
|
const WABinary_1 = require("../WABinary");
|
|
16
|
-
const
|
|
17
|
-
const usync_1 = require("./usync");
|
|
15
|
+
const socket_1 = require("./socket");
|
|
18
16
|
const MAX_SYNC_ATTEMPTS = 2;
|
|
19
17
|
const makeChatsSocket = (config) => {
|
|
20
18
|
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
|
|
21
|
-
const sock = (0,
|
|
19
|
+
const sock = (0, socket_1.makeSocket)(config);
|
|
22
20
|
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, } = sock;
|
|
23
21
|
let privacySettings;
|
|
24
22
|
let needToFlushWithAppStateSync = false;
|
|
25
23
|
let pendingAppStateSync = false;
|
|
26
24
|
/** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
|
|
27
25
|
const processingMutex = (0, make_mutex_1.makeMutex)();
|
|
28
|
-
const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
|
|
29
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
30
|
-
useClones: false
|
|
31
|
-
});
|
|
32
|
-
if (!config.placeholderResendCache) {
|
|
33
|
-
config.placeholderResendCache = placeholderResendCache;
|
|
34
|
-
}
|
|
35
26
|
/** helper function to fetch the given app state sync key */
|
|
36
27
|
const getAppStateSyncKey = async (keyId) => {
|
|
37
28
|
const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
|
|
@@ -75,9 +66,6 @@ const makeChatsSocket = (config) => {
|
|
|
75
66
|
}]
|
|
76
67
|
});
|
|
77
68
|
};
|
|
78
|
-
const updateCallPrivacy = async (value) => {
|
|
79
|
-
await privacyQuery('calladd', value);
|
|
80
|
-
};
|
|
81
69
|
const updateLastSeenPrivacy = async (value) => {
|
|
82
70
|
await privacyQuery('last', value);
|
|
83
71
|
};
|
|
@@ -112,39 +100,74 @@ const makeChatsSocket = (config) => {
|
|
|
112
100
|
}]
|
|
113
101
|
});
|
|
114
102
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
103
|
+
/** helper function to run a generic IQ query */
|
|
104
|
+
const interactiveQuery = async (userNodes, queryNode) => {
|
|
105
|
+
const result = await query({
|
|
106
|
+
tag: 'iq',
|
|
107
|
+
attrs: {
|
|
108
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
109
|
+
type: 'get',
|
|
110
|
+
xmlns: 'usync',
|
|
111
|
+
},
|
|
112
|
+
content: [
|
|
113
|
+
{
|
|
114
|
+
tag: 'usync',
|
|
115
|
+
attrs: {
|
|
116
|
+
sid: generateMessageTag(),
|
|
117
|
+
mode: 'query',
|
|
118
|
+
last: 'true',
|
|
119
|
+
index: '0',
|
|
120
|
+
context: 'interactive',
|
|
121
|
+
},
|
|
122
|
+
content: [
|
|
123
|
+
{
|
|
124
|
+
tag: 'query',
|
|
125
|
+
attrs: {},
|
|
126
|
+
content: [queryNode]
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
tag: 'list',
|
|
130
|
+
attrs: {},
|
|
131
|
+
content: userNodes
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
});
|
|
137
|
+
const usyncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'usync');
|
|
138
|
+
const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
|
|
139
|
+
const users = (0, WABinary_1.getBinaryNodeChildren)(listNode, 'user');
|
|
140
|
+
return users;
|
|
137
141
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
const onWhatsApp = async (...jids) => {
|
|
143
|
+
const query = { tag: 'contact', attrs: {} };
|
|
144
|
+
const list = jids.map((jid) => {
|
|
145
|
+
// insures only 1 + is there
|
|
146
|
+
const content = `+${jid.replace('+', '')}`;
|
|
147
|
+
return {
|
|
148
|
+
tag: 'user',
|
|
149
|
+
attrs: {},
|
|
150
|
+
content: [{
|
|
151
|
+
tag: 'contact',
|
|
152
|
+
attrs: {},
|
|
153
|
+
content,
|
|
154
|
+
}],
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
const results = await interactiveQuery(list, query);
|
|
158
|
+
return results.map(user => {
|
|
159
|
+
const contact = (0, WABinary_1.getBinaryNodeChild)(user, 'contact');
|
|
160
|
+
return { exists: (contact === null || contact === void 0 ? void 0 : contact.attrs.type) === 'in', jid: user.attrs.jid };
|
|
161
|
+
}).filter(item => item.exists);
|
|
162
|
+
};
|
|
163
|
+
const fetchStatus = async (jid) => {
|
|
164
|
+
const [result] = await interactiveQuery([{ tag: 'user', attrs: { jid } }], { tag: 'status', attrs: {} });
|
|
146
165
|
if (result) {
|
|
147
|
-
|
|
166
|
+
const status = (0, WABinary_1.getBinaryNodeChild)(result, 'status');
|
|
167
|
+
return {
|
|
168
|
+
status: status === null || status === void 0 ? void 0 : status.content.toString(),
|
|
169
|
+
setAt: new Date(+((status === null || status === void 0 ? void 0 : status.attrs.t) || 0) * 1000)
|
|
170
|
+
};
|
|
148
171
|
}
|
|
149
172
|
};
|
|
150
173
|
/** update the profile picture for yourself or a group */
|
|
@@ -326,9 +349,9 @@ const makeChatsSocket = (config) => {
|
|
|
326
349
|
const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
|
|
327
350
|
const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
|
|
328
351
|
const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
|
|
329
|
-
const businessHoursConfig = businessHours
|
|
330
|
-
|
|
331
|
-
|
|
352
|
+
const businessHoursConfig = businessHours ?
|
|
353
|
+
(0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
|
|
354
|
+
undefined;
|
|
332
355
|
const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
|
|
333
356
|
return {
|
|
334
357
|
wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
|
|
@@ -437,12 +460,16 @@ const makeChatsSocket = (config) => {
|
|
|
437
460
|
states[name] = newState;
|
|
438
461
|
Object.assign(globalMutationMap, mutationMap);
|
|
439
462
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
440
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
463
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
464
|
+
[name]: newState
|
|
465
|
+
} });
|
|
441
466
|
}
|
|
442
467
|
// only process if there are syncd patches
|
|
443
468
|
if (patches.length) {
|
|
444
469
|
const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
445
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
470
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
471
|
+
[name]: newState
|
|
472
|
+
} });
|
|
446
473
|
logger.info(`synced ${name} to v${newState.version}`);
|
|
447
474
|
initialVersionMap[name] = newState.version;
|
|
448
475
|
Object.assign(globalMutationMap, mutationMap);
|
|
@@ -457,11 +484,13 @@ const makeChatsSocket = (config) => {
|
|
|
457
484
|
catch (error) {
|
|
458
485
|
// if retry attempts overshoot
|
|
459
486
|
// or key not found
|
|
460
|
-
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
|
|
461
|
-
|
|
462
|
-
|
|
487
|
+
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
|
|
488
|
+
((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404 ||
|
|
489
|
+
error.name === 'TypeError';
|
|
463
490
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
464
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
491
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
492
|
+
[name]: null
|
|
493
|
+
} });
|
|
465
494
|
// increment number of retries
|
|
466
495
|
attemptsMap[name] = (attemptsMap[name] || 0) + 1;
|
|
467
496
|
if (isIrrecoverableError) {
|
|
@@ -543,15 +572,15 @@ const makeChatsSocket = (config) => {
|
|
|
543
572
|
id: generateMessageTag(),
|
|
544
573
|
type: 'subscribe'
|
|
545
574
|
},
|
|
546
|
-
content: tcToken
|
|
547
|
-
|
|
575
|
+
content: tcToken ?
|
|
576
|
+
[
|
|
548
577
|
{
|
|
549
578
|
tag: 'tctoken',
|
|
550
579
|
attrs: {},
|
|
551
580
|
content: tcToken
|
|
552
581
|
}
|
|
553
|
-
]
|
|
554
|
-
|
|
582
|
+
] :
|
|
583
|
+
undefined
|
|
555
584
|
}));
|
|
556
585
|
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
557
586
|
var _a;
|
|
@@ -582,7 +611,9 @@ const makeChatsSocket = (config) => {
|
|
|
582
611
|
logger.error({ tag, attrs, content }, 'recv invalid presence node');
|
|
583
612
|
}
|
|
584
613
|
if (presence) {
|
|
585
|
-
ev.emit('presence.update', { id: jid, presences: {
|
|
614
|
+
ev.emit('presence.update', { id: jid, presences: {
|
|
615
|
+
[participant]: presence
|
|
616
|
+
} });
|
|
586
617
|
}
|
|
587
618
|
};
|
|
588
619
|
const appPatch = async (patchCreate) => {
|
|
@@ -633,7 +664,9 @@ const makeChatsSocket = (config) => {
|
|
|
633
664
|
]
|
|
634
665
|
};
|
|
635
666
|
await query(node);
|
|
636
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
667
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
668
|
+
[name]: state
|
|
669
|
+
} });
|
|
637
670
|
});
|
|
638
671
|
});
|
|
639
672
|
if (config.emitOwnEvents) {
|
|
@@ -646,7 +679,7 @@ const makeChatsSocket = (config) => {
|
|
|
646
679
|
};
|
|
647
680
|
/** sending non-abt props may fix QR scan fail if server expects */
|
|
648
681
|
const fetchProps = async () => {
|
|
649
|
-
var _a, _b
|
|
682
|
+
var _a, _b;
|
|
650
683
|
const resultNode = await query({
|
|
651
684
|
tag: 'iq',
|
|
652
685
|
attrs: {
|
|
@@ -655,19 +688,20 @@ const makeChatsSocket = (config) => {
|
|
|
655
688
|
type: 'get',
|
|
656
689
|
},
|
|
657
690
|
content: [
|
|
658
|
-
{
|
|
691
|
+
{
|
|
692
|
+
tag: 'props',
|
|
693
|
+
attrs: {
|
|
659
694
|
protocol: '2',
|
|
660
695
|
hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
|
|
661
|
-
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
662
698
|
]
|
|
663
699
|
});
|
|
664
700
|
const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
|
|
665
701
|
let props = {};
|
|
666
702
|
if (propsNode) {
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
ev.emit('creds.update', authState.creds);
|
|
670
|
-
}
|
|
703
|
+
authState.creds.lastPropHash = (_b = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash;
|
|
704
|
+
ev.emit('creds.update', authState.creds);
|
|
671
705
|
props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
|
|
672
706
|
}
|
|
673
707
|
logger.debug('fetched props');
|
|
@@ -677,7 +711,7 @@ const makeChatsSocket = (config) => {
|
|
|
677
711
|
* modify a chat -- mark unread, read etc.
|
|
678
712
|
* lastMessages must be sorted in reverse chronologically
|
|
679
713
|
* requires the last messages till the last message received; required for archive & unread
|
|
680
|
-
|
|
714
|
+
*/
|
|
681
715
|
const chatModify = (mod, jid) => {
|
|
682
716
|
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
683
717
|
return appPatch(patch);
|
|
@@ -693,32 +727,6 @@ const makeChatsSocket = (config) => {
|
|
|
693
727
|
}
|
|
694
728
|
}, jid);
|
|
695
729
|
};
|
|
696
|
-
/**
|
|
697
|
-
* Add or Edit Contact
|
|
698
|
-
*/
|
|
699
|
-
const addOrEditContact = (jid, contact) => {
|
|
700
|
-
return chatModify({
|
|
701
|
-
contact
|
|
702
|
-
}, jid);
|
|
703
|
-
};
|
|
704
|
-
/**
|
|
705
|
-
* Remove Contact
|
|
706
|
-
*/
|
|
707
|
-
const removeContact = (jid) => {
|
|
708
|
-
return chatModify({
|
|
709
|
-
contact: null
|
|
710
|
-
}, jid);
|
|
711
|
-
};
|
|
712
|
-
/**
|
|
713
|
-
* Adds label
|
|
714
|
-
*/
|
|
715
|
-
const addLabel = (jid, labels) => {
|
|
716
|
-
return chatModify({
|
|
717
|
-
addLabel: {
|
|
718
|
-
...labels
|
|
719
|
-
}
|
|
720
|
-
}, jid);
|
|
721
|
-
};
|
|
722
730
|
/**
|
|
723
731
|
* Adds label for the chats
|
|
724
732
|
*/
|
|
@@ -787,25 +795,24 @@ const makeChatsSocket = (config) => {
|
|
|
787
795
|
}
|
|
788
796
|
}
|
|
789
797
|
const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
|
|
790
|
-
const shouldProcessHistoryMsg = historyMsg
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
798
|
+
const shouldProcessHistoryMsg = historyMsg ?
|
|
799
|
+
(shouldSyncHistoryMessage(historyMsg) &&
|
|
800
|
+
Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)) :
|
|
801
|
+
false;
|
|
794
802
|
if (historyMsg && !authState.creds.myAppStateKeyId) {
|
|
795
803
|
logger.warn('skipping app state sync, as myAppStateKeyId is not set');
|
|
796
804
|
pendingAppStateSync = true;
|
|
797
805
|
}
|
|
798
806
|
await Promise.all([
|
|
799
807
|
(async () => {
|
|
800
|
-
if (historyMsg
|
|
801
|
-
|
|
808
|
+
if (historyMsg &&
|
|
809
|
+
authState.creds.myAppStateKeyId) {
|
|
802
810
|
pendingAppStateSync = false;
|
|
803
811
|
await doAppStateSync();
|
|
804
812
|
}
|
|
805
813
|
})(),
|
|
806
814
|
(0, process_message_1.default)(msg, {
|
|
807
815
|
shouldProcessHistoryMsg,
|
|
808
|
-
placeholderResendCache,
|
|
809
816
|
ev,
|
|
810
817
|
creds: authState.creds,
|
|
811
818
|
keyStore: authState.keys,
|
|
@@ -814,8 +821,8 @@ const makeChatsSocket = (config) => {
|
|
|
814
821
|
getMessage: config.getMessage,
|
|
815
822
|
})
|
|
816
823
|
]);
|
|
817
|
-
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
|
|
818
|
-
|
|
824
|
+
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare) &&
|
|
825
|
+
pendingAppStateSync) {
|
|
819
826
|
await doAppStateSync();
|
|
820
827
|
pendingAppStateSync = false;
|
|
821
828
|
}
|
|
@@ -866,13 +873,14 @@ const makeChatsSocket = (config) => {
|
|
|
866
873
|
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
867
874
|
.catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
868
875
|
}
|
|
869
|
-
if (receivedPendingNotifications
|
|
876
|
+
if (receivedPendingNotifications) {
|
|
877
|
+
// if we don't have the app state key
|
|
870
878
|
// we keep buffering events until we finally have
|
|
871
879
|
// the key and can sync the messages
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
880
|
+
if (!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId) && !config.mobile) {
|
|
881
|
+
ev.buffer();
|
|
882
|
+
needToFlushWithAppStateSync = true;
|
|
883
|
+
}
|
|
876
884
|
}
|
|
877
885
|
});
|
|
878
886
|
return {
|
|
@@ -887,15 +895,11 @@ const makeChatsSocket = (config) => {
|
|
|
887
895
|
onWhatsApp,
|
|
888
896
|
fetchBlocklist,
|
|
889
897
|
fetchStatus,
|
|
890
|
-
fetchDisappearingDuration,
|
|
891
898
|
updateProfilePicture,
|
|
892
|
-
updateProfilePictureFull,
|
|
893
|
-
updateProfilePictureFull2,
|
|
894
899
|
removeProfilePicture,
|
|
895
900
|
updateProfileStatus,
|
|
896
901
|
updateProfileName,
|
|
897
902
|
updateBlockStatus,
|
|
898
|
-
updateCallPrivacy,
|
|
899
903
|
updateLastSeenPrivacy,
|
|
900
904
|
updateOnlinePrivacy,
|
|
901
905
|
updateProfilePicturePrivacy,
|
|
@@ -907,9 +911,6 @@ const makeChatsSocket = (config) => {
|
|
|
907
911
|
resyncAppState,
|
|
908
912
|
chatModify,
|
|
909
913
|
cleanDirtyBits,
|
|
910
|
-
addOrEditContact,
|
|
911
|
-
removeContact,
|
|
912
|
-
addLabel,
|
|
913
914
|
addChatLabel,
|
|
914
915
|
removeChatLabel,
|
|
915
916
|
addMessageLabel,
|