@kelvdra/baileys 1.0.4 → 1.0.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/LICENSE +21 -0
- package/WAProto/index.js +65472 -137440
- package/lib/Defaults/index.d.ts +1 -1
- package/lib/Defaults/index.js +22 -3
- package/lib/Socket/chats.js +12 -13
- package/lib/Socket/groups.js +140 -7
- package/lib/Socket/hydra.js +44 -0
- package/lib/Socket/messages-recv.js +736 -324
- package/lib/Socket/messages-send.js +481 -110
- package/lib/Socket/mex.js +44 -6
- package/lib/Socket/newsletter.d.ts +16 -9
- package/lib/Socket/newsletter.js +259 -70
- package/lib/Types/Mex.d.ts +141 -0
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/State.js +54 -1
- package/lib/Utils/auth-utils.js +12 -1
- package/lib/Utils/chat-utils.js +36 -2
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/decode-wa-message.js +23 -4
- package/lib/Utils/generics.js +4 -1
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.js +1 -1
- package/lib/Utils/message-retry-manager.js +25 -1
- package/lib/Utils/messages-media.js +162 -43
- package/lib/Utils/messages.d.ts +1 -1
- package/lib/Utils/messages.js +230 -9
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/signal.js +45 -1
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/package.json +3 -1
package/lib/Socket/mex.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Boom } from '@hapi/boom';
|
|
2
2
|
import { getBinaryNodeChild, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
3
|
+
|
|
3
4
|
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
4
5
|
return query({
|
|
5
6
|
tag: 'iq',
|
|
@@ -18,25 +19,62 @@ const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
|
18
19
|
]
|
|
19
20
|
});
|
|
20
21
|
};
|
|
22
|
+
|
|
21
23
|
export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
22
24
|
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
23
|
-
|
|
25
|
+
|
|
26
|
+
const child =
|
|
27
|
+
getBinaryNodeChild(result, 'result') ||
|
|
28
|
+
getBinaryNodeChild(result, 'query') ||
|
|
29
|
+
(Array.isArray(result?.content)
|
|
30
|
+
? result.content.find(item =>
|
|
31
|
+
Buffer.isBuffer(item?.content) || item?.content instanceof Uint8Array
|
|
32
|
+
)
|
|
33
|
+
: undefined);
|
|
34
|
+
|
|
24
35
|
if (child?.content) {
|
|
25
|
-
const data = JSON.parse(child.content.toString());
|
|
36
|
+
const data = JSON.parse(Buffer.from(child.content).toString());
|
|
37
|
+
|
|
26
38
|
if (data.errors && data.errors.length > 0) {
|
|
27
39
|
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
|
|
28
40
|
const firstError = data.errors[0];
|
|
29
41
|
const errorCode = firstError.extensions?.error_code || 400;
|
|
30
|
-
throw new Boom(`GraphQL server error: ${errorMessages}`, {
|
|
42
|
+
throw new Boom(`GraphQL server error: ${errorMessages}`, {
|
|
43
|
+
statusCode: errorCode,
|
|
44
|
+
data: firstError
|
|
45
|
+
});
|
|
31
46
|
}
|
|
32
|
-
|
|
47
|
+
|
|
48
|
+
const root = data?.data;
|
|
49
|
+
|
|
50
|
+
// normal path
|
|
51
|
+
const response = dataPath ? root?.[dataPath] : root;
|
|
33
52
|
if (typeof response !== 'undefined') {
|
|
34
53
|
return response;
|
|
35
54
|
}
|
|
55
|
+
|
|
56
|
+
if (root && typeof root === 'object') {
|
|
57
|
+
const keys = Object.keys(root);
|
|
58
|
+
if (keys.length === 1) {
|
|
59
|
+
return root[keys[0]];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (typeof data?.result !== 'undefined') {
|
|
64
|
+
return data.result;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (root && typeof root === 'object') {
|
|
68
|
+
return root;
|
|
69
|
+
}
|
|
36
70
|
}
|
|
71
|
+
|
|
37
72
|
const action = (dataPath || '').startsWith('xwa2_')
|
|
38
73
|
? dataPath.substring(5).replace(/_/g, ' ')
|
|
39
74
|
: dataPath?.replace(/_/g, ' ');
|
|
40
|
-
|
|
75
|
+
|
|
76
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, {
|
|
77
|
+
statusCode: 400,
|
|
78
|
+
data: result
|
|
79
|
+
});
|
|
41
80
|
};
|
|
42
|
-
//# sourceMappingURL=mex.js.map
|
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
import type { SocketConfig, WAMediaUpload } from '../Types/index.js';
|
|
2
2
|
import type { NewsletterMetadata, NewsletterUpdate } from '../Types/index.js';
|
|
3
|
+
export declare const extractNewsletterMetadata: (result: any, isCreate?: boolean) => any;
|
|
3
4
|
export declare const makeNewsletterSocket: (config: SocketConfig) => {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
newsletterQuery: (jid: string, type: string, content: any[]) => Promise<any>;
|
|
6
|
+
newsletterWMexQuery: (jid: string | undefined, queryId: string, content?: Record<string, any>, dataPath?: string) => Promise<any>;
|
|
7
|
+
newsletterCreate: (name: string, description?: string, picture?: WAMediaUpload) => Promise<NewsletterMetadata>;
|
|
8
|
+
newsletterUpdate: (jid: string, updates: NewsletterUpdate & {
|
|
9
|
+
settings?: any;
|
|
10
|
+
}) => Promise<unknown>;
|
|
6
11
|
newsletterSubscribers: (jid: string) => Promise<{
|
|
7
12
|
subscribers: number;
|
|
8
13
|
}>;
|
|
9
|
-
newsletterMetadata: (type: "invite" | "jid", key: string) => Promise<NewsletterMetadata | null>;
|
|
14
|
+
newsletterMetadata: (type: "invite" | "jid", key: string, role?: string) => Promise<NewsletterMetadata | null>;
|
|
15
|
+
subscribeNewsletterUpdates: (jid: string) => Promise<any>;
|
|
16
|
+
newsletterReactionMode: (jid: string, mode: string) => Promise<unknown>;
|
|
10
17
|
newsletterFollow: (jid: string) => Promise<unknown>;
|
|
11
18
|
newsletterUnfollow: (jid: string) => Promise<unknown>;
|
|
12
19
|
newsletterMute: (jid: string) => Promise<unknown>;
|
|
13
20
|
newsletterUnmute: (jid: string) => Promise<unknown>;
|
|
21
|
+
newsletterAction: (jid: string, type: string) => Promise<any>;
|
|
14
22
|
newsletterUpdateName: (jid: string, name: string) => Promise<unknown>;
|
|
15
23
|
newsletterUpdateDescription: (jid: string, description: string) => Promise<unknown>;
|
|
16
24
|
newsletterUpdatePicture: (jid: string, content: WAMediaUpload) => Promise<unknown>;
|
|
17
25
|
newsletterRemovePicture: (jid: string) => Promise<unknown>;
|
|
18
|
-
|
|
19
|
-
newsletterFetchMessages: (jid: string, count: number, since: number, after: number) => Promise<any>;
|
|
20
|
-
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
21
|
-
duration: string;
|
|
22
|
-
} | null>;
|
|
26
|
+
newsletterFetchAllParticipating: () => Promise<never>;
|
|
23
27
|
newsletterAdminCount: (jid: string) => Promise<number>;
|
|
24
28
|
newsletterChangeOwner: (jid: string, newOwnerJid: string) => Promise<void>;
|
|
25
29
|
newsletterDemote: (jid: string, userJid: string) => Promise<void>;
|
|
26
30
|
newsletterDelete: (jid: string) => Promise<void>;
|
|
31
|
+
newsletterReactMessage: (jid: string, serverId: string, reaction?: string) => Promise<void>;
|
|
32
|
+
newsletterFetchMessages: (...args: any[]) => Promise<any>;
|
|
33
|
+
newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<any>;
|
|
27
34
|
groupMetadata: (jid: string) => Promise<import("../index.js").GroupMetadata>;
|
|
28
35
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../index.js").GroupMetadata>;
|
|
29
36
|
groupLeave: (id: string) => Promise<void>;
|
|
@@ -146,4 +153,4 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
|
|
|
146
153
|
}[] | undefined>;
|
|
147
154
|
};
|
|
148
155
|
export type NewsletterSocket = ReturnType<typeof makeNewsletterSocket>;
|
|
149
|
-
//# sourceMappingURL=newsletter.d.ts.map
|
|
156
|
+
//# sourceMappingURL=newsletter.d.ts.map
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -1,27 +1,39 @@
|
|
|
1
1
|
import { QueryIds, XWAPaths } from '../Types/index.js';
|
|
2
|
-
import { generateProfilePicture } from '../Utils/
|
|
3
|
-
import { getBinaryNodeChild } from '../WABinary/index.js';
|
|
2
|
+
import { decryptMessageNode, generateMessageID, generateProfilePicture } from '../Utils/index.js';
|
|
3
|
+
import { getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildren, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
4
4
|
import { makeGroupsSocket } from './groups.js';
|
|
5
5
|
import { executeWMexQuery as genericExecuteWMexQuery } from './mex.js';
|
|
6
|
+
|
|
7
|
+
const encoder = new TextEncoder();
|
|
8
|
+
|
|
6
9
|
const parseNewsletterCreateResponse = (response) => {
|
|
10
|
+
const metadata = extractNewsletterMetadataFromGraphQL(response, true);
|
|
11
|
+
if (metadata) {
|
|
12
|
+
return metadata;
|
|
13
|
+
}
|
|
7
14
|
const { id, thread_metadata: thread, viewer_metadata: viewer } = response;
|
|
8
15
|
return {
|
|
9
|
-
id
|
|
16
|
+
id,
|
|
10
17
|
owner: undefined,
|
|
11
|
-
name: thread
|
|
12
|
-
creation_time: parseInt(thread
|
|
13
|
-
description: thread
|
|
14
|
-
invite: thread
|
|
15
|
-
subscribers: parseInt(thread
|
|
16
|
-
verification: thread
|
|
18
|
+
name: thread?.name?.text,
|
|
19
|
+
creation_time: parseInt(thread?.creation_time || '0', 10) || undefined,
|
|
20
|
+
description: thread?.description?.text,
|
|
21
|
+
invite: thread?.invite,
|
|
22
|
+
subscribers: parseInt(thread?.subscribers_count || '0', 10) || undefined,
|
|
23
|
+
verification: thread?.verification,
|
|
17
24
|
picture: {
|
|
18
|
-
id: thread
|
|
19
|
-
directPath: thread
|
|
25
|
+
id: thread?.picture?.id,
|
|
26
|
+
directPath: thread?.picture?.direct_path
|
|
20
27
|
},
|
|
21
|
-
mute_state: viewer
|
|
28
|
+
mute_state: viewer?.mute
|
|
22
29
|
};
|
|
23
30
|
};
|
|
31
|
+
|
|
24
32
|
const parseNewsletterMetadata = (result) => {
|
|
33
|
+
const extracted = extractNewsletterMetadataFromGraphQL(result, false);
|
|
34
|
+
if (extracted) {
|
|
35
|
+
return extracted;
|
|
36
|
+
}
|
|
25
37
|
if (typeof result !== 'object' || result === null) {
|
|
26
38
|
return null;
|
|
27
39
|
}
|
|
@@ -33,29 +45,182 @@ const parseNewsletterMetadata = (result) => {
|
|
|
33
45
|
}
|
|
34
46
|
return null;
|
|
35
47
|
};
|
|
48
|
+
|
|
49
|
+
const extractNewsletterMetadataFromGraphQL = (result, isCreate = false) => {
|
|
50
|
+
const metadataPath = isCreate
|
|
51
|
+
? result
|
|
52
|
+
: result?.result?.id
|
|
53
|
+
? result.result
|
|
54
|
+
: result;
|
|
55
|
+
|
|
56
|
+
if (!metadataPath || typeof metadataPath !== 'object' || !metadataPath.id) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const thread = metadataPath.thread_metadata || {};
|
|
61
|
+
const viewer = metadataPath.viewer_metadata || {};
|
|
62
|
+
const settings = thread.settings || {};
|
|
63
|
+
|
|
64
|
+
const reactionCodes = Array.isArray(settings.reaction_codes)
|
|
65
|
+
? settings.reaction_codes
|
|
66
|
+
: Array.isArray(settings.reaction_codes?.codes)
|
|
67
|
+
? settings.reaction_codes.codes
|
|
68
|
+
: undefined;
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
id: metadataPath.id,
|
|
72
|
+
state: metadataPath?.state?.type,
|
|
73
|
+
creation_time: thread?.creation_time ? +thread.creation_time : undefined,
|
|
74
|
+
name: thread?.name?.text,
|
|
75
|
+
nameTime: thread?.name?.update_time ? +thread.name.update_time : undefined,
|
|
76
|
+
description: thread?.description?.text,
|
|
77
|
+
descriptionTime: thread?.description?.update_time ? +thread.description.update_time : undefined,
|
|
78
|
+
invite: thread?.invite,
|
|
79
|
+
handle: thread?.handle,
|
|
80
|
+
picture: {
|
|
81
|
+
id: thread?.picture?.id,
|
|
82
|
+
directPath: thread?.picture?.direct_path
|
|
83
|
+
},
|
|
84
|
+
preview: thread?.preview?.direct_path
|
|
85
|
+
? {
|
|
86
|
+
directPath: thread.preview.direct_path,
|
|
87
|
+
id: thread?.preview?.id
|
|
88
|
+
}
|
|
89
|
+
: undefined,
|
|
90
|
+
reaction_codes: reactionCodes,
|
|
91
|
+
subscribers: thread?.subscribers_count ? +thread.subscribers_count : undefined,
|
|
92
|
+
verification: thread?.verification,
|
|
93
|
+
viewer_metadata: viewer,
|
|
94
|
+
mute_state: viewer?.mute
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const extractNewsletterMetadata = extractNewsletterMetadataFromGraphQL;
|
|
99
|
+
|
|
36
100
|
export const makeNewsletterSocket = (config) => {
|
|
37
101
|
const sock = makeGroupsSocket(config);
|
|
38
|
-
const { query, generateMessageTag } = sock;
|
|
102
|
+
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
103
|
+
|
|
39
104
|
const executeWMexQuery = (variables, queryId, dataPath) => {
|
|
40
105
|
return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
|
|
41
106
|
};
|
|
107
|
+
|
|
108
|
+
const newsletterQuery = async (jid, type, content) => {
|
|
109
|
+
return query({
|
|
110
|
+
tag: 'iq',
|
|
111
|
+
attrs: {
|
|
112
|
+
id: generateMessageTag(),
|
|
113
|
+
type,
|
|
114
|
+
xmlns: 'newsletter',
|
|
115
|
+
to: jid
|
|
116
|
+
},
|
|
117
|
+
content
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const newsletterWMexQuery = async (jid, queryId, content, dataPath) => {
|
|
122
|
+
const variables = {
|
|
123
|
+
...(jid ? { newsletter_id: jid } : {}),
|
|
124
|
+
...(content || {})
|
|
125
|
+
};
|
|
126
|
+
return executeWMexQuery(variables, queryId, dataPath);
|
|
127
|
+
};
|
|
128
|
+
|
|
42
129
|
const newsletterUpdate = async (jid, updates) => {
|
|
43
130
|
const variables = {
|
|
44
131
|
newsletter_id: jid,
|
|
45
132
|
updates: {
|
|
46
133
|
...updates,
|
|
47
|
-
settings: null
|
|
134
|
+
settings: updates?.settings === undefined ? null : updates.settings
|
|
48
135
|
}
|
|
49
136
|
};
|
|
50
137
|
return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update');
|
|
51
138
|
};
|
|
139
|
+
|
|
140
|
+
const parseFetchedUpdates = async (node, type) => {
|
|
141
|
+
let child;
|
|
142
|
+
if (type === 'messages') {
|
|
143
|
+
child = getBinaryNodeChild(node, 'messages');
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
const parent = getBinaryNodeChild(node, 'message_updates');
|
|
147
|
+
child = getBinaryNodeChild(parent, 'messages');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const messageNodes = child ? getAllBinaryNodeChildren(child) : [];
|
|
151
|
+
return Promise.all(messageNodes.map(async (messageNode) => {
|
|
152
|
+
messageNode.attrs.from = child?.attrs?.jid || messageNode.attrs.from;
|
|
153
|
+
|
|
154
|
+
const views = parseInt(getBinaryNodeChild(messageNode, 'views_count')?.attrs?.count || '0', 10);
|
|
155
|
+
const reactionNode = getBinaryNodeChild(messageNode, 'reactions');
|
|
156
|
+
const reactions = getBinaryNodeChildren(reactionNode, 'reaction')
|
|
157
|
+
.map(({ attrs }) => ({ count: +(attrs.count || 0), code: attrs.code }));
|
|
158
|
+
|
|
159
|
+
const data = {
|
|
160
|
+
server_id: messageNode.attrs.server_id,
|
|
161
|
+
views,
|
|
162
|
+
reactions
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
if (type === 'messages') {
|
|
166
|
+
const { fullMessage: message, decrypt } = decryptMessageNode(
|
|
167
|
+
messageNode,
|
|
168
|
+
authState.creds.me.id,
|
|
169
|
+
authState.creds.me.lid || '',
|
|
170
|
+
signalRepository,
|
|
171
|
+
config.logger
|
|
172
|
+
);
|
|
173
|
+
await decrypt();
|
|
174
|
+
data.message = message;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return data;
|
|
178
|
+
}));
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const resolveActionQueryId = (type) => {
|
|
182
|
+
const value = QueryIds?.[String(type).toUpperCase()];
|
|
183
|
+
if (!value) {
|
|
184
|
+
throw new Error(`Unknown newsletter action: ${type}`);
|
|
185
|
+
}
|
|
186
|
+
return value;
|
|
187
|
+
};
|
|
188
|
+
|
|
52
189
|
return {
|
|
53
190
|
...sock,
|
|
54
|
-
|
|
191
|
+
newsletterQuery,
|
|
192
|
+
newsletterWMexQuery,
|
|
193
|
+
newsletterCreate: async (name, description, picture) => {
|
|
194
|
+
await query({
|
|
195
|
+
tag: 'iq',
|
|
196
|
+
attrs: {
|
|
197
|
+
to: S_WHATSAPP_NET,
|
|
198
|
+
xmlns: 'tos',
|
|
199
|
+
id: generateMessageTag(),
|
|
200
|
+
type: 'set'
|
|
201
|
+
},
|
|
202
|
+
content: [
|
|
203
|
+
{
|
|
204
|
+
tag: 'notice',
|
|
205
|
+
attrs: {
|
|
206
|
+
id: '20601218',
|
|
207
|
+
stage: '5'
|
|
208
|
+
},
|
|
209
|
+
content: []
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
});
|
|
213
|
+
|
|
55
214
|
const variables = {
|
|
56
215
|
input: {
|
|
57
216
|
name,
|
|
58
|
-
description: description ?? null
|
|
217
|
+
description: description ?? null,
|
|
218
|
+
picture: picture ? (await generateProfilePicture(picture)).img.toString('base64') : null,
|
|
219
|
+
settings: {
|
|
220
|
+
reaction_codes: {
|
|
221
|
+
value: 'ALL'
|
|
222
|
+
}
|
|
223
|
+
}
|
|
59
224
|
}
|
|
60
225
|
};
|
|
61
226
|
const rawResponse = await executeWMexQuery(variables, QueryIds.CREATE, XWAPaths.xwa2_newsletter_create);
|
|
@@ -65,19 +230,34 @@ export const makeNewsletterSocket = (config) => {
|
|
|
65
230
|
newsletterSubscribers: async (jid) => {
|
|
66
231
|
return executeWMexQuery({ newsletter_id: jid }, QueryIds.SUBSCRIBERS, XWAPaths.xwa2_newsletter_subscribers);
|
|
67
232
|
},
|
|
68
|
-
newsletterMetadata: async (type, key) => {
|
|
233
|
+
newsletterMetadata: async (type, key, role = 'GUEST') => {
|
|
69
234
|
const variables = {
|
|
70
235
|
fetch_creation_time: true,
|
|
71
236
|
fetch_full_image: true,
|
|
72
237
|
fetch_viewer_metadata: true,
|
|
73
238
|
input: {
|
|
74
239
|
key,
|
|
75
|
-
type: type.toUpperCase()
|
|
240
|
+
type: String(type).toUpperCase(),
|
|
241
|
+
view_role: role
|
|
76
242
|
}
|
|
77
243
|
};
|
|
78
244
|
const result = await executeWMexQuery(variables, QueryIds.METADATA, XWAPaths.xwa2_newsletter_metadata);
|
|
79
245
|
return parseNewsletterMetadata(result);
|
|
80
246
|
},
|
|
247
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
248
|
+
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
249
|
+
const liveUpdatesNode = getBinaryNodeChild(result, 'live_updates');
|
|
250
|
+
return liveUpdatesNode?.attrs || null;
|
|
251
|
+
},
|
|
252
|
+
newsletterReactionMode: async (jid, mode) => {
|
|
253
|
+
return await newsletterUpdate(jid, {
|
|
254
|
+
settings: {
|
|
255
|
+
reaction_codes: {
|
|
256
|
+
value: mode
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
},
|
|
81
261
|
newsletterFollow: (jid) => {
|
|
82
262
|
return executeWMexQuery({ newsletter_id: jid }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_follow);
|
|
83
263
|
},
|
|
@@ -90,6 +270,10 @@ export const makeNewsletterSocket = (config) => {
|
|
|
90
270
|
newsletterUnmute: (jid) => {
|
|
91
271
|
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2);
|
|
92
272
|
},
|
|
273
|
+
newsletterAction: async (jid, type) => {
|
|
274
|
+
const queryId = resolveActionQueryId(type);
|
|
275
|
+
return await newsletterWMexQuery(jid, queryId);
|
|
276
|
+
},
|
|
93
277
|
newsletterUpdateName: async (jid, name) => {
|
|
94
278
|
return await newsletterUpdate(jid, { name });
|
|
95
279
|
},
|
|
@@ -103,6 +287,22 @@ export const makeNewsletterSocket = (config) => {
|
|
|
103
287
|
newsletterRemovePicture: async (jid) => {
|
|
104
288
|
return await newsletterUpdate(jid, { picture: '' });
|
|
105
289
|
},
|
|
290
|
+
newsletterFetchAllParticipating: async () => {
|
|
291
|
+
throw new Error('newsletterFetchAllParticipating is not available in this lib build because the SUBSCRIBED query ID is not present in current Types/Newsletter definitions.');
|
|
292
|
+
},
|
|
293
|
+
newsletterAdminCount: async (jid) => {
|
|
294
|
+
const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
|
|
295
|
+
return response.admin_count;
|
|
296
|
+
},
|
|
297
|
+
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
298
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
|
|
299
|
+
},
|
|
300
|
+
newsletterDemote: async (jid, userJid) => {
|
|
301
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
|
|
302
|
+
},
|
|
303
|
+
newsletterDelete: async (jid) => {
|
|
304
|
+
await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
|
|
305
|
+
},
|
|
106
306
|
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
107
307
|
await query({
|
|
108
308
|
tag: 'message',
|
|
@@ -111,7 +311,7 @@ export const makeNewsletterSocket = (config) => {
|
|
|
111
311
|
...(reaction ? {} : { edit: '7' }),
|
|
112
312
|
type: 'reaction',
|
|
113
313
|
server_id: serverId,
|
|
114
|
-
id:
|
|
314
|
+
id: generateMessageID()
|
|
115
315
|
},
|
|
116
316
|
content: [
|
|
117
317
|
{
|
|
@@ -121,61 +321,50 @@ export const makeNewsletterSocket = (config) => {
|
|
|
121
321
|
]
|
|
122
322
|
});
|
|
123
323
|
},
|
|
124
|
-
newsletterFetchMessages: async (
|
|
125
|
-
|
|
126
|
-
count
|
|
127
|
-
|
|
128
|
-
if (typeof since === 'number') {
|
|
129
|
-
messageUpdateAttrs.since = since.toString();
|
|
130
|
-
}
|
|
131
|
-
if (after) {
|
|
132
|
-
messageUpdateAttrs.after = after.toString();
|
|
133
|
-
}
|
|
134
|
-
const result = await query({
|
|
135
|
-
tag: 'iq',
|
|
136
|
-
attrs: {
|
|
137
|
-
id: generateMessageTag(),
|
|
138
|
-
type: 'get',
|
|
139
|
-
xmlns: 'newsletter',
|
|
140
|
-
to: jid
|
|
141
|
-
},
|
|
142
|
-
content: [
|
|
324
|
+
newsletterFetchMessages: async (...args) => {
|
|
325
|
+
if (typeof args[0] === 'string' && (args[0] === 'invite' || args[0] === 'jid')) {
|
|
326
|
+
const [type, key, count, after] = args;
|
|
327
|
+
const result = await newsletterQuery(S_WHATSAPP_NET, 'get', [
|
|
143
328
|
{
|
|
144
|
-
tag: '
|
|
145
|
-
attrs:
|
|
329
|
+
tag: 'messages',
|
|
330
|
+
attrs: {
|
|
331
|
+
type,
|
|
332
|
+
...(type === 'invite' ? { key } : { jid: key }),
|
|
333
|
+
count: String(count),
|
|
334
|
+
after: after?.toString() || '100'
|
|
335
|
+
}
|
|
146
336
|
}
|
|
147
|
-
]
|
|
148
|
-
|
|
337
|
+
]);
|
|
338
|
+
return await parseFetchedUpdates(result, 'messages');
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const [jid, count, since, after] = args;
|
|
342
|
+
const messageUpdateAttrs = {
|
|
343
|
+
count: count.toString(),
|
|
344
|
+
...(typeof since === 'number' ? { since: since.toString() } : {}),
|
|
345
|
+
...(after !== undefined && after !== null ? { after: after.toString() } : {})
|
|
346
|
+
};
|
|
347
|
+
const result = await newsletterQuery(jid, 'get', [
|
|
348
|
+
{
|
|
349
|
+
tag: 'message_updates',
|
|
350
|
+
attrs: messageUpdateAttrs
|
|
351
|
+
}
|
|
352
|
+
]);
|
|
149
353
|
return result;
|
|
150
354
|
},
|
|
151
|
-
|
|
152
|
-
const result = await
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const duration = liveUpdatesNode?.attrs?.duration;
|
|
164
|
-
return duration ? { duration: duration } : null;
|
|
165
|
-
},
|
|
166
|
-
newsletterAdminCount: async (jid) => {
|
|
167
|
-
const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
|
|
168
|
-
return response.admin_count;
|
|
169
|
-
},
|
|
170
|
-
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
171
|
-
await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
|
|
172
|
-
},
|
|
173
|
-
newsletterDemote: async (jid, userJid) => {
|
|
174
|
-
await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
|
|
175
|
-
},
|
|
176
|
-
newsletterDelete: async (jid) => {
|
|
177
|
-
await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
|
|
355
|
+
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
356
|
+
const result = await newsletterQuery(jid, 'get', [
|
|
357
|
+
{
|
|
358
|
+
tag: 'message_updates',
|
|
359
|
+
attrs: {
|
|
360
|
+
count: String(count),
|
|
361
|
+
after: after?.toString() || '100',
|
|
362
|
+
since: since?.toString() || '0'
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
]);
|
|
366
|
+
return await parseFetchedUpdates(result, 'updates');
|
|
178
367
|
}
|
|
179
368
|
};
|
|
180
369
|
};
|
|
181
|
-
//# sourceMappingURL=newsletter.js.map
|
|
370
|
+
//# sourceMappingURL=newsletter.js.map
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
export declare enum XWAPaths {
|
|
2
|
+
xwa2_newsletter_create = "xwa2_newsletter_create",
|
|
3
|
+
xwa2_newsletter_subscribers = "xwa2_newsletter_subscribers",
|
|
4
|
+
xwa2_newsletter_view = "xwa2_newsletter_view",
|
|
5
|
+
xwa2_newsletter_metadata = "xwa2_newsletter",
|
|
6
|
+
xwa2_newsletter_admin_count = "xwa2_newsletter_admin",
|
|
7
|
+
xwa2_newsletter_mute_v2 = "xwa2_newsletter_mute_v2",
|
|
8
|
+
xwa2_newsletter_unmute_v2 = "xwa2_newsletter_unmute_v2",
|
|
9
|
+
xwa2_newsletter_follow = "xwa2_newsletter_follow",
|
|
10
|
+
xwa2_newsletter_unfollow = "xwa2_newsletter_unfollow",
|
|
11
|
+
xwa2_newsletter_join_v2 = "xwa2_newsletter_join_v2",
|
|
12
|
+
xwa2_newsletter_leave_v2 = "xwa2_newsletter_leave_v2",
|
|
13
|
+
xwa2_newsletter_change_owner = "xwa2_newsletter_change_owner",
|
|
14
|
+
xwa2_newsletter_demote = "xwa2_newsletter_demote",
|
|
15
|
+
xwa2_newsletter_delete_v2 = "xwa2_newsletter_delete_v2",
|
|
16
|
+
xwa2_fetch_account_reachout_timelock = "xwa2_fetch_account_reachout_timelock",
|
|
17
|
+
xwa2_message_capping_info = "xwa2_message_capping_info"
|
|
18
|
+
}
|
|
19
|
+
export declare enum QueryIds {
|
|
20
|
+
CREATE = "8823471724422422",
|
|
21
|
+
UPDATE_METADATA = "24250201037901610",
|
|
22
|
+
METADATA = "6563316087068696",
|
|
23
|
+
SUBSCRIBERS = "9783111038412085",
|
|
24
|
+
FOLLOW = "24404358912487870",
|
|
25
|
+
UNFOLLOW = "9767147403369991",
|
|
26
|
+
MUTE = "29766401636284406",
|
|
27
|
+
UNMUTE = "9864994326891137",
|
|
28
|
+
ADMIN_COUNT = "7130823597031706",
|
|
29
|
+
CHANGE_OWNER = "7341777602580933",
|
|
30
|
+
DEMOTE = "6551828931592903",
|
|
31
|
+
DELETE = "30062808666639665",
|
|
32
|
+
REACHOUT_TIMELOCK = "23983697327930364",
|
|
33
|
+
MESSAGE_CAPPING_INFO = "24503548349331633"
|
|
34
|
+
}
|
|
35
|
+
export type NewsletterUpdate = {
|
|
36
|
+
name?: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
picture?: string;
|
|
39
|
+
};
|
|
40
|
+
export interface NewsletterCreateResponse {
|
|
41
|
+
id: string;
|
|
42
|
+
state: {
|
|
43
|
+
type: string;
|
|
44
|
+
};
|
|
45
|
+
thread_metadata: {
|
|
46
|
+
creation_time: string;
|
|
47
|
+
description: {
|
|
48
|
+
id: string;
|
|
49
|
+
text: string;
|
|
50
|
+
update_time: string;
|
|
51
|
+
};
|
|
52
|
+
handle: string | null;
|
|
53
|
+
invite: string;
|
|
54
|
+
name: {
|
|
55
|
+
id: string;
|
|
56
|
+
text: string;
|
|
57
|
+
update_time: string;
|
|
58
|
+
};
|
|
59
|
+
picture: {
|
|
60
|
+
direct_path: string;
|
|
61
|
+
id: string;
|
|
62
|
+
type: string;
|
|
63
|
+
};
|
|
64
|
+
preview: {
|
|
65
|
+
direct_path: string;
|
|
66
|
+
id: string;
|
|
67
|
+
type: string;
|
|
68
|
+
};
|
|
69
|
+
subscribers_count: string;
|
|
70
|
+
verification: 'VERIFIED' | 'UNVERIFIED';
|
|
71
|
+
};
|
|
72
|
+
viewer_metadata: {
|
|
73
|
+
mute: 'ON' | 'OFF';
|
|
74
|
+
role: NewsletterViewRole;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export interface NewsletterCreateResponse {
|
|
78
|
+
id: string;
|
|
79
|
+
state: {
|
|
80
|
+
type: string;
|
|
81
|
+
};
|
|
82
|
+
thread_metadata: {
|
|
83
|
+
creation_time: string;
|
|
84
|
+
description: {
|
|
85
|
+
id: string;
|
|
86
|
+
text: string;
|
|
87
|
+
update_time: string;
|
|
88
|
+
};
|
|
89
|
+
handle: string | null;
|
|
90
|
+
invite: string;
|
|
91
|
+
name: {
|
|
92
|
+
id: string;
|
|
93
|
+
text: string;
|
|
94
|
+
update_time: string;
|
|
95
|
+
};
|
|
96
|
+
picture: {
|
|
97
|
+
direct_path: string;
|
|
98
|
+
id: string;
|
|
99
|
+
type: string;
|
|
100
|
+
};
|
|
101
|
+
preview: {
|
|
102
|
+
direct_path: string;
|
|
103
|
+
id: string;
|
|
104
|
+
type: string;
|
|
105
|
+
};
|
|
106
|
+
subscribers_count: string;
|
|
107
|
+
verification: 'VERIFIED' | 'UNVERIFIED';
|
|
108
|
+
};
|
|
109
|
+
viewer_metadata: {
|
|
110
|
+
mute: 'ON' | 'OFF';
|
|
111
|
+
role: NewsletterViewRole;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
export type NewsletterViewRole = 'ADMIN' | 'GUEST' | 'OWNER' | 'SUBSCRIBER';
|
|
115
|
+
export interface NewsletterMetadata {
|
|
116
|
+
id: string;
|
|
117
|
+
owner?: string;
|
|
118
|
+
name: string;
|
|
119
|
+
description?: string;
|
|
120
|
+
invite?: string;
|
|
121
|
+
creation_time?: number;
|
|
122
|
+
subscribers?: number;
|
|
123
|
+
picture?: {
|
|
124
|
+
url?: string;
|
|
125
|
+
directPath?: string;
|
|
126
|
+
mediaKey?: string;
|
|
127
|
+
id?: string;
|
|
128
|
+
};
|
|
129
|
+
verification?: 'VERIFIED' | 'UNVERIFIED';
|
|
130
|
+
reaction_codes?: {
|
|
131
|
+
code: string;
|
|
132
|
+
count: number;
|
|
133
|
+
}[];
|
|
134
|
+
mute_state?: 'ON' | 'OFF';
|
|
135
|
+
thread_metadata?: {
|
|
136
|
+
creation_time?: number;
|
|
137
|
+
name?: string;
|
|
138
|
+
description?: string;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=Mex.d.ts.map
|