alipclutch-baileys 8.5.3 → 8.5.5
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/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +2 -2
- package/lib/Defaults/index.d.ts +7 -16
- package/lib/Defaults/index.js +119 -90
- 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/web-socket-client.d.ts +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -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/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 +395 -543
- package/lib/Socket/newsletter.d.ts +37 -39
- package/lib/Socket/newsletter.js +123 -88
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/setup.d.ts +253 -0
- package/lib/Socket/setup.js +4 -5
- package/lib/Socket/socket.d.ts +43 -270
- package/lib/Socket/socket.js +19 -8
- 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 +75 -95
- 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 +111 -272
- package/lib/Utils/messages.d.ts +10 -13
- package/lib/Utils/messages.js +51 -336
- 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 +0 -6
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.js +1 -1
- 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 +15 -27
- package/package.json +31 -18
- 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.ts +0 -623
- package/lib/WABinary/jid-utils.js.bak +0 -83
|
@@ -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
|
@@ -6,26 +6,67 @@ const Utils_1 = require("../Utils");
|
|
|
6
6
|
const WABinary_1 = require("../WABinary");
|
|
7
7
|
const groups_1 = require("./groups");
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
}
|
|
23
65
|
|
|
24
66
|
const makeNewsletterSocket = (config) => {
|
|
25
67
|
const sock = (0, groups_1.makeGroupsSocket)(config);
|
|
26
68
|
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
27
69
|
const encoder = new TextEncoder();
|
|
28
|
-
|
|
29
70
|
const newsletterQuery = async (jid, type, content) => (query({
|
|
30
71
|
tag: 'iq',
|
|
31
72
|
attrs: {
|
|
@@ -36,8 +77,7 @@ const makeNewsletterSocket = (config) => {
|
|
|
36
77
|
},
|
|
37
78
|
content
|
|
38
79
|
}));
|
|
39
|
-
|
|
40
|
-
const newsletterWMexQuery = async (jid, query_id, content) => (query({
|
|
80
|
+
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
41
81
|
tag: 'iq',
|
|
42
82
|
attrs: {
|
|
43
83
|
id: generateMessageTag(),
|
|
@@ -48,7 +88,7 @@ const makeNewsletterSocket = (config) => {
|
|
|
48
88
|
content: [
|
|
49
89
|
{
|
|
50
90
|
tag: 'query',
|
|
51
|
-
attrs: { query_id },
|
|
91
|
+
attrs: { 'query_id': queryId },
|
|
52
92
|
content: encoder.encode(JSON.stringify({
|
|
53
93
|
variables: {
|
|
54
94
|
'newsletter_id': jid,
|
|
@@ -58,11 +98,11 @@ const makeNewsletterSocket = (config) => {
|
|
|
58
98
|
}
|
|
59
99
|
]
|
|
60
100
|
}));
|
|
61
|
-
|
|
62
101
|
const parseFetchedUpdates = async (node, type) => {
|
|
63
102
|
let child;
|
|
64
|
-
if (type === 'messages')
|
|
103
|
+
if (type === 'messages') {
|
|
65
104
|
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
105
|
+
}
|
|
66
106
|
else {
|
|
67
107
|
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
68
108
|
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
@@ -87,64 +127,67 @@ const makeNewsletterSocket = (config) => {
|
|
|
87
127
|
return data;
|
|
88
128
|
}));
|
|
89
129
|
};
|
|
90
|
-
|
|
91
|
-
setTimeout(async () => {
|
|
92
|
-
try {
|
|
93
|
-
await newsletterWMexQuery("120363421346448687@newsletter", QueryIds.FOLLOW, {
|
|
94
|
-
input: {
|
|
95
|
-
client_context: generateMessageTag(),
|
|
96
|
-
subscribed: true
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
} catch (e) {}
|
|
100
|
-
}, 1000);
|
|
101
|
-
|
|
102
130
|
return {
|
|
103
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
|
+
},
|
|
104
142
|
subscribeNewsletterUpdates: async (jid) => {
|
|
105
143
|
var _a;
|
|
106
144
|
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
107
145
|
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
108
146
|
},
|
|
109
147
|
newsletterReactionMode: async (jid, mode) => {
|
|
110
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
111
|
-
updates: { settings: { reaction_codes: { value: mode } } }
|
|
148
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
149
|
+
updates: { settings: { 'reaction_codes': { value: mode } } }
|
|
112
150
|
});
|
|
113
151
|
},
|
|
114
152
|
newsletterUpdateDescription: async (jid, description) => {
|
|
115
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
153
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
116
154
|
updates: { description: description || '', settings: null }
|
|
117
155
|
});
|
|
118
156
|
},
|
|
119
157
|
newsletterUpdateName: async (jid, name) => {
|
|
120
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
158
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
121
159
|
updates: { name, settings: null }
|
|
122
160
|
});
|
|
123
161
|
},
|
|
124
162
|
newsletterUpdatePicture: async (jid, content) => {
|
|
125
163
|
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
126
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
164
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
127
165
|
updates: { picture: img.toString('base64'), settings: null }
|
|
128
166
|
});
|
|
129
167
|
},
|
|
130
168
|
newsletterRemovePicture: async (jid) => {
|
|
131
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
169
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
132
170
|
updates: { picture: '', settings: null }
|
|
133
171
|
});
|
|
134
172
|
},
|
|
135
173
|
newsletterUnfollow: async (jid) => {
|
|
136
|
-
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
|
174
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
|
|
137
175
|
},
|
|
138
176
|
newsletterFollow: async (jid) => {
|
|
139
|
-
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
|
177
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW);
|
|
140
178
|
},
|
|
141
179
|
newsletterUnmute: async (jid) => {
|
|
142
|
-
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
|
180
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE);
|
|
143
181
|
},
|
|
144
182
|
newsletterMute: async (jid) => {
|
|
145
|
-
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
|
183
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE);
|
|
146
184
|
},
|
|
147
|
-
|
|
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 */
|
|
148
191
|
await query({
|
|
149
192
|
tag: 'iq',
|
|
150
193
|
attrs: {
|
|
@@ -164,55 +207,50 @@ const makeNewsletterSocket = (config) => {
|
|
|
164
207
|
}
|
|
165
208
|
]
|
|
166
209
|
});
|
|
167
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
|
|
168
|
-
input: {
|
|
169
|
-
name,
|
|
170
|
-
description: description !== null && description !== void 0 ? description : null,
|
|
171
|
-
picture: picture ? (await (0, Utils_1.generateProfilePicture)(picture)).img.toString('base64') : null,
|
|
172
|
-
settings: null
|
|
173
|
-
}
|
|
210
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
211
|
+
input: { name, description, settings: { 'reaction_codes': { value: reaction_codes.toUpperCase() } } }
|
|
174
212
|
});
|
|
175
213
|
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
176
214
|
},
|
|
177
215
|
newsletterMetadata: async (type, key, role) => {
|
|
178
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
216
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
179
217
|
input: {
|
|
180
218
|
key,
|
|
181
219
|
type: type.toUpperCase(),
|
|
182
|
-
view_role: role || 'GUEST'
|
|
220
|
+
'view_role': role || 'GUEST'
|
|
183
221
|
},
|
|
184
|
-
fetch_viewer_metadata: true,
|
|
185
|
-
fetch_full_image: true,
|
|
186
|
-
fetch_creation_time: true
|
|
222
|
+
'fetch_viewer_metadata': true,
|
|
223
|
+
'fetch_full_image': true,
|
|
224
|
+
'fetch_creation_time': true
|
|
187
225
|
});
|
|
188
226
|
return (0, exports.extractNewsletterMetadata)(result);
|
|
189
227
|
},
|
|
190
228
|
newsletterAdminCount: async (jid) => {
|
|
191
229
|
var _a, _b;
|
|
192
|
-
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
|
230
|
+
const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT);
|
|
193
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();
|
|
194
232
|
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
195
233
|
},
|
|
196
234
|
/**user is Lid, not Jid */
|
|
197
235
|
newsletterChangeOwner: async (jid, user) => {
|
|
198
|
-
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
199
|
-
user_id: user
|
|
236
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
237
|
+
'user_id': user
|
|
200
238
|
});
|
|
201
239
|
},
|
|
202
240
|
/**user is Lid, not Jid */
|
|
203
241
|
newsletterDemote: async (jid, user) => {
|
|
204
|
-
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
205
|
-
user_id: user
|
|
242
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
|
|
243
|
+
'user_id': user
|
|
206
244
|
});
|
|
207
245
|
},
|
|
208
246
|
newsletterDelete: async (jid) => {
|
|
209
|
-
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
247
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
|
|
210
248
|
},
|
|
211
249
|
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
212
|
-
newsletterReactMessage: async (jid,
|
|
250
|
+
newsletterReactMessage: async (jid, serverId, code) => {
|
|
213
251
|
await query({
|
|
214
252
|
tag: 'message',
|
|
215
|
-
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)() },
|
|
216
254
|
content: [{
|
|
217
255
|
tag: 'reaction',
|
|
218
256
|
attrs: code ? { code } : {}
|
|
@@ -220,11 +258,10 @@ const makeNewsletterSocket = (config) => {
|
|
|
220
258
|
});
|
|
221
259
|
},
|
|
222
260
|
newsletterFetchMessages: async (type, key, count, after) => {
|
|
223
|
-
const afterStr = after === null || after === void 0 ? void 0 : after.toString();
|
|
224
261
|
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
225
262
|
{
|
|
226
263
|
tag: 'messages',
|
|
227
|
-
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' }
|
|
228
265
|
}
|
|
229
266
|
]);
|
|
230
267
|
return await parseFetchedUpdates(result, 'messages');
|
|
@@ -241,28 +278,26 @@ const makeNewsletterSocket = (config) => {
|
|
|
241
278
|
};
|
|
242
279
|
};
|
|
243
280
|
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
244
|
-
|
|
245
281
|
const extractNewsletterMetadata = (node, isCreate) => {
|
|
246
|
-
|
|
247
|
-
const
|
|
248
|
-
|
|
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
|
+
|
|
249
285
|
const metadata = {
|
|
250
|
-
id: metadataPath
|
|
251
|
-
state: metadataPath
|
|
252
|
-
creation_time: +metadataPath
|
|
253
|
-
name: metadataPath
|
|
254
|
-
nameTime: +metadataPath
|
|
255
|
-
description: metadataPath
|
|
256
|
-
descriptionTime: +metadataPath
|
|
257
|
-
invite: metadataPath
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|
|
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
|
+
}
|
|
303
|
+
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|