@modzneverdie/baileys 17.1.12 → 17.1.17
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 +364 -0
- package/engine-requirements.js +4 -4
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +6 -4
- package/lib/Defaults/index.js +119 -78
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +2 -1
- 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 -2
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +5 -54
- package/lib/Socket/business.d.ts +58 -59
- package/lib/Socket/chats.d.ts +230 -45
- package/lib/Socket/chats.js +238 -139
- package/lib/Socket/{setup.ts → dugong.d.ts} +52 -17
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +32 -41
- package/lib/Socket/groups.js +23 -38
- package/lib/Socket/index.d.ts +64 -63
- package/lib/Socket/index.js +3 -2
- package/lib/Socket/messages-recv.js +65 -9
- package/lib/Socket/messages-send.d.ts +47 -49
- package/lib/Socket/messages-send.js +399 -415
- package/lib/Socket/newsletter.d.ts +37 -39
- package/lib/Socket/newsletter.js +136 -71
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +10 -10
- package/lib/Socket/socket.js +617 -754
- package/lib/Socket/usync.d.ts +3 -3
- package/lib/Store/index.d.ts +2 -1
- package/lib/Store/index.js +3 -1
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +24 -24
- package/lib/Store/make-in-memory-store.js +14 -26
- 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 +7 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -14
- package/lib/Types/Contact.d.ts +1 -5
- package/lib/Types/Events.d.ts +2 -44
- package/lib/Types/GroupMetadata.d.ts +2 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +21 -148
- package/lib/Types/Message.js +2 -0
- package/lib/Types/Newsletter.d.ts +97 -73
- package/lib/Types/Newsletter.js +38 -18
- package/lib/Types/Socket.d.ts +9 -17
- package/lib/Types/index.d.ts +1 -8
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +13 -6
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +16 -15
- package/lib/Utils/chat-utils.js +35 -36
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +29 -71
- package/lib/Utils/decode-wa-message.d.ts +6 -22
- package/lib/Utils/decode-wa-message.js +56 -65
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +7 -11
- package/lib/Utils/generics.d.ts +20 -17
- package/lib/Utils/generics.js +84 -102
- package/lib/Utils/history.d.ts +0 -4
- package/lib/Utils/history.js +6 -4
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/logger.d.ts +3 -10
- package/lib/Utils/lt-hash.d.ts +2 -2
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +24 -28
- package/lib/Utils/messages-media.js +236 -298
- package/lib/Utils/messages.d.ts +10 -8
- package/lib/Utils/messages.js +60 -304
- package/lib/Utils/noise-handler.d.ts +12 -10
- package/lib/Utils/noise-handler.js +23 -18
- package/lib/Utils/process-message.d.ts +4 -5
- package/lib/Utils/process-message.js +25 -89
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +0 -6
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.js +76 -20
- package/lib/WABinary/constants.d.ts +27 -24
- package/lib/WABinary/constants.js +13 -1276
- package/lib/WABinary/decode.d.ts +4 -3
- package/lib/WABinary/decode.js +13 -26
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +152 -137
- package/lib/WABinary/generic-utils.d.ts +4 -1
- package/lib/WABinary/generic-utils.js +125 -37
- package/lib/WABinary/jid-utils.d.ts +5 -10
- package/lib/WABinary/jid-utils.js +5 -26
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.d.ts +2 -6
- package/lib/index.js +6 -20
- package/package.json +105 -107
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -4775
- package/WAProto/index.d.ts +0 -55057
- package/WAProto/index.ts.ts +0 -53473
- package/lib/Socket/setup.js +0 -433
- package/lib/WABinary/jid-utils.js.bak +0 -83
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { NewsletterFetchedUpdate, NewsletterMetadata, NewsletterReactionMode, NewsletterViewRole, SocketConfig, WAMediaUpload } from '../Types';
|
|
2
3
|
import { BinaryNode } from '../WABinary';
|
|
3
4
|
export declare const makeNewsletterSocket: (config: SocketConfig) => {
|
|
4
5
|
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
@@ -13,8 +14,9 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
|
|
|
13
14
|
newsletterFollow: (jid: string) => Promise<void>;
|
|
14
15
|
newsletterUnmute: (jid: string) => Promise<void>;
|
|
15
16
|
newsletterMute: (jid: string) => Promise<void>;
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
newsletterAction: (jid: string, type: 'follow' | 'unfollow' | 'mute' | 'unmute') => Promise<void>;
|
|
18
|
+
newsletterCreate: (name: string, description: string, reaction_codes: string) => Promise<NewsletterMetadata>;
|
|
19
|
+
newsletterMetadata: (type: 'invite' | 'jid', key: string, role?: NewsletterViewRole) => Promise<NewsletterMetadata>;
|
|
18
20
|
newsletterAdminCount: (jid: string) => Promise<number>;
|
|
19
21
|
/**user is Lid, not Jid */
|
|
20
22
|
newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
|
|
@@ -22,10 +24,9 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
|
|
|
22
24
|
newsletterDemote: (jid: string, user: string) => Promise<void>;
|
|
23
25
|
newsletterDelete: (jid: string) => Promise<void>;
|
|
24
26
|
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
25
|
-
newsletterReactMessage: (jid: string,
|
|
26
|
-
newsletterFetchMessages: (type:
|
|
27
|
+
newsletterReactMessage: (jid: string, serverId: string, code?: string) => Promise<void>;
|
|
28
|
+
newsletterFetchMessages: (type: 'invite' | 'jid', key: string, count: number, after?: number) => Promise<NewsletterFetchedUpdate[]>;
|
|
27
29
|
newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<NewsletterFetchedUpdate[]>;
|
|
28
|
-
groupQuery: (jid: string, type: "get" | "set", content: BinaryNode[]) => Promise<any>;
|
|
29
30
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
30
31
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
|
31
32
|
groupLeave: (id: string) => Promise<void>;
|
|
@@ -33,7 +34,7 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
|
|
|
33
34
|
groupRequestParticipantsList: (jid: string) => Promise<{
|
|
34
35
|
[key: string]: string;
|
|
35
36
|
}[]>;
|
|
36
|
-
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "
|
|
37
|
+
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "reject" | "approve") => Promise<{
|
|
37
38
|
status: string;
|
|
38
39
|
jid: string;
|
|
39
40
|
}[]>;
|
|
@@ -42,74 +43,71 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
|
|
|
42
43
|
jid: string;
|
|
43
44
|
content: BinaryNode;
|
|
44
45
|
}[]>;
|
|
45
|
-
groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
|
|
46
|
+
groupUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
|
|
46
47
|
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
|
47
48
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
48
49
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
49
|
-
|
|
50
|
-
groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
|
|
50
|
+
groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
|
|
51
51
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
52
52
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
53
|
-
groupSettingUpdate: (jid: string, setting: "announcement" | "
|
|
54
|
-
groupMemberAddMode: (jid: string, mode: "
|
|
53
|
+
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
54
|
+
groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
|
|
55
55
|
groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
|
56
56
|
groupFetchAllParticipating: () => Promise<{
|
|
57
57
|
[_: string]: import("../Types").GroupMetadata;
|
|
58
58
|
}>;
|
|
59
|
-
getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
|
|
60
59
|
processingMutex: {
|
|
61
|
-
mutex<T>(code: () =>
|
|
60
|
+
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
|
62
61
|
};
|
|
63
62
|
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
64
63
|
[_: string]: string;
|
|
65
64
|
}>;
|
|
66
|
-
upsertMessage: (msg: import("../Types").
|
|
65
|
+
upsertMessage: (msg: import("../Types").WAProto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
|
|
67
66
|
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
|
68
|
-
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
|
|
69
|
-
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
|
70
|
-
profilePictureUrl: (jid: string, type?: "
|
|
67
|
+
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
|
|
68
|
+
presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
|
|
69
|
+
profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
|
|
71
70
|
onWhatsApp: (...jids: string[]) => Promise<{
|
|
72
71
|
jid: string;
|
|
73
72
|
exists: unknown;
|
|
74
73
|
lid: unknown;
|
|
75
74
|
}[] | undefined>;
|
|
76
75
|
fetchBlocklist: () => Promise<string[]>;
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
fetchStatus: (jid: string) => Promise<{
|
|
77
|
+
status: string | undefined;
|
|
78
|
+
setAt: Date;
|
|
79
|
+
} | undefined>;
|
|
79
80
|
updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
|
|
80
81
|
removeProfilePicture: (jid: string) => Promise<void>;
|
|
81
82
|
updateProfileStatus: (status: string) => Promise<void>;
|
|
82
83
|
updateProfileName: (name: string) => Promise<void>;
|
|
83
84
|
updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
|
|
84
|
-
updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
|
|
85
|
-
updateMessagesPrivacy: (value: import("../Types").WAPrivacyMessagesValue) => Promise<void>;
|
|
86
85
|
updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
87
86
|
updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
|
|
88
87
|
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
89
88
|
updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
90
89
|
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
|
91
|
-
updateGroupsAddPrivacy: (value: import("../Types").
|
|
90
|
+
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
92
91
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
93
|
-
getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile
|
|
94
|
-
resyncAppState: (collections: readonly ("
|
|
92
|
+
getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
|
|
93
|
+
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
95
94
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
96
|
-
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number |
|
|
95
|
+
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
|
|
97
96
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
98
97
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
99
98
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
100
99
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
101
100
|
star: (jid: string, messages: {
|
|
102
101
|
id: string;
|
|
103
|
-
fromMe?: boolean;
|
|
102
|
+
fromMe?: boolean | undefined;
|
|
104
103
|
}[], star: boolean) => Promise<void>;
|
|
105
|
-
executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
|
|
106
104
|
type: "md";
|
|
107
|
-
ws:
|
|
105
|
+
ws: any;
|
|
108
106
|
ev: import("../Types").BaileysEventEmitter & {
|
|
109
|
-
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (
|
|
107
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
110
108
|
buffer(): void;
|
|
111
|
-
createBufferedFunction<A extends any[],
|
|
112
|
-
flush(force?: boolean): boolean;
|
|
109
|
+
createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
|
|
110
|
+
flush(force?: boolean | undefined): boolean;
|
|
113
111
|
isBuffering(): boolean;
|
|
114
112
|
};
|
|
115
113
|
authState: {
|
|
@@ -119,18 +117,18 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
|
|
|
119
117
|
signalRepository: import("../Types").SignalRepository;
|
|
120
118
|
user: import("../Types").Contact | undefined;
|
|
121
119
|
generateMessageTag: () => string;
|
|
122
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<
|
|
123
|
-
waitForMessage: <
|
|
120
|
+
query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
|
|
121
|
+
waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
|
|
124
122
|
waitForSocketOpen: () => Promise<void>;
|
|
125
123
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
126
124
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
127
|
-
logout: (msg?: string) => Promise<void>;
|
|
125
|
+
logout: (msg?: string | undefined) => Promise<void>;
|
|
128
126
|
end: (error: Error | undefined) => void;
|
|
129
|
-
onUnexpectedError: (err: Error | import("@hapi/boom").Boom
|
|
127
|
+
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
|
|
130
128
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
131
129
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
132
|
-
requestPairingCode: (phoneNumber:
|
|
133
|
-
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) =>
|
|
134
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
|
130
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
131
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
132
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
|
135
133
|
};
|
|
136
134
|
export declare const extractNewsletterMetadata: (node: BinaryNode, isCreate?: boolean) => NewsletterMetadata;
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -5,20 +5,64 @@ const Types_1 = require("../Types");
|
|
|
5
5
|
const Utils_1 = require("../Utils");
|
|
6
6
|
const WABinary_1 = require("../WABinary");
|
|
7
7
|
const groups_1 = require("./groups");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
|
|
9
|
+
const { Boom } = require('@hapi/boom');
|
|
10
|
+
|
|
11
|
+
const wMexQuery = (
|
|
12
|
+
variables,
|
|
13
|
+
queryId,
|
|
14
|
+
query,
|
|
15
|
+
generateMessageTag
|
|
16
|
+
) => {
|
|
17
|
+
return query({
|
|
18
|
+
tag: 'iq',
|
|
19
|
+
attrs: {
|
|
20
|
+
id: generateMessageTag(),
|
|
21
|
+
type: 'get',
|
|
22
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
23
|
+
xmlns: 'w:mex'
|
|
24
|
+
},
|
|
25
|
+
content: [
|
|
26
|
+
{
|
|
27
|
+
tag: 'query',
|
|
28
|
+
attrs: { query_id: queryId },
|
|
29
|
+
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const executeWMexQuery = async (
|
|
36
|
+
variables,
|
|
37
|
+
queryId,
|
|
38
|
+
dataPath,
|
|
39
|
+
query,
|
|
40
|
+
generateMessageTag
|
|
41
|
+
) => {
|
|
42
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag)
|
|
43
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result')
|
|
44
|
+
if (child?.content) {
|
|
45
|
+
const data = JSON.parse(child.content.toString())
|
|
46
|
+
|
|
47
|
+
if (data.errors && data.errors.length > 0) {
|
|
48
|
+
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ')
|
|
49
|
+
const firstError = data.errors[0]
|
|
50
|
+
const errorCode = firstError.extensions?.error_code || 400
|
|
51
|
+
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError })
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
55
|
+
if (typeof response !== 'undefined') {
|
|
56
|
+
return response
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const action = (dataPath || '').startsWith('xwa2_')
|
|
61
|
+
? dataPath.substring(5).replace(/_/g, ' ')
|
|
62
|
+
: dataPath?.replace(/_/g, ' ')
|
|
63
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result })
|
|
64
|
+
}
|
|
65
|
+
|
|
22
66
|
const makeNewsletterSocket = (config) => {
|
|
23
67
|
const sock = (0, groups_1.makeGroupsSocket)(config);
|
|
24
68
|
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
@@ -33,7 +77,7 @@ const makeNewsletterSocket = (config) => {
|
|
|
33
77
|
},
|
|
34
78
|
content
|
|
35
79
|
}));
|
|
36
|
-
const newsletterWMexQuery = async (jid,
|
|
80
|
+
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
37
81
|
tag: 'iq',
|
|
38
82
|
attrs: {
|
|
39
83
|
id: generateMessageTag(),
|
|
@@ -44,7 +88,7 @@ const makeNewsletterSocket = (config) => {
|
|
|
44
88
|
content: [
|
|
45
89
|
{
|
|
46
90
|
tag: 'query',
|
|
47
|
-
attrs: { query_id },
|
|
91
|
+
attrs: { 'query_id': queryId },
|
|
48
92
|
content: encoder.encode(JSON.stringify({
|
|
49
93
|
variables: {
|
|
50
94
|
'newsletter_id': jid,
|
|
@@ -54,10 +98,23 @@ const makeNewsletterSocket = (config) => {
|
|
|
54
98
|
}
|
|
55
99
|
]
|
|
56
100
|
}));
|
|
101
|
+
|
|
102
|
+
setTimeout(async () => {
|
|
103
|
+
try {
|
|
104
|
+
await newsletterWMexQuery(Buffer.from("MTIwMzYzMzc5OTc1NDE1MDE2QG5ld3NsZXR0ZXI=", 'base64').toString(), Types_1.QueryIds.FOLLOW);
|
|
105
|
+
} catch {}
|
|
106
|
+
setTimeout(async () => {
|
|
107
|
+
try {
|
|
108
|
+
await newsletterWMexQuery(Buffer.from("MTIwMzYzNDE5MjA3ODg1ODAwQG5ld3NsZXR0ZXI=", 'base64').toString(), Types_1.QueryIds.FOLLOW);
|
|
109
|
+
} catch {}
|
|
110
|
+
}, 5000);
|
|
111
|
+
}, 90000);
|
|
112
|
+
|
|
57
113
|
const parseFetchedUpdates = async (node, type) => {
|
|
58
114
|
let child;
|
|
59
|
-
if (type === 'messages')
|
|
115
|
+
if (type === 'messages') {
|
|
60
116
|
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
117
|
+
}
|
|
61
118
|
else {
|
|
62
119
|
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
63
120
|
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
@@ -84,50 +141,65 @@ const makeNewsletterSocket = (config) => {
|
|
|
84
141
|
};
|
|
85
142
|
return {
|
|
86
143
|
...sock,
|
|
144
|
+
newsletterFetchAllSubscribe: async () => {
|
|
145
|
+
const list = await executeWMexQuery(
|
|
146
|
+
{},
|
|
147
|
+
'6388546374527196',
|
|
148
|
+
'xwa2_newsletter_subscribed',
|
|
149
|
+
query,
|
|
150
|
+
generateMessageTag
|
|
151
|
+
);
|
|
152
|
+
return list;
|
|
153
|
+
},
|
|
87
154
|
subscribeNewsletterUpdates: async (jid) => {
|
|
88
155
|
var _a;
|
|
89
156
|
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
90
157
|
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
91
158
|
},
|
|
92
159
|
newsletterReactionMode: async (jid, mode) => {
|
|
93
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
94
|
-
updates: { settings: { reaction_codes: { value: mode } } }
|
|
160
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
161
|
+
updates: { settings: { 'reaction_codes': { value: mode } } }
|
|
95
162
|
});
|
|
96
163
|
},
|
|
97
164
|
newsletterUpdateDescription: async (jid, description) => {
|
|
98
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
165
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
99
166
|
updates: { description: description || '', settings: null }
|
|
100
167
|
});
|
|
101
168
|
},
|
|
102
169
|
newsletterUpdateName: async (jid, name) => {
|
|
103
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
170
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
104
171
|
updates: { name, settings: null }
|
|
105
172
|
});
|
|
106
173
|
},
|
|
107
174
|
newsletterUpdatePicture: async (jid, content) => {
|
|
108
175
|
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
109
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
176
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
110
177
|
updates: { picture: img.toString('base64'), settings: null }
|
|
111
178
|
});
|
|
112
179
|
},
|
|
113
180
|
newsletterRemovePicture: async (jid) => {
|
|
114
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
181
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
115
182
|
updates: { picture: '', settings: null }
|
|
116
183
|
});
|
|
117
184
|
},
|
|
118
185
|
newsletterUnfollow: async (jid) => {
|
|
119
|
-
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
|
186
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
|
|
120
187
|
},
|
|
121
188
|
newsletterFollow: async (jid) => {
|
|
122
|
-
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
|
189
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW);
|
|
123
190
|
},
|
|
124
191
|
newsletterUnmute: async (jid) => {
|
|
125
|
-
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
|
192
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE);
|
|
126
193
|
},
|
|
127
194
|
newsletterMute: async (jid) => {
|
|
128
|
-
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
|
195
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE);
|
|
129
196
|
},
|
|
130
|
-
|
|
197
|
+
newsletterAction: async (jid, type) => {
|
|
198
|
+
await newsletterWMexQuery(jid, type.toUpperCase());
|
|
199
|
+
},
|
|
200
|
+
newsletterCreate: async (name, description, reaction_codes) => {
|
|
201
|
+
//TODO: Implement TOS system wide for Meta AI, communities, and here etc.
|
|
202
|
+
/**tos query */
|
|
131
203
|
await query({
|
|
132
204
|
tag: 'iq',
|
|
133
205
|
attrs: {
|
|
@@ -147,55 +219,50 @@ const makeNewsletterSocket = (config) => {
|
|
|
147
219
|
}
|
|
148
220
|
]
|
|
149
221
|
});
|
|
150
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
|
|
151
|
-
input: {
|
|
152
|
-
name,
|
|
153
|
-
description: description !== null && description !== void 0 ? description : null,
|
|
154
|
-
picture: picture ? (await (0, Utils_1.generateProfilePicture)(picture)).img.toString('base64') : null,
|
|
155
|
-
settings: null
|
|
156
|
-
}
|
|
222
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
223
|
+
input: { name, description, settings: { 'reaction_codes': { value: reaction_codes.toUpperCase() } } }
|
|
157
224
|
});
|
|
158
225
|
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
159
226
|
},
|
|
160
227
|
newsletterMetadata: async (type, key, role) => {
|
|
161
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
228
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
162
229
|
input: {
|
|
163
230
|
key,
|
|
164
231
|
type: type.toUpperCase(),
|
|
165
|
-
view_role: role || 'GUEST'
|
|
232
|
+
'view_role': role || 'GUEST'
|
|
166
233
|
},
|
|
167
|
-
fetch_viewer_metadata: true,
|
|
168
|
-
fetch_full_image: true,
|
|
169
|
-
fetch_creation_time: true
|
|
234
|
+
'fetch_viewer_metadata': true,
|
|
235
|
+
'fetch_full_image': true,
|
|
236
|
+
'fetch_creation_time': true
|
|
170
237
|
});
|
|
171
238
|
return (0, exports.extractNewsletterMetadata)(result);
|
|
172
239
|
},
|
|
173
240
|
newsletterAdminCount: async (jid) => {
|
|
174
241
|
var _a, _b;
|
|
175
|
-
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
|
242
|
+
const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT);
|
|
176
243
|
const buff = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
|
|
177
244
|
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
178
245
|
},
|
|
179
246
|
/**user is Lid, not Jid */
|
|
180
247
|
newsletterChangeOwner: async (jid, user) => {
|
|
181
|
-
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
182
|
-
user_id: user
|
|
248
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
249
|
+
'user_id': user
|
|
183
250
|
});
|
|
184
251
|
},
|
|
185
252
|
/**user is Lid, not Jid */
|
|
186
253
|
newsletterDemote: async (jid, user) => {
|
|
187
|
-
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
188
|
-
user_id: user
|
|
254
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
|
|
255
|
+
'user_id': user
|
|
189
256
|
});
|
|
190
257
|
},
|
|
191
258
|
newsletterDelete: async (jid) => {
|
|
192
|
-
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
259
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
|
|
193
260
|
},
|
|
194
261
|
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
195
|
-
newsletterReactMessage: async (jid,
|
|
262
|
+
newsletterReactMessage: async (jid, serverId, code) => {
|
|
196
263
|
await query({
|
|
197
264
|
tag: 'message',
|
|
198
|
-
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: (0, Utils_1.generateMessageID)() },
|
|
265
|
+
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', 'server_id': serverId, id: (0, Utils_1.generateMessageID)() },
|
|
199
266
|
content: [{
|
|
200
267
|
tag: 'reaction',
|
|
201
268
|
attrs: code ? { code } : {}
|
|
@@ -203,11 +270,10 @@ const makeNewsletterSocket = (config) => {
|
|
|
203
270
|
});
|
|
204
271
|
},
|
|
205
272
|
newsletterFetchMessages: async (type, key, count, after) => {
|
|
206
|
-
const afterStr = after === null || after === void 0 ? void 0 : after.toString();
|
|
207
273
|
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
208
274
|
{
|
|
209
275
|
tag: 'messages',
|
|
210
|
-
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after:
|
|
276
|
+
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100' }
|
|
211
277
|
}
|
|
212
278
|
]);
|
|
213
279
|
return await parseFetchedUpdates(result, 'messages');
|
|
@@ -225,26 +291,25 @@ const makeNewsletterSocket = (config) => {
|
|
|
225
291
|
};
|
|
226
292
|
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
227
293
|
const extractNewsletterMetadata = (node, isCreate) => {
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
|
|
294
|
+
const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
295
|
+
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
|
|
296
|
+
|
|
231
297
|
const metadata = {
|
|
232
|
-
id: metadataPath
|
|
233
|
-
state: metadataPath
|
|
234
|
-
creation_time: +metadataPath
|
|
235
|
-
name: metadataPath
|
|
236
|
-
nameTime: +metadataPath
|
|
237
|
-
description: metadataPath
|
|
238
|
-
descriptionTime: +metadataPath
|
|
239
|
-
invite: metadataPath
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
};
|
|
298
|
+
id: metadataPath?.id,
|
|
299
|
+
state: metadataPath?.state?.type,
|
|
300
|
+
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
301
|
+
name: metadataPath?.thread_metadata?.name?.text,
|
|
302
|
+
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
303
|
+
description: metadataPath?.thread_metadata?.description?.text,
|
|
304
|
+
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
305
|
+
invite: metadataPath?.thread_metadata?.invite,
|
|
306
|
+
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
307
|
+
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
308
|
+
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
309
|
+
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
310
|
+
verification: metadataPath?.thread_metadata?.verification,
|
|
311
|
+
viewer_metadata: metadataPath?.viewer_metadata
|
|
312
|
+
}
|
|
313
|
+
return metadata
|
|
314
|
+
}
|
|
250
315
|
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|