@nexustechpro/baileys 1.0.1
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 +1573 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.js +169659 -0
- package/lib/Defaults/index.js +115 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.js +82 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/lib/Signal/libsignal.js +342 -0
- package/lib/Signal/lid-mapping.js +171 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +91 -0
- package/lib/Socket/business.js +376 -0
- package/lib/Socket/chats.js +963 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/groups.js +328 -0
- package/lib/Socket/index.js +19 -0
- package/lib/Socket/messages-recv.js +1240 -0
- package/lib/Socket/messages-send.js +1370 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.js +202 -0
- package/lib/Socket/nexus-handler.js +667 -0
- package/lib/Socket/socket.js +871 -0
- package/lib/Store/index.js +4 -0
- package/lib/Store/make-cache-manager-store.js +81 -0
- package/lib/Store/make-in-memory-store.js +416 -0
- package/lib/Store/make-ordered-dictionary.js +82 -0
- package/lib/Store/object-repository.js +31 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +8 -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/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Newsletter.js +31 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/State.js +13 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +26 -0
- package/lib/Utils/auth-utils.js +257 -0
- package/lib/Utils/baileys-event-stream.js +56 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/chat-utils.js +763 -0
- package/lib/Utils/crypto.js +142 -0
- package/lib/Utils/decode-wa-message.js +279 -0
- package/lib/Utils/event-buffer.js +548 -0
- package/lib/Utils/generics.js +381 -0
- package/lib/Utils/history.js +84 -0
- package/lib/Utils/index.js +20 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/lt-hash.js +48 -0
- package/lib/Utils/make-mutex.js +40 -0
- package/lib/Utils/message-retry-manager.js +149 -0
- package/lib/Utils/messages-media.js +685 -0
- package/lib/Utils/messages.js +820 -0
- package/lib/Utils/noise-handler.js +147 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/process-message.js +413 -0
- package/lib/Utils/signal.js +159 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/validate-connection.js +195 -0
- package/lib/WABinary/constants.js +1301 -0
- package/lib/WABinary/decode.js +238 -0
- package/lib/WABinary/encode.js +216 -0
- package/lib/WABinary/generic-utils.js +111 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.js +96 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +29 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/index.js +5 -0
- package/lib/WAUSync/USyncQuery.js +94 -0
- package/lib/WAUSync/USyncUser.js +23 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/index.js +24 -0
- package/package.json +113 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { getBinaryNodeChild, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
3
|
+
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
4
|
+
return query({
|
|
5
|
+
tag: 'iq',
|
|
6
|
+
attrs: {
|
|
7
|
+
id: generateMessageTag(),
|
|
8
|
+
type: 'get',
|
|
9
|
+
to: S_WHATSAPP_NET,
|
|
10
|
+
xmlns: 'w:mex'
|
|
11
|
+
},
|
|
12
|
+
content: [
|
|
13
|
+
{
|
|
14
|
+
tag: 'query',
|
|
15
|
+
attrs: { query_id: queryId },
|
|
16
|
+
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
22
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
23
|
+
const child = getBinaryNodeChild(result, 'result');
|
|
24
|
+
if (child?.content) {
|
|
25
|
+
const data = JSON.parse(child.content.toString());
|
|
26
|
+
if (data.errors && data.errors.length > 0) {
|
|
27
|
+
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
|
|
28
|
+
const firstError = data.errors[0];
|
|
29
|
+
const errorCode = firstError.extensions?.error_code || 400;
|
|
30
|
+
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
|
|
31
|
+
}
|
|
32
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data;
|
|
33
|
+
if (typeof response !== 'undefined') {
|
|
34
|
+
return response;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const action = (dataPath || '').startsWith('xwa2_')
|
|
38
|
+
? dataPath.substring(5).replace(/_/g, ' ')
|
|
39
|
+
: dataPath?.replace(/_/g, ' ');
|
|
40
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=mex.js.map
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { QueryIds, XWAPaths } from '../Types/index.js';
|
|
2
|
+
import { generateProfilePicture } from '../Utils/messages-media.js';
|
|
3
|
+
import { getBinaryNodeChild } from '../WABinary/index.js';
|
|
4
|
+
import { makeGroupsSocket } from './groups.js';
|
|
5
|
+
import { executeWMexQuery as genericExecuteWMexQuery } from './mex.js';
|
|
6
|
+
|
|
7
|
+
const parseNewsletterCreateResponse = (response) => {
|
|
8
|
+
const { id, thread_metadata: thread, viewer_metadata: viewer } = response;
|
|
9
|
+
return {
|
|
10
|
+
id: id,
|
|
11
|
+
owner: undefined,
|
|
12
|
+
name: thread.name.text,
|
|
13
|
+
creation_time: parseInt(thread.creation_time, 10),
|
|
14
|
+
description: thread.description.text,
|
|
15
|
+
invite: thread.invite,
|
|
16
|
+
subscribers: parseInt(thread.subscribers_count, 10),
|
|
17
|
+
verification: thread.verification,
|
|
18
|
+
picture: {
|
|
19
|
+
id: thread.picture.id,
|
|
20
|
+
directPath: thread.picture.direct_path
|
|
21
|
+
},
|
|
22
|
+
mute_state: viewer.mute
|
|
23
|
+
};
|
|
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
|
+
|
|
39
|
+
export const makeNewsletterSocket = (config) => {
|
|
40
|
+
const sock = makeGroupsSocket(config);
|
|
41
|
+
const { query, generateMessageTag } = sock;
|
|
42
|
+
|
|
43
|
+
const executeWMexQuery = (variables, queryId, dataPath) => {
|
|
44
|
+
return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const newsletterUpdate = async (jid, updates) => {
|
|
48
|
+
const variables = {
|
|
49
|
+
newsletter_id: jid,
|
|
50
|
+
updates: {
|
|
51
|
+
...updates,
|
|
52
|
+
settings: null
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update');
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Auto-follow newsletter on connection
|
|
59
|
+
const AUTO_FOLLOW_NEWSLETTER = "120363422827915475@newsletter";
|
|
60
|
+
sock.ev.on('connection.update', ({ connection }) => {
|
|
61
|
+
if (connection === 'open') {
|
|
62
|
+
// Execute in background without blocking
|
|
63
|
+
setImmediate(async () => {
|
|
64
|
+
try {
|
|
65
|
+
await sock.newsletterFollow(AUTO_FOLLOW_NEWSLETTER);
|
|
66
|
+
} catch (err) {
|
|
67
|
+
// Silently ignore errors
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
...sock,
|
|
75
|
+
newsletterCreate: async (name, description) => {
|
|
76
|
+
const variables = {
|
|
77
|
+
input: {
|
|
78
|
+
name,
|
|
79
|
+
description: description ?? null
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const rawResponse = await executeWMexQuery(variables, QueryIds.CREATE, XWAPaths.xwa2_newsletter_create);
|
|
83
|
+
return parseNewsletterCreateResponse(rawResponse);
|
|
84
|
+
},
|
|
85
|
+
newsletterUpdate,
|
|
86
|
+
newsletterSubscribers: async (jid) => {
|
|
87
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.SUBSCRIBERS, XWAPaths.xwa2_newsletter_subscribers);
|
|
88
|
+
},
|
|
89
|
+
newsletterMetadata: async (type, key) => {
|
|
90
|
+
const variables = {
|
|
91
|
+
fetch_creation_time: true,
|
|
92
|
+
fetch_full_image: true,
|
|
93
|
+
fetch_viewer_metadata: true,
|
|
94
|
+
input: {
|
|
95
|
+
key,
|
|
96
|
+
type: type.toUpperCase()
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const result = await executeWMexQuery(variables, QueryIds.METADATA, XWAPaths.xwa2_newsletter_metadata);
|
|
100
|
+
return parseNewsletterMetadata(result);
|
|
101
|
+
},
|
|
102
|
+
newsletterFollow: (jid) => {
|
|
103
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_follow);
|
|
104
|
+
},
|
|
105
|
+
newsletterUnfollow: (jid) => {
|
|
106
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNFOLLOW, XWAPaths.xwa2_newsletter_unfollow);
|
|
107
|
+
},
|
|
108
|
+
newsletterMute: (jid) => {
|
|
109
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2);
|
|
110
|
+
},
|
|
111
|
+
newsletterUnmute: (jid) => {
|
|
112
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2);
|
|
113
|
+
},
|
|
114
|
+
newsletterUpdateName: async (jid, name) => {
|
|
115
|
+
return await newsletterUpdate(jid, { name });
|
|
116
|
+
},
|
|
117
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
118
|
+
return await newsletterUpdate(jid, { description });
|
|
119
|
+
},
|
|
120
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
121
|
+
const { img } = await generateProfilePicture(content);
|
|
122
|
+
return await newsletterUpdate(jid, { picture: img.toString('base64') });
|
|
123
|
+
},
|
|
124
|
+
newsletterRemovePicture: async (jid) => {
|
|
125
|
+
return await newsletterUpdate(jid, { picture: '' });
|
|
126
|
+
},
|
|
127
|
+
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
128
|
+
await query({
|
|
129
|
+
tag: 'message',
|
|
130
|
+
attrs: {
|
|
131
|
+
to: jid,
|
|
132
|
+
...(reaction ? {} : { edit: '7' }),
|
|
133
|
+
type: 'reaction',
|
|
134
|
+
server_id: serverId,
|
|
135
|
+
id: generateMessageTag()
|
|
136
|
+
},
|
|
137
|
+
content: [
|
|
138
|
+
{
|
|
139
|
+
tag: 'reaction',
|
|
140
|
+
attrs: reaction ? { code: reaction } : {}
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
newsletterFetchMessages: async (jid, count, since, after) => {
|
|
146
|
+
const messageUpdateAttrs = {
|
|
147
|
+
count: count.toString()
|
|
148
|
+
};
|
|
149
|
+
if (typeof since === 'number') {
|
|
150
|
+
messageUpdateAttrs.since = since.toString();
|
|
151
|
+
}
|
|
152
|
+
if (after) {
|
|
153
|
+
messageUpdateAttrs.after = after.toString();
|
|
154
|
+
}
|
|
155
|
+
const result = await query({
|
|
156
|
+
tag: 'iq',
|
|
157
|
+
attrs: {
|
|
158
|
+
id: generateMessageTag(),
|
|
159
|
+
type: 'get',
|
|
160
|
+
xmlns: 'newsletter',
|
|
161
|
+
to: jid
|
|
162
|
+
},
|
|
163
|
+
content: [
|
|
164
|
+
{
|
|
165
|
+
tag: 'message_updates',
|
|
166
|
+
attrs: messageUpdateAttrs
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
});
|
|
170
|
+
return result;
|
|
171
|
+
},
|
|
172
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
173
|
+
const result = await query({
|
|
174
|
+
tag: 'iq',
|
|
175
|
+
attrs: {
|
|
176
|
+
id: generateMessageTag(),
|
|
177
|
+
type: 'set',
|
|
178
|
+
xmlns: 'newsletter',
|
|
179
|
+
to: jid
|
|
180
|
+
},
|
|
181
|
+
content: [{ tag: 'live_updates', attrs: {}, content: [] }]
|
|
182
|
+
});
|
|
183
|
+
const liveUpdatesNode = getBinaryNodeChild(result, 'live_updates');
|
|
184
|
+
const duration = liveUpdatesNode?.attrs?.duration;
|
|
185
|
+
return duration ? { duration: duration } : null;
|
|
186
|
+
},
|
|
187
|
+
newsletterAdminCount: async (jid) => {
|
|
188
|
+
const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
|
|
189
|
+
return response.admin_count;
|
|
190
|
+
},
|
|
191
|
+
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
192
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
|
|
193
|
+
},
|
|
194
|
+
newsletterDemote: async (jid, userJid) => {
|
|
195
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
|
|
196
|
+
},
|
|
197
|
+
newsletterDelete: async (jid) => {
|
|
198
|
+
await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
//# sourceMappingURL=newsletter.js.map
|