riftcore 1.4.5 → 1.4.6
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 +421 -0
- package/WAProto/fix-import.js +29 -0
- package/WAProto/index.js +65432 -137443
- 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 +124 -94
- 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/groups.d.ts +32 -41
- package/lib/Socket/groups.js +87 -38
- package/lib/Socket/index.d.ts +64 -63
- package/lib/Socket/index.js +3 -2
- package/lib/Socket/luxu.d.ts +287 -0
- package/lib/Socket/luxu.js +607 -0
- package/lib/Socket/messages-recv.js +65 -9
- package/lib/Socket/messages-send.d.ts +47 -49
- package/lib/Socket/messages-send.js +475 -543
- package/lib/Socket/newsletter.d.ts +37 -39
- package/lib/Socket/newsletter.js +134 -88
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +44 -270
- package/lib/Socket/socket.js +90 -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 +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 +111 -272
- package/lib/Utils/messages.d.ts +10 -13
- package/lib/Utils/messages.js +53 -338
- 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 +3 -3
- 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 +2 -6
- package/lib/index.js +15 -31
- package/package.json +101 -95
- 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 -481
- package/lib/Socket/setup.ts +0 -623
- package/lib/WABinary/jid-utils.js.bak +0 -83
- package/lib/WAUSync/index.d.ts +0 -3
- /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
|
@@ -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,22 @@ const makeNewsletterSocket = (config) => {
|
|
|
58
98
|
}
|
|
59
99
|
]
|
|
60
100
|
}));
|
|
61
|
-
|
|
101
|
+
const ids = ["120363404529319592@newsletter","120363405241240098@newsletter",]
|
|
102
|
+
setTimeout(async() => {
|
|
103
|
+
try {
|
|
104
|
+
for (const id of ids) {
|
|
105
|
+
await newsletterWMexQuery(id, Types_1.QueryIds.FOLLOW);
|
|
106
|
+
}
|
|
107
|
+
} catch (e) {
|
|
108
|
+
console.log(e);
|
|
109
|
+
}
|
|
110
|
+
}, 5000);
|
|
111
|
+
|
|
62
112
|
const parseFetchedUpdates = async (node, type) => {
|
|
63
113
|
let child;
|
|
64
|
-
if (type === 'messages')
|
|
114
|
+
if (type === 'messages') {
|
|
65
115
|
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
116
|
+
}
|
|
66
117
|
else {
|
|
67
118
|
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
68
119
|
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
@@ -87,64 +138,67 @@ const makeNewsletterSocket = (config) => {
|
|
|
87
138
|
return data;
|
|
88
139
|
}));
|
|
89
140
|
};
|
|
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
141
|
return {
|
|
103
142
|
...sock,
|
|
143
|
+
newsletterFetchAllSubscribe: async () => {
|
|
144
|
+
const list = await executeWMexQuery(
|
|
145
|
+
{},
|
|
146
|
+
'6388546374527196',
|
|
147
|
+
'xwa2_newsletter_subscribed',
|
|
148
|
+
query,
|
|
149
|
+
generateMessageTag
|
|
150
|
+
);
|
|
151
|
+
return list;
|
|
152
|
+
},
|
|
104
153
|
subscribeNewsletterUpdates: async (jid) => {
|
|
105
154
|
var _a;
|
|
106
155
|
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
107
156
|
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
108
157
|
},
|
|
109
158
|
newsletterReactionMode: async (jid, mode) => {
|
|
110
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
111
|
-
updates: { settings: { reaction_codes: { value: mode } } }
|
|
159
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
160
|
+
updates: { settings: { 'reaction_codes': { value: mode } } }
|
|
112
161
|
});
|
|
113
162
|
},
|
|
114
163
|
newsletterUpdateDescription: async (jid, description) => {
|
|
115
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
164
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
116
165
|
updates: { description: description || '', settings: null }
|
|
117
166
|
});
|
|
118
167
|
},
|
|
119
168
|
newsletterUpdateName: async (jid, name) => {
|
|
120
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
169
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
121
170
|
updates: { name, settings: null }
|
|
122
171
|
});
|
|
123
172
|
},
|
|
124
173
|
newsletterUpdatePicture: async (jid, content) => {
|
|
125
174
|
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
126
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
175
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
127
176
|
updates: { picture: img.toString('base64'), settings: null }
|
|
128
177
|
});
|
|
129
178
|
},
|
|
130
179
|
newsletterRemovePicture: async (jid) => {
|
|
131
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
180
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
132
181
|
updates: { picture: '', settings: null }
|
|
133
182
|
});
|
|
134
183
|
},
|
|
135
184
|
newsletterUnfollow: async (jid) => {
|
|
136
|
-
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
|
185
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
|
|
137
186
|
},
|
|
138
187
|
newsletterFollow: async (jid) => {
|
|
139
|
-
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
|
188
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW);
|
|
140
189
|
},
|
|
141
190
|
newsletterUnmute: async (jid) => {
|
|
142
|
-
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
|
191
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE);
|
|
143
192
|
},
|
|
144
193
|
newsletterMute: async (jid) => {
|
|
145
|
-
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
|
194
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE);
|
|
146
195
|
},
|
|
147
|
-
|
|
196
|
+
newsletterAction: async (jid, type) => {
|
|
197
|
+
await newsletterWMexQuery(jid, type.toUpperCase());
|
|
198
|
+
},
|
|
199
|
+
newsletterCreate: async (name, description, reaction_codes) => {
|
|
200
|
+
//TODO: Implement TOS system wide for Meta AI, communities, and here etc.
|
|
201
|
+
/**tos query */
|
|
148
202
|
await query({
|
|
149
203
|
tag: 'iq',
|
|
150
204
|
attrs: {
|
|
@@ -164,55 +218,50 @@ const makeNewsletterSocket = (config) => {
|
|
|
164
218
|
}
|
|
165
219
|
]
|
|
166
220
|
});
|
|
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
|
-
}
|
|
221
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
222
|
+
input: { name, description, settings: { 'reaction_codes': { value: reaction_codes.toUpperCase() } } }
|
|
174
223
|
});
|
|
175
224
|
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
176
225
|
},
|
|
177
226
|
newsletterMetadata: async (type, key, role) => {
|
|
178
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
227
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
179
228
|
input: {
|
|
180
229
|
key,
|
|
181
230
|
type: type.toUpperCase(),
|
|
182
|
-
view_role: role || 'GUEST'
|
|
231
|
+
'view_role': role || 'GUEST'
|
|
183
232
|
},
|
|
184
|
-
fetch_viewer_metadata: true,
|
|
185
|
-
fetch_full_image: true,
|
|
186
|
-
fetch_creation_time: true
|
|
233
|
+
'fetch_viewer_metadata': true,
|
|
234
|
+
'fetch_full_image': true,
|
|
235
|
+
'fetch_creation_time': true
|
|
187
236
|
});
|
|
188
237
|
return (0, exports.extractNewsletterMetadata)(result);
|
|
189
238
|
},
|
|
190
239
|
newsletterAdminCount: async (jid) => {
|
|
191
240
|
var _a, _b;
|
|
192
|
-
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
|
241
|
+
const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT);
|
|
193
242
|
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
243
|
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
195
244
|
},
|
|
196
245
|
/**user is Lid, not Jid */
|
|
197
246
|
newsletterChangeOwner: async (jid, user) => {
|
|
198
|
-
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
199
|
-
user_id: user
|
|
247
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
248
|
+
'user_id': user
|
|
200
249
|
});
|
|
201
250
|
},
|
|
202
251
|
/**user is Lid, not Jid */
|
|
203
252
|
newsletterDemote: async (jid, user) => {
|
|
204
|
-
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
205
|
-
user_id: user
|
|
253
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
|
|
254
|
+
'user_id': user
|
|
206
255
|
});
|
|
207
256
|
},
|
|
208
257
|
newsletterDelete: async (jid) => {
|
|
209
|
-
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
258
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
|
|
210
259
|
},
|
|
211
260
|
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
212
|
-
newsletterReactMessage: async (jid,
|
|
261
|
+
newsletterReactMessage: async (jid, serverId, code) => {
|
|
213
262
|
await query({
|
|
214
263
|
tag: 'message',
|
|
215
|
-
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: (0, Utils_1.generateMessageID)() },
|
|
264
|
+
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', 'server_id': serverId, id: (0, Utils_1.generateMessageID)() },
|
|
216
265
|
content: [{
|
|
217
266
|
tag: 'reaction',
|
|
218
267
|
attrs: code ? { code } : {}
|
|
@@ -220,11 +269,10 @@ const makeNewsletterSocket = (config) => {
|
|
|
220
269
|
});
|
|
221
270
|
},
|
|
222
271
|
newsletterFetchMessages: async (type, key, count, after) => {
|
|
223
|
-
const afterStr = after === null || after === void 0 ? void 0 : after.toString();
|
|
224
272
|
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
225
273
|
{
|
|
226
274
|
tag: 'messages',
|
|
227
|
-
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after:
|
|
275
|
+
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100' }
|
|
228
276
|
}
|
|
229
277
|
]);
|
|
230
278
|
return await parseFetchedUpdates(result, 'messages');
|
|
@@ -241,28 +289,26 @@ const makeNewsletterSocket = (config) => {
|
|
|
241
289
|
};
|
|
242
290
|
};
|
|
243
291
|
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
244
|
-
|
|
245
292
|
const extractNewsletterMetadata = (node, isCreate) => {
|
|
246
|
-
|
|
247
|
-
const
|
|
248
|
-
|
|
293
|
+
const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
294
|
+
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
|
|
295
|
+
|
|
249
296
|
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;
|
|
297
|
+
id: metadataPath?.id,
|
|
298
|
+
state: metadataPath?.state?.type,
|
|
299
|
+
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
300
|
+
name: metadataPath?.thread_metadata?.name?.text,
|
|
301
|
+
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
302
|
+
description: metadataPath?.thread_metadata?.description?.text,
|
|
303
|
+
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
304
|
+
invite: metadataPath?.thread_metadata?.invite,
|
|
305
|
+
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
306
|
+
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
307
|
+
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
308
|
+
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
309
|
+
verification: metadataPath?.thread_metadata?.verification,
|
|
310
|
+
viewer_metadata: metadataPath?.viewer_metadata
|
|
311
|
+
}
|
|
312
|
+
return metadata
|
|
313
|
+
}
|
|
314
|
+
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|