@genuxofficial/baileys 2.0.0 → 4.0.0
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/WAProto/WAProto.proto +4451 -0
- package/WAProto/index.d.ts +219 -2233
- package/WAProto/index.js +525 -6773
- package/WAProto/shizo.x +1 -0
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +236 -3
- package/lib/Defaults/index.js +24 -8
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/libsignal.js +9 -18
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +2 -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} +3 -3
- package/lib/Socket/business.d.ts +43 -43
- package/lib/Socket/chats.d.ts +17 -23
- package/lib/Socket/chats.js +9 -123
- package/lib/Socket/groups.d.ts +27 -32
- package/lib/Socket/groups.js +5 -18
- package/lib/Socket/index.d.ts +51 -49
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +41 -42
- package/lib/Socket/messages-recv.js +20 -39
- package/lib/Socket/messages-send.d.ts +33 -38
- package/lib/Socket/messages-send.js +16 -37
- package/lib/Socket/newsletter.d.ts +30 -35
- package/lib/Socket/newsletter.js +22 -26
- package/lib/Socket/registration.d.ts +271 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +10 -9
- package/lib/Socket/socket.js +19 -16
- package/lib/Socket/usync.d.ts +12 -10
- package/lib/Socket/usync.js +15 -10
- package/lib/Store/index.d.ts +2 -1
- package/lib/Store/index.js +3 -1
- package/lib/Store/make-in-memory-store.d.ts +1 -1
- package/lib/Store/make-in-memory-store.js +10 -8
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +8 -0
- package/lib/Types/Chat.d.ts +2 -12
- package/lib/Types/Contact.d.ts +1 -6
- package/lib/Types/GroupMetadata.d.ts +0 -7
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +8 -7
- package/lib/Types/Message.js +2 -0
- package/lib/Types/Newsletter.js +2 -2
- package/lib/Types/Socket.d.ts +6 -7
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.d.ts +1 -1
- package/lib/Utils/auth-utils.js +12 -5
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +13 -11
- package/lib/Utils/chat-utils.js +2 -28
- package/lib/Utils/crypto.d.ts +16 -14
- package/lib/Utils/crypto.js +22 -34
- package/lib/Utils/decode-wa-message.d.ts +2 -4
- package/lib/Utils/decode-wa-message.js +24 -160
- package/lib/Utils/event-buffer.js +6 -4
- package/lib/Utils/generics.d.ts +12 -40
- package/lib/Utils/generics.js +25 -103
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/lt-hash.d.ts +3 -3
- package/lib/Utils/lt-hash.js +45 -11
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +16 -26
- package/lib/Utils/messages-media.js +26 -102
- package/lib/Utils/messages.d.ts +8 -5
- package/lib/Utils/messages.js +15 -17
- package/lib/Utils/noise-handler.d.ts +8 -5
- package/lib/Utils/noise-handler.js +10 -5
- package/lib/Utils/process-message.js +2 -2
- package/lib/Utils/use-multi-file-auth-state.js +11 -48
- package/lib/Utils/validate-connection.d.ts +3 -2
- package/lib/Utils/validate-connection.js +44 -10
- package/lib/WABinary/constants.js +5 -5
- package/lib/WABinary/decode.d.ts +4 -2
- package/lib/WABinary/decode.js +7 -17
- package/lib/WABinary/encode.d.ts +3 -1
- package/lib/WABinary/encode.js +17 -40
- package/lib/WABinary/generic-utils.d.ts +3 -1
- package/lib/WABinary/generic-utils.js +2 -2
- package/lib/WABinary/jid-utils.d.ts +3 -8
- package/lib/WABinary/jid-utils.js +2 -23
- package/lib/WAM/BinaryInfo.d.ts +12 -2
- package/lib/WAM/constants.d.ts +2 -3
- package/lib/WAM/encode.d.ts +3 -1
- package/lib/WAM/encode.js +2 -2
- 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/USyncQuery.d.ts +0 -2
- package/lib/WAUSync/USyncQuery.js +13 -27
- package/lib/WAUSync/USyncUser.d.ts +0 -2
- package/lib/WAUSync/USyncUser.js +0 -4
- package/package.json +60 -55
- package/LICENSE +0 -21
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.MobileSocketClient = void 0;
|
4
|
+
const net_1 = require("net");
|
5
|
+
const abstract_socket_client_1 = require("./abstract-socket-client");
|
6
|
+
class MobileSocketClient extends abstract_socket_client_1.AbstractSocketClient {
|
7
|
+
constructor() {
|
8
|
+
super(...arguments);
|
9
|
+
this.socket = null;
|
10
|
+
}
|
11
|
+
get isOpen() {
|
12
|
+
var _a;
|
13
|
+
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'open';
|
14
|
+
}
|
15
|
+
get isClosed() {
|
16
|
+
var _a;
|
17
|
+
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'closed';
|
18
|
+
}
|
19
|
+
get isClosing() {
|
20
|
+
var _a;
|
21
|
+
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'closed';
|
22
|
+
}
|
23
|
+
get isConnecting() {
|
24
|
+
var _a;
|
25
|
+
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'opening';
|
26
|
+
}
|
27
|
+
async connect() {
|
28
|
+
var _a;
|
29
|
+
if (this.socket) {
|
30
|
+
return;
|
31
|
+
}
|
32
|
+
if (this.config.agent) {
|
33
|
+
throw new Error('There are not support for proxy agent for mobile connection');
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
this.socket = (0, net_1.connect)({
|
37
|
+
host: this.url.hostname,
|
38
|
+
port: Number(this.url.port) || 443
|
39
|
+
});
|
40
|
+
}
|
41
|
+
this.socket.setMaxListeners(0);
|
42
|
+
const events = ['close', 'connect', 'data', 'drain', 'end', 'error', 'lookup', 'ready', 'timeout'];
|
43
|
+
for (const event of events) {
|
44
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.on(event, (...args) => this.emit(event, ...args));
|
45
|
+
}
|
46
|
+
this.socket.on('data', (...args) => this.emit('message', ...args));
|
47
|
+
this.socket.on('ready', (...args) => this.emit('open', ...args));
|
48
|
+
}
|
49
|
+
async close() {
|
50
|
+
if (!this.socket) {
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
return new Promise(resolve => {
|
54
|
+
this.socket.end(resolve);
|
55
|
+
this.socket = null;
|
56
|
+
});
|
57
|
+
}
|
58
|
+
send(str, cb) {
|
59
|
+
if (this.socket === null) {
|
60
|
+
return false;
|
61
|
+
}
|
62
|
+
return this.socket.write(str, undefined, cb);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
exports.MobileSocketClient = MobileSocketClient;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import WebSocket from 'ws';
|
2
|
-
import { AbstractSocketClient } from './
|
2
|
+
import { AbstractSocketClient } from './abstract-socket-client';
|
3
3
|
export declare class WebSocketClient extends AbstractSocketClient {
|
4
4
|
protected socket: WebSocket | null;
|
5
5
|
get isOpen(): boolean;
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.WebSocketClient = void 0;
|
7
7
|
const ws_1 = __importDefault(require("ws"));
|
8
8
|
const Defaults_1 = require("../../Defaults");
|
9
|
-
const
|
10
|
-
class WebSocketClient extends
|
9
|
+
const abstract_socket_client_1 = require("./abstract-socket-client");
|
10
|
+
class WebSocketClient extends abstract_socket_client_1.AbstractSocketClient {
|
11
11
|
constructor() {
|
12
12
|
super(...arguments);
|
13
13
|
this.socket = null;
|
@@ -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
@@ -1,3 +1,6 @@
|
|
1
|
+
/// <reference types="long" />
|
2
|
+
/// <reference types="node" />
|
3
|
+
/// <reference types="node" />
|
1
4
|
import { GetCatalogOptions, ProductCreate, ProductUpdate, SocketConfig } from '../Types';
|
2
5
|
import { BinaryNode } from '../WABinary';
|
3
6
|
export declare const makeBusinessSocket: (config: SocketConfig) => {
|
@@ -15,7 +18,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
15
18
|
deleted: number;
|
16
19
|
}>;
|
17
20
|
productUpdate: (productId: string, update: ProductUpdate) => Promise<import("../Types").Product>;
|
18
|
-
sendMessageAck: ({ tag, attrs, content }: BinaryNode, errorCode?: number) => Promise<void>;
|
21
|
+
sendMessageAck: ({ tag, attrs, content }: BinaryNode, errorCode?: number | undefined) => Promise<void>;
|
19
22
|
sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
|
20
23
|
rejectCall: (callId: string, callFrom: string) => Promise<void>;
|
21
24
|
offerCall: (toJid: string, isVideo?: boolean) => Promise<{
|
@@ -23,14 +26,16 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
23
26
|
toJid: string;
|
24
27
|
isVideo: boolean;
|
25
28
|
}>;
|
26
|
-
fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | Long) => Promise<string>;
|
29
|
+
fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | import("long").Long) => Promise<string>;
|
27
30
|
requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
|
28
|
-
getPrivacyTokens: (jids: string[]) => Promise<
|
31
|
+
getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
|
29
32
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
30
33
|
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
|
31
34
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
32
35
|
sendReceipts: (keys: import("../Types").WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
33
|
-
getButtonArgs: (message: import("../Types").WAProto.IMessage) =>
|
36
|
+
getButtonArgs: (message: import("../Types").WAProto.IMessage) => {
|
37
|
+
[key: string]: string;
|
38
|
+
};
|
34
39
|
readMessages: (keys: import("../Types").WAMessageKey[]) => Promise<void>;
|
35
40
|
refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
|
36
41
|
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
@@ -38,7 +43,9 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
38
43
|
[_: string]: string;
|
39
44
|
}>;
|
40
45
|
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
|
41
|
-
createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?:
|
46
|
+
createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: {
|
47
|
+
[key: string]: string;
|
48
|
+
} | undefined) => Promise<{
|
42
49
|
nodes: BinaryNode[];
|
43
50
|
shouldIncludeDeviceIdentity: boolean;
|
44
51
|
}>;
|
@@ -49,7 +56,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
49
56
|
duration: string;
|
50
57
|
}>;
|
51
58
|
newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
|
52
|
-
newsletterUpdateDescription: (jid: string, description?: string) => Promise<void>;
|
59
|
+
newsletterUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
|
53
60
|
newsletterUpdateName: (jid: string, name: string) => Promise<void>;
|
54
61
|
newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
55
62
|
newsletterRemovePicture: (jid: string) => Promise<void>;
|
@@ -57,15 +64,15 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
57
64
|
newsletterFollow: (jid: string) => Promise<void>;
|
58
65
|
newsletterUnmute: (jid: string) => Promise<void>;
|
59
66
|
newsletterMute: (jid: string) => Promise<void>;
|
60
|
-
newsletterCreate: (name: string, description
|
61
|
-
newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole) => Promise<import("../Types").NewsletterMetadata>;
|
67
|
+
newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
|
68
|
+
newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
|
62
69
|
newsletterAdminCount: (jid: string) => Promise<number>;
|
63
70
|
newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
|
64
71
|
newsletterDemote: (jid: string, user: string) => Promise<void>;
|
65
72
|
newsletterDelete: (jid: string) => Promise<void>;
|
66
|
-
newsletterReactMessage: (jid: string, server_id: string, code?: string) => Promise<void>;
|
67
|
-
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
68
|
-
newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
73
|
+
newsletterReactMessage: (jid: string, server_id: string, code?: string | undefined) => Promise<void>;
|
74
|
+
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
75
|
+
newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
69
76
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
70
77
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
71
78
|
groupLeave: (id: string) => Promise<void>;
|
@@ -73,7 +80,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
73
80
|
groupRequestParticipantsList: (jid: string) => Promise<{
|
74
81
|
[key: string]: string;
|
75
82
|
}[]>;
|
76
|
-
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "
|
83
|
+
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "reject" | "approve") => Promise<{
|
77
84
|
status: string;
|
78
85
|
jid: string;
|
79
86
|
}[]>;
|
@@ -82,40 +89,36 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
82
89
|
jid: string;
|
83
90
|
content: BinaryNode;
|
84
91
|
}[]>;
|
85
|
-
groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
|
92
|
+
groupUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
|
86
93
|
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
87
94
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
88
95
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
89
96
|
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
90
|
-
groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<
|
97
|
+
groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
|
91
98
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
92
99
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
93
|
-
groupSettingUpdate: (jid: string, setting: "announcement" | "
|
94
|
-
groupMemberAddMode: (jid: string, mode: "
|
100
|
+
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
101
|
+
groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
|
95
102
|
groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
96
103
|
groupFetchAllParticipating: () => Promise<{
|
97
104
|
[_: string]: import("../Types").GroupMetadata;
|
98
105
|
}>;
|
99
|
-
getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
|
100
106
|
processingMutex: {
|
101
|
-
mutex<T>(code: () =>
|
107
|
+
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
102
108
|
};
|
103
109
|
upsertMessage: (msg: import("../Types").WAProto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
|
104
110
|
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
105
|
-
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
|
106
|
-
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
107
|
-
profilePictureUrl: (jid: string, type?: "
|
111
|
+
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
|
112
|
+
presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
|
113
|
+
profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
|
108
114
|
onWhatsApp: (...jids: string[]) => Promise<{
|
109
115
|
jid: string;
|
110
116
|
exists: unknown;
|
111
|
-
lid: unknown;
|
112
117
|
}[] | undefined>;
|
113
118
|
fetchBlocklist: () => Promise<string[]>;
|
114
|
-
fetchDisappearingDuration: (...jids: string[]) => Promise<import("
|
115
|
-
fetchStatus: (...jids: string[]) => Promise<import("
|
119
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>;
|
120
|
+
fetchStatus: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>;
|
116
121
|
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
117
|
-
updateProfilePictureFull: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
118
|
-
updateProfilePictureFull2: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
119
122
|
removeProfilePicture: (jid: string) => Promise<void>;
|
120
123
|
updateProfileStatus: (status: string) => Promise<void>;
|
121
124
|
updateProfileName: (name: string) => Promise<void>;
|
@@ -129,29 +132,26 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
129
132
|
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
130
133
|
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
|
131
134
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
132
|
-
getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile
|
135
|
+
getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
|
133
136
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
134
137
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
135
|
-
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number |
|
136
|
-
addOrEditContact: (jid: string, contact: import("../Types").ContactAction) => Promise<void>;
|
137
|
-
removeContact: (jid: string) => Promise<void>;
|
138
|
-
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
138
|
+
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
|
139
139
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
140
140
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
141
141
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
142
142
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
143
143
|
star: (jid: string, messages: {
|
144
144
|
id: string;
|
145
|
-
fromMe?: boolean;
|
145
|
+
fromMe?: boolean | undefined;
|
146
146
|
}[], star: boolean) => Promise<void>;
|
147
|
-
executeUSyncQuery: (usyncQuery: import("
|
147
|
+
executeUSyncQuery: (usyncQuery: import("../index").USyncQuery) => Promise<import("../index").USyncQueryResult | undefined>;
|
148
148
|
type: "md";
|
149
|
-
ws:
|
149
|
+
ws: any;
|
150
150
|
ev: import("../Types").BaileysEventEmitter & {
|
151
|
-
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (
|
151
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
152
152
|
buffer(): void;
|
153
|
-
createBufferedFunction<A extends any[],
|
154
|
-
flush(force?: boolean): boolean;
|
153
|
+
createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
|
154
|
+
flush(force?: boolean | undefined): boolean;
|
155
155
|
isBuffering(): boolean;
|
156
156
|
};
|
157
157
|
authState: {
|
@@ -161,17 +161,17 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
161
161
|
signalRepository: import("../Types").SignalRepository;
|
162
162
|
user: import("../Types").Contact | undefined;
|
163
163
|
generateMessageTag: () => string;
|
164
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<
|
165
|
-
waitForMessage: <
|
164
|
+
query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
|
165
|
+
waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
|
166
166
|
waitForSocketOpen: () => Promise<void>;
|
167
167
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
168
168
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
169
|
-
logout: (msg?: string) => Promise<void>;
|
169
|
+
logout: (msg?: string | undefined) => Promise<void>;
|
170
170
|
end: (error: Error | undefined) => void;
|
171
|
-
onUnexpectedError: (err: Error | import("@hapi/boom").Boom
|
171
|
+
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
|
172
172
|
uploadPreKeys: (count?: number) => Promise<void>;
|
173
173
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
174
174
|
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
175
|
-
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
176
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
175
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
|
176
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
177
177
|
};
|
package/lib/Socket/chats.d.ts
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
1
3
|
import { Boom } from '@hapi/boom';
|
2
4
|
import { proto } from '../../WAProto';
|
3
|
-
import {
|
4
|
-
import { LabelActionBody } from '../Types/Label';
|
5
|
+
import { ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAPatchCreate, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyMessagesValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types';
|
5
6
|
import { BinaryNode } from '../WABinary';
|
6
7
|
import { USyncQuery } from '../WAUSync';
|
7
8
|
export declare const makeChatsSocket: (config: SocketConfig) => {
|
8
|
-
getBotListV2: () => Promise<BotListInfo[]>;
|
9
9
|
processingMutex: {
|
10
|
-
mutex<T>(code: () =>
|
10
|
+
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
11
11
|
};
|
12
12
|
fetchPrivacySettings: (force?: boolean) => Promise<{
|
13
13
|
[_: string]: string;
|
@@ -16,22 +16,19 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
16
16
|
appPatch: (patchCreate: WAPatchCreate) => Promise<void>;
|
17
17
|
sendPresenceUpdate: (type: WAPresence, toJid?: string) => Promise<void>;
|
18
18
|
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
19
|
-
profilePictureUrl: (jid: string, type?:
|
19
|
+
profilePictureUrl: (jid: string, type?: 'preview' | 'image', timeoutMs?: number) => Promise<string | undefined>;
|
20
20
|
onWhatsApp: (...jids: string[]) => Promise<{
|
21
21
|
jid: string;
|
22
22
|
exists: unknown;
|
23
|
-
lid: unknown;
|
24
23
|
}[] | undefined>;
|
25
24
|
fetchBlocklist: () => Promise<string[]>;
|
26
25
|
fetchDisappearingDuration: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
|
27
26
|
fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
|
28
27
|
updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
|
29
|
-
updateProfilePictureFull: (jid: string, content: WAMediaUpload) => Promise<void>;
|
30
|
-
updateProfilePictureFull2: (jid: string, content: WAMediaUpload) => Promise<void>;
|
31
28
|
removeProfilePicture: (jid: string) => Promise<void>;
|
32
29
|
updateProfileStatus: (status: string) => Promise<void>;
|
33
30
|
updateProfileName: (name: string) => Promise<void>;
|
34
|
-
updateBlockStatus: (jid: string, action:
|
31
|
+
updateBlockStatus: (jid: string, action: 'block' | 'unblock') => Promise<void>;
|
35
32
|
updateCallPrivacy: (value: WAPrivacyCallValue) => Promise<void>;
|
36
33
|
updateMessagesPrivacy: (value: WAPrivacyMessagesValue) => Promise<void>;
|
37
34
|
updateLastSeenPrivacy: (value: WAPrivacyValue) => Promise<void>;
|
@@ -44,10 +41,7 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
44
41
|
getBusinessProfile: (jid: string) => Promise<WABusinessProfile | void>;
|
45
42
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
46
43
|
chatModify: (mod: ChatModification, jid: string) => Promise<void>;
|
47
|
-
cleanDirtyBits: (type:
|
48
|
-
addOrEditContact: (jid: string, contact: ContactAction) => Promise<void>;
|
49
|
-
removeContact: (jid: string) => Promise<void>;
|
50
|
-
addLabel: (jid: string, labels: LabelActionBody) => Promise<void>;
|
44
|
+
cleanDirtyBits: (type: 'account_sync' | 'groups', fromTimestamp?: number | string) => Promise<void>;
|
51
45
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
52
46
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
53
47
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
@@ -58,12 +52,12 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
58
52
|
}[], star: boolean) => Promise<void>;
|
59
53
|
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
|
60
54
|
type: "md";
|
61
|
-
ws:
|
55
|
+
ws: any;
|
62
56
|
ev: import("../Types").BaileysEventEmitter & {
|
63
|
-
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (
|
57
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
64
58
|
buffer(): void;
|
65
|
-
createBufferedFunction<A extends any[],
|
66
|
-
flush(force?: boolean): boolean;
|
59
|
+
createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
|
60
|
+
flush(force?: boolean | undefined): boolean;
|
67
61
|
isBuffering(): boolean;
|
68
62
|
};
|
69
63
|
authState: {
|
@@ -73,17 +67,17 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
73
67
|
signalRepository: import("../Types").SignalRepository;
|
74
68
|
user: import("../Types").Contact | undefined;
|
75
69
|
generateMessageTag: () => string;
|
76
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<
|
77
|
-
waitForMessage: <
|
70
|
+
query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
|
71
|
+
waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
|
78
72
|
waitForSocketOpen: () => Promise<void>;
|
79
73
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
80
74
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
81
|
-
logout: (msg?: string) => Promise<void>;
|
75
|
+
logout: (msg?: string | undefined) => Promise<void>;
|
82
76
|
end: (error: Error | undefined) => void;
|
83
|
-
onUnexpectedError: (err: Error | Boom
|
77
|
+
onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
|
84
78
|
uploadPreKeys: (count?: number) => Promise<void>;
|
85
79
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
86
80
|
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
87
|
-
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
88
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
81
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
|
82
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
89
83
|
};
|
package/lib/Socket/chats.js
CHANGED
@@ -26,7 +26,7 @@ const makeChatsSocket = (config) => {
|
|
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
28
|
const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
|
29
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
29
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
30
30
|
useClones: false
|
31
31
|
});
|
32
32
|
if (!config.placeholderResendCache) {
|
@@ -115,46 +115,16 @@ const makeChatsSocket = (config) => {
|
|
115
115
|
}]
|
116
116
|
});
|
117
117
|
};
|
118
|
-
const getBotListV2 = async () => {
|
119
|
-
const resp = await query({
|
120
|
-
tag: 'iq',
|
121
|
-
attrs: {
|
122
|
-
xmlns: 'bot',
|
123
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
124
|
-
type: 'get'
|
125
|
-
},
|
126
|
-
content: [{
|
127
|
-
tag: 'bot',
|
128
|
-
attrs: {
|
129
|
-
v: '2'
|
130
|
-
}
|
131
|
-
}]
|
132
|
-
});
|
133
|
-
const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
|
134
|
-
const botList = [];
|
135
|
-
for (const section of (0, WABinary_1.getBinaryNodeChildren)(botNode, 'section')) {
|
136
|
-
if (section.attrs.type === 'all') {
|
137
|
-
for (const bot of (0, WABinary_1.getBinaryNodeChildren)(section, 'bot')) {
|
138
|
-
botList.push({
|
139
|
-
jid: bot.attrs.jid,
|
140
|
-
personaId: bot.attrs['persona_id']
|
141
|
-
});
|
142
|
-
}
|
143
|
-
}
|
144
|
-
}
|
145
|
-
return botList;
|
146
|
-
};
|
147
118
|
const onWhatsApp = async (...jids) => {
|
148
119
|
const usyncQuery = new WAUSync_1.USyncQuery()
|
149
|
-
.withContactProtocol()
|
150
|
-
.withLIDProtocol();
|
120
|
+
.withContactProtocol();
|
151
121
|
for (const jid of jids) {
|
152
122
|
const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
|
153
123
|
usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
|
154
124
|
}
|
155
125
|
const results = await sock.executeUSyncQuery(usyncQuery);
|
156
126
|
if (results) {
|
157
|
-
return results.list.filter((a) => !!a.contact).map(({ contact, id
|
127
|
+
return results.list.filter((a) => !!a.contact).map(({ contact, id }) => ({ jid: id, exists: contact }));
|
158
128
|
}
|
159
129
|
};
|
160
130
|
const fetchStatus = async (...jids) => {
|
@@ -206,59 +176,6 @@ const makeChatsSocket = (config) => {
|
|
206
176
|
]
|
207
177
|
});
|
208
178
|
};
|
209
|
-
/** update the profile picture for yourself or a group as Full */
|
210
|
-
const updateProfilePictureFull = async (jid, content) => {
|
211
|
-
let targetJid;
|
212
|
-
if (!jid) {
|
213
|
-
throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
214
|
-
}
|
215
|
-
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
216
|
-
targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
|
217
|
-
}
|
218
|
-
const { img } = await (0, Utils_1.generateProfilePictureFull)(content);
|
219
|
-
await query({
|
220
|
-
tag: 'iq',
|
221
|
-
attrs: {
|
222
|
-
target: targetJid,
|
223
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
224
|
-
type: 'set',
|
225
|
-
xmlns: 'w:profile:picture'
|
226
|
-
},
|
227
|
-
content: [
|
228
|
-
{
|
229
|
-
tag: 'picture',
|
230
|
-
attrs: { type: 'image' },
|
231
|
-
content: img
|
232
|
-
}
|
233
|
-
]
|
234
|
-
});
|
235
|
-
};
|
236
|
-
const updateProfilePictureFull2 = async (jid, content) => {
|
237
|
-
let targetJid;
|
238
|
-
if (!jid) {
|
239
|
-
throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
|
240
|
-
}
|
241
|
-
if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
|
242
|
-
targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
|
243
|
-
}
|
244
|
-
const { preview } = await (0, Utils_1.generateProfilePictureFP)(content);
|
245
|
-
await query({
|
246
|
-
tag: 'iq',
|
247
|
-
attrs: {
|
248
|
-
target: targetJid,
|
249
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
250
|
-
type: 'set',
|
251
|
-
xmlns: 'w:profile:picture'
|
252
|
-
},
|
253
|
-
content: [
|
254
|
-
{
|
255
|
-
tag: 'picture',
|
256
|
-
attrs: { type: 'image' },
|
257
|
-
content: preview
|
258
|
-
}
|
259
|
-
]
|
260
|
-
});
|
261
|
-
};
|
262
179
|
/** remove the profile picture for yourself or a group */
|
263
180
|
const removeProfilePicture = async (jid) => {
|
264
181
|
let targetJid;
|
@@ -725,32 +642,6 @@ const makeChatsSocket = (config) => {
|
|
725
642
|
}
|
726
643
|
}, jid);
|
727
644
|
};
|
728
|
-
/**
|
729
|
-
* Add or Edit Contact
|
730
|
-
*/
|
731
|
-
const addOrEditContact = (jid, contact) => {
|
732
|
-
return chatModify({
|
733
|
-
contact
|
734
|
-
}, jid);
|
735
|
-
};
|
736
|
-
/**
|
737
|
-
* Remove Contact
|
738
|
-
*/
|
739
|
-
const removeContact = (jid) => {
|
740
|
-
return chatModify({
|
741
|
-
contact: null
|
742
|
-
}, jid);
|
743
|
-
};
|
744
|
-
/**
|
745
|
-
* Adds label
|
746
|
-
*/
|
747
|
-
const addLabel = (jid, labels) => {
|
748
|
-
return chatModify({
|
749
|
-
addLabel: {
|
750
|
-
...labels
|
751
|
-
}
|
752
|
-
}, jid);
|
753
|
-
};
|
754
645
|
/**
|
755
646
|
* Adds label for the chats
|
756
647
|
*/
|
@@ -898,18 +789,18 @@ const makeChatsSocket = (config) => {
|
|
898
789
|
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
899
790
|
.catch(error => onUnexpectedError(error, 'presence update requests'));
|
900
791
|
}
|
901
|
-
if (receivedPendingNotifications
|
792
|
+
if (receivedPendingNotifications) {
|
793
|
+
// if we don't have the app state key
|
902
794
|
// we keep buffering events until we finally have
|
903
795
|
// the key and can sync the messages
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
796
|
+
if (!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId) && !config.mobile) {
|
797
|
+
ev.buffer();
|
798
|
+
needToFlushWithAppStateSync = true;
|
799
|
+
}
|
908
800
|
}
|
909
801
|
});
|
910
802
|
return {
|
911
803
|
...sock,
|
912
|
-
getBotListV2,
|
913
804
|
processingMutex,
|
914
805
|
fetchPrivacySettings,
|
915
806
|
upsertMessage,
|
@@ -922,8 +813,6 @@ const makeChatsSocket = (config) => {
|
|
922
813
|
fetchDisappearingDuration,
|
923
814
|
fetchStatus,
|
924
815
|
updateProfilePicture,
|
925
|
-
updateProfilePictureFull,
|
926
|
-
updateProfilePictureFull2,
|
927
816
|
removeProfilePicture,
|
928
817
|
updateProfileStatus,
|
929
818
|
updateProfileName,
|
@@ -941,9 +830,6 @@ const makeChatsSocket = (config) => {
|
|
941
830
|
resyncAppState,
|
942
831
|
chatModify,
|
943
832
|
cleanDirtyBits,
|
944
|
-
addOrEditContact,
|
945
|
-
removeContact,
|
946
|
-
addLabel,
|
947
833
|
addChatLabel,
|
948
834
|
removeChatLabel,
|
949
835
|
addMessageLabel,
|