alipclutch-baileys 6.7.0 → 7.1.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/LICENSE +1 -1
- package/WAProto/index.js +77698 -117050
- package/engine-requirements.js +3 -3
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +6 -4
- package/lib/Defaults/index.js +118 -78
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -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/types.d.ts +1 -0
- package/lib/Socket/Client/types.js +1 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/Client/websocket.d.ts +1 -0
- package/lib/Socket/Client/websocket.js +1 -0
- 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/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +483 -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 +420 -382
- package/lib/Socket/newsletter.d.ts +37 -39
- package/lib/Socket/newsletter.js +124 -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 +38 -62
- package/lib/Socket/usync.d.ts +4 -3
- package/lib/Socket/usync.js +1 -0
- 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 +76 -96
- 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 -296
- package/lib/Utils/messages.d.ts +10 -13
- package/lib/Utils/messages.js +92 -325
- 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 -108
- 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 +6 -51
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.js +52 -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 -11
- package/lib/WABinary/jid-utils.js +5 -28
- 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 +1 -0
- package/lib/index.js +36 -43
- package/package.json +1 -1
- 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/WAProto/p.html +0 -1
- package/lib/Defaults/wileys-version.json +0 -3
- package/lib/WABinary/jid-utils.js.bak +0 -83
- /package/{README.MD → README.md} +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,
|
|
@@ -56,8 +100,9 @@ const makeNewsletterSocket = (config) => {
|
|
|
56
100
|
}));
|
|
57
101
|
const parseFetchedUpdates = async (node, type) => {
|
|
58
102
|
let child;
|
|
59
|
-
if (type === 'messages')
|
|
103
|
+
if (type === 'messages') {
|
|
60
104
|
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
105
|
+
}
|
|
61
106
|
else {
|
|
62
107
|
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
63
108
|
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
@@ -84,50 +129,65 @@ const makeNewsletterSocket = (config) => {
|
|
|
84
129
|
};
|
|
85
130
|
return {
|
|
86
131
|
...sock,
|
|
132
|
+
newsletterFetchAllSubscribe: async () => {
|
|
133
|
+
const list = await executeWMexQuery(
|
|
134
|
+
{},
|
|
135
|
+
'6388546374527196',
|
|
136
|
+
'xwa2_newsletter_subscribed',
|
|
137
|
+
query,
|
|
138
|
+
generateMessageTag
|
|
139
|
+
);
|
|
140
|
+
return list;
|
|
141
|
+
},
|
|
87
142
|
subscribeNewsletterUpdates: async (jid) => {
|
|
88
143
|
var _a;
|
|
89
144
|
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
90
145
|
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
91
146
|
},
|
|
92
147
|
newsletterReactionMode: async (jid, mode) => {
|
|
93
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
94
|
-
updates: { settings: { reaction_codes: { value: mode } } }
|
|
148
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
149
|
+
updates: { settings: { 'reaction_codes': { value: mode } } }
|
|
95
150
|
});
|
|
96
151
|
},
|
|
97
152
|
newsletterUpdateDescription: async (jid, description) => {
|
|
98
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
153
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
99
154
|
updates: { description: description || '', settings: null }
|
|
100
155
|
});
|
|
101
156
|
},
|
|
102
157
|
newsletterUpdateName: async (jid, name) => {
|
|
103
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
158
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
104
159
|
updates: { name, settings: null }
|
|
105
160
|
});
|
|
106
161
|
},
|
|
107
162
|
newsletterUpdatePicture: async (jid, content) => {
|
|
108
163
|
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
109
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
164
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
110
165
|
updates: { picture: img.toString('base64'), settings: null }
|
|
111
166
|
});
|
|
112
167
|
},
|
|
113
168
|
newsletterRemovePicture: async (jid) => {
|
|
114
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
169
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
115
170
|
updates: { picture: '', settings: null }
|
|
116
171
|
});
|
|
117
172
|
},
|
|
118
173
|
newsletterUnfollow: async (jid) => {
|
|
119
|
-
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
|
174
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
|
|
120
175
|
},
|
|
121
176
|
newsletterFollow: async (jid) => {
|
|
122
|
-
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
|
177
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW);
|
|
123
178
|
},
|
|
124
179
|
newsletterUnmute: async (jid) => {
|
|
125
|
-
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
|
180
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE);
|
|
126
181
|
},
|
|
127
182
|
newsletterMute: async (jid) => {
|
|
128
|
-
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
|
183
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE);
|
|
129
184
|
},
|
|
130
|
-
|
|
185
|
+
newsletterAction: async (jid, type) => {
|
|
186
|
+
await newsletterWMexQuery(jid, type.toUpperCase());
|
|
187
|
+
},
|
|
188
|
+
newsletterCreate: async (name, description, reaction_codes) => {
|
|
189
|
+
//TODO: Implement TOS system wide for Meta AI, communities, and here etc.
|
|
190
|
+
/**tos query */
|
|
131
191
|
await query({
|
|
132
192
|
tag: 'iq',
|
|
133
193
|
attrs: {
|
|
@@ -147,55 +207,50 @@ const makeNewsletterSocket = (config) => {
|
|
|
147
207
|
}
|
|
148
208
|
]
|
|
149
209
|
});
|
|
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
|
-
}
|
|
210
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
211
|
+
input: { name, description, settings: { 'reaction_codes': { value: reaction_codes.toUpperCase() } } }
|
|
157
212
|
});
|
|
158
213
|
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
159
214
|
},
|
|
160
215
|
newsletterMetadata: async (type, key, role) => {
|
|
161
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
216
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
162
217
|
input: {
|
|
163
218
|
key,
|
|
164
219
|
type: type.toUpperCase(),
|
|
165
|
-
view_role: role || 'GUEST'
|
|
220
|
+
'view_role': role || 'GUEST'
|
|
166
221
|
},
|
|
167
|
-
fetch_viewer_metadata: true,
|
|
168
|
-
fetch_full_image: true,
|
|
169
|
-
fetch_creation_time: true
|
|
222
|
+
'fetch_viewer_metadata': true,
|
|
223
|
+
'fetch_full_image': true,
|
|
224
|
+
'fetch_creation_time': true
|
|
170
225
|
});
|
|
171
226
|
return (0, exports.extractNewsletterMetadata)(result);
|
|
172
227
|
},
|
|
173
228
|
newsletterAdminCount: async (jid) => {
|
|
174
229
|
var _a, _b;
|
|
175
|
-
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
|
230
|
+
const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT);
|
|
176
231
|
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
232
|
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
178
233
|
},
|
|
179
234
|
/**user is Lid, not Jid */
|
|
180
235
|
newsletterChangeOwner: async (jid, user) => {
|
|
181
|
-
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
182
|
-
user_id: user
|
|
236
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
237
|
+
'user_id': user
|
|
183
238
|
});
|
|
184
239
|
},
|
|
185
240
|
/**user is Lid, not Jid */
|
|
186
241
|
newsletterDemote: async (jid, user) => {
|
|
187
|
-
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
188
|
-
user_id: user
|
|
242
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
|
|
243
|
+
'user_id': user
|
|
189
244
|
});
|
|
190
245
|
},
|
|
191
246
|
newsletterDelete: async (jid) => {
|
|
192
|
-
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
247
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
|
|
193
248
|
},
|
|
194
249
|
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
195
|
-
newsletterReactMessage: async (jid,
|
|
250
|
+
newsletterReactMessage: async (jid, serverId, code) => {
|
|
196
251
|
await query({
|
|
197
252
|
tag: 'message',
|
|
198
|
-
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: (0, Utils_1.generateMessageID)() },
|
|
253
|
+
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', 'server_id': serverId, id: (0, Utils_1.generateMessageID)() },
|
|
199
254
|
content: [{
|
|
200
255
|
tag: 'reaction',
|
|
201
256
|
attrs: code ? { code } : {}
|
|
@@ -203,11 +258,10 @@ const makeNewsletterSocket = (config) => {
|
|
|
203
258
|
});
|
|
204
259
|
},
|
|
205
260
|
newsletterFetchMessages: async (type, key, count, after) => {
|
|
206
|
-
const afterStr = after === null || after === void 0 ? void 0 : after.toString();
|
|
207
261
|
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
208
262
|
{
|
|
209
263
|
tag: 'messages',
|
|
210
|
-
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after:
|
|
264
|
+
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100' }
|
|
211
265
|
}
|
|
212
266
|
]);
|
|
213
267
|
return await parseFetchedUpdates(result, 'messages');
|
|
@@ -225,26 +279,25 @@ const makeNewsletterSocket = (config) => {
|
|
|
225
279
|
};
|
|
226
280
|
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
227
281
|
const extractNewsletterMetadata = (node, isCreate) => {
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
|
|
282
|
+
const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
283
|
+
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
|
|
284
|
+
|
|
231
285
|
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
|
-
};
|
|
286
|
+
id: metadataPath?.id,
|
|
287
|
+
state: metadataPath?.state?.type,
|
|
288
|
+
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
289
|
+
name: metadataPath?.thread_metadata?.name?.text,
|
|
290
|
+
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
291
|
+
description: metadataPath?.thread_metadata?.description?.text,
|
|
292
|
+
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
293
|
+
invite: metadataPath?.thread_metadata?.invite,
|
|
294
|
+
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
295
|
+
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
296
|
+
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
297
|
+
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
298
|
+
verification: metadataPath?.thread_metadata?.verification,
|
|
299
|
+
viewer_metadata: metadataPath?.viewer_metadata
|
|
300
|
+
}
|
|
301
|
+
return metadata
|
|
302
|
+
}
|
|
250
303
|
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|