@genuxofficial/baileys 1.0.0 → 2.0.0
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 +1 -1
- package/README.md +5 -1
- package/WAProto/index.d.ts +19244 -2787
- package/WAProto/index.js +138202 -74217
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +3 -5
- package/lib/Defaults/index.js +7 -6
- package/lib/Signal/libsignal.js +18 -9
- package/lib/Socket/Client/types.d.ts +0 -2
- package/lib/Socket/Client/websocket.js +1 -1
- package/lib/Socket/business.d.ts +65 -37
- package/lib/Socket/chats.d.ts +22 -18
- package/lib/Socket/chats.js +110 -6
- package/lib/Socket/groups.d.ts +30 -26
- package/lib/Socket/groups.js +20 -6
- package/lib/Socket/index.d.ts +66 -38
- package/lib/Socket/messages-recv.d.ts +63 -33
- package/lib/Socket/messages-recv.js +174 -27
- package/lib/Socket/messages-send.d.ts +55 -29
- package/lib/Socket/messages-send.js +190 -26
- package/lib/Socket/newsletter.d.ts +140 -0
- package/lib/Socket/newsletter.js +252 -0
- package/lib/Socket/socket.d.ts +8 -10
- package/lib/Socket/socket.js +26 -13
- package/lib/Socket/usync.d.ts +10 -12
- package/lib/Socket/usync.js +10 -15
- package/lib/Store/index.d.ts +1 -2
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.d.ts +1 -1
- package/lib/Store/make-in-memory-store.js +14 -5
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Types/Auth.d.ts +0 -2
- package/lib/Types/Chat.d.ts +7 -0
- package/lib/Types/Contact.d.ts +5 -0
- package/lib/Types/Events.d.ts +27 -0
- package/lib/Types/GroupMetadata.d.ts +7 -0
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +129 -16
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.d.ts +79 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/Socket.d.ts +8 -5
- package/lib/Types/index.d.ts +1 -0
- package/lib/Types/index.js +2 -1
- package/lib/Utils/auth-utils.d.ts +1 -1
- package/lib/Utils/auth-utils.js +6 -7
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +8 -10
- package/lib/Utils/chat-utils.js +11 -0
- package/lib/Utils/crypto.d.ts +14 -16
- package/lib/Utils/crypto.js +40 -26
- package/lib/Utils/decode-wa-message.d.ts +5 -3
- package/lib/Utils/decode-wa-message.js +171 -29
- package/lib/Utils/event-buffer.js +1 -3
- package/lib/Utils/generics.d.ts +35 -9
- package/lib/Utils/generics.js +93 -27
- package/lib/Utils/history.d.ts +2 -2
- package/lib/Utils/link-preview.d.ts +1 -1
- package/lib/Utils/link-preview.js +17 -7
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/make-mutex.js +0 -1
- package/lib/Utils/messages-media.d.ts +35 -16
- package/lib/Utils/messages-media.js +168 -43
- package/lib/Utils/messages.d.ts +6 -9
- package/lib/Utils/messages.js +297 -37
- package/lib/Utils/noise-handler.d.ts +5 -7
- package/lib/Utils/process-message.js +2 -3
- package/lib/Utils/use-multi-file-auth-state.js +44 -13
- package/lib/Utils/validate-connection.d.ts +2 -2
- package/lib/Utils/validate-connection.js +1 -3
- package/lib/WABinary/decode.d.ts +2 -4
- package/lib/WABinary/decode.js +20 -9
- package/lib/WABinary/encode.d.ts +1 -3
- package/lib/WABinary/encode.js +30 -12
- package/lib/WABinary/generic-utils.d.ts +1 -3
- package/lib/WABinary/generic-utils.js +2 -2
- package/lib/WABinary/jid-utils.d.ts +9 -4
- package/lib/WABinary/jid-utils.js +25 -4
- package/lib/WAM/BinaryInfo.d.ts +2 -12
- package/lib/WAM/encode.d.ts +1 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -5
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/USyncQuery.d.ts +2 -0
- package/lib/WAUSync/USyncQuery.js +27 -13
- package/lib/WAUSync/USyncUser.d.ts +2 -0
- package/lib/WAUSync/USyncUser.js +4 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/package.json +59 -57
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -3344
@@ -0,0 +1,252 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.extractNewsletterMetadata = exports.makeNewsletterSocket = void 0;
|
4
|
+
const Types_1 = require("../Types");
|
5
|
+
const Utils_1 = require("../Utils");
|
6
|
+
const WABinary_1 = require("../WABinary");
|
7
|
+
const groups_1 = require("./groups");
|
8
|
+
var QueryIds;
|
9
|
+
(function (QueryIds) {
|
10
|
+
QueryIds["JOB_MUTATION"] = "7150902998257522";
|
11
|
+
QueryIds["METADATA"] = "6620195908089573";
|
12
|
+
QueryIds["UNFOLLOW"] = "7238632346214362";
|
13
|
+
QueryIds["FOLLOW"] = "7871414976211147";
|
14
|
+
QueryIds["UNMUTE"] = "7337137176362961";
|
15
|
+
QueryIds["MUTE"] = "25151904754424642";
|
16
|
+
QueryIds["CREATE"] = "6996806640408138";
|
17
|
+
QueryIds["ADMIN_COUNT"] = "7130823597031706";
|
18
|
+
QueryIds["CHANGE_OWNER"] = "7341777602580933";
|
19
|
+
QueryIds["DELETE"] = "8316537688363079";
|
20
|
+
QueryIds["DEMOTE"] = "6551828931592903";
|
21
|
+
})(QueryIds || (QueryIds = {}));
|
22
|
+
const makeNewsletterSocket = (config) => {
|
23
|
+
const sock = (0, groups_1.makeGroupsSocket)(config);
|
24
|
+
const { authState, signalRepository, query, generateMessageTag } = sock;
|
25
|
+
const encoder = new TextEncoder();
|
26
|
+
const newsletterQuery = async (jid, type, content) => (query({
|
27
|
+
tag: 'iq',
|
28
|
+
attrs: {
|
29
|
+
id: generateMessageTag(),
|
30
|
+
type,
|
31
|
+
xmlns: 'newsletter',
|
32
|
+
to: jid,
|
33
|
+
},
|
34
|
+
content
|
35
|
+
}));
|
36
|
+
const newsletterWMexQuery = async (jid, query_id, content) => (query({
|
37
|
+
tag: 'iq',
|
38
|
+
attrs: {
|
39
|
+
id: generateMessageTag(),
|
40
|
+
type: 'get',
|
41
|
+
xmlns: 'w:mex',
|
42
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
43
|
+
},
|
44
|
+
content: [
|
45
|
+
{
|
46
|
+
tag: 'query',
|
47
|
+
attrs: { query_id },
|
48
|
+
content: encoder.encode(JSON.stringify({
|
49
|
+
variables: {
|
50
|
+
'newsletter_id': jid,
|
51
|
+
...content
|
52
|
+
}
|
53
|
+
}))
|
54
|
+
}
|
55
|
+
]
|
56
|
+
}));
|
57
|
+
const parseFetchedUpdates = async (node, type) => {
|
58
|
+
let child;
|
59
|
+
if (type === 'messages')
|
60
|
+
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
61
|
+
else {
|
62
|
+
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
63
|
+
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
64
|
+
}
|
65
|
+
return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
|
66
|
+
var _a, _b;
|
67
|
+
messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
|
68
|
+
const views = parseInt(((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'views_count')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.count) || '0');
|
69
|
+
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
70
|
+
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
71
|
+
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
72
|
+
const data = {
|
73
|
+
'server_id': messageNode.attrs.server_id,
|
74
|
+
views,
|
75
|
+
reactions
|
76
|
+
};
|
77
|
+
if (type === 'messages') {
|
78
|
+
const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger, config.getMessage);
|
79
|
+
await decrypt();
|
80
|
+
data.message = message;
|
81
|
+
}
|
82
|
+
return data;
|
83
|
+
}));
|
84
|
+
};
|
85
|
+
return {
|
86
|
+
...sock,
|
87
|
+
subscribeNewsletterUpdates: async (jid) => {
|
88
|
+
var _a;
|
89
|
+
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
90
|
+
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
91
|
+
},
|
92
|
+
newsletterReactionMode: async (jid, mode) => {
|
93
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
94
|
+
updates: { settings: { reaction_codes: { value: mode } } }
|
95
|
+
});
|
96
|
+
},
|
97
|
+
newsletterUpdateDescription: async (jid, description) => {
|
98
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
99
|
+
updates: { description: description || '', settings: null }
|
100
|
+
});
|
101
|
+
},
|
102
|
+
newsletterUpdateName: async (jid, name) => {
|
103
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
104
|
+
updates: { name, settings: null }
|
105
|
+
});
|
106
|
+
},
|
107
|
+
newsletterUpdatePicture: async (jid, content) => {
|
108
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
109
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
110
|
+
updates: { picture: img.toString('base64'), settings: null }
|
111
|
+
});
|
112
|
+
},
|
113
|
+
newsletterRemovePicture: async (jid) => {
|
114
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
115
|
+
updates: { picture: '', settings: null }
|
116
|
+
});
|
117
|
+
},
|
118
|
+
newsletterUnfollow: async (jid) => {
|
119
|
+
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
120
|
+
},
|
121
|
+
newsletterFollow: async (jid) => {
|
122
|
+
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
123
|
+
},
|
124
|
+
newsletterUnmute: async (jid) => {
|
125
|
+
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
126
|
+
},
|
127
|
+
newsletterMute: async (jid) => {
|
128
|
+
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
129
|
+
},
|
130
|
+
newsletterCreate: async (name, description, picture) => {
|
131
|
+
await query({
|
132
|
+
tag: 'iq',
|
133
|
+
attrs: {
|
134
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
135
|
+
xmlns: 'tos',
|
136
|
+
id: generateMessageTag(),
|
137
|
+
type: 'set'
|
138
|
+
},
|
139
|
+
content: [
|
140
|
+
{
|
141
|
+
tag: 'notice',
|
142
|
+
attrs: {
|
143
|
+
id: '20601218',
|
144
|
+
stage: '5'
|
145
|
+
},
|
146
|
+
content: []
|
147
|
+
}
|
148
|
+
]
|
149
|
+
});
|
150
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
|
151
|
+
input: {
|
152
|
+
name,
|
153
|
+
description: description !== null && description !== void 0 ? description : null,
|
154
|
+
picture: picture ? (await (0, Utils_1.generateProfilePicture)(picture)).img.toString('base64') : null,
|
155
|
+
settings: {
|
156
|
+
reaction_codes: { value: 'ALL' }
|
157
|
+
}
|
158
|
+
}
|
159
|
+
});
|
160
|
+
return (0, exports.extractNewsletterMetadata)(result, true);
|
161
|
+
},
|
162
|
+
newsletterMetadata: async (type, key, role) => {
|
163
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
164
|
+
input: {
|
165
|
+
key,
|
166
|
+
type: type.toUpperCase(),
|
167
|
+
view_role: role || 'GUEST'
|
168
|
+
},
|
169
|
+
fetch_viewer_metadata: true,
|
170
|
+
fetch_full_image: true,
|
171
|
+
fetch_creation_time: true
|
172
|
+
});
|
173
|
+
return (0, exports.extractNewsletterMetadata)(result);
|
174
|
+
},
|
175
|
+
newsletterAdminCount: async (jid) => {
|
176
|
+
var _a, _b;
|
177
|
+
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
178
|
+
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();
|
179
|
+
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
180
|
+
},
|
181
|
+
/**user is Lid, not Jid */
|
182
|
+
newsletterChangeOwner: async (jid, user) => {
|
183
|
+
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
184
|
+
user_id: user
|
185
|
+
});
|
186
|
+
},
|
187
|
+
/**user is Lid, not Jid */
|
188
|
+
newsletterDemote: async (jid, user) => {
|
189
|
+
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
190
|
+
user_id: user
|
191
|
+
});
|
192
|
+
},
|
193
|
+
newsletterDelete: async (jid) => {
|
194
|
+
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
195
|
+
},
|
196
|
+
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
197
|
+
newsletterReactMessage: async (jid, server_id, code) => {
|
198
|
+
await query({
|
199
|
+
tag: 'message',
|
200
|
+
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: (0, Utils_1.generateMessageID)() },
|
201
|
+
content: [{
|
202
|
+
tag: 'reaction',
|
203
|
+
attrs: code ? { code } : {}
|
204
|
+
}]
|
205
|
+
});
|
206
|
+
},
|
207
|
+
newsletterFetchMessages: async (type, key, count, after) => {
|
208
|
+
const afterStr = after === null || after === void 0 ? void 0 : after.toString();
|
209
|
+
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
210
|
+
{
|
211
|
+
tag: 'messages',
|
212
|
+
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: afterStr || '100' }
|
213
|
+
}
|
214
|
+
]);
|
215
|
+
return await parseFetchedUpdates(result, 'messages');
|
216
|
+
},
|
217
|
+
newsletterFetchUpdates: async (jid, count, after, since) => {
|
218
|
+
const result = await newsletterQuery(jid, 'get', [
|
219
|
+
{
|
220
|
+
tag: 'message_updates',
|
221
|
+
attrs: { count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100', since: (since === null || since === void 0 ? void 0 : since.toString()) || '0' }
|
222
|
+
}
|
223
|
+
]);
|
224
|
+
return await parseFetchedUpdates(result, 'updates');
|
225
|
+
}
|
226
|
+
};
|
227
|
+
};
|
228
|
+
exports.makeNewsletterSocket = makeNewsletterSocket;
|
229
|
+
const extractNewsletterMetadata = (node, isCreate) => {
|
230
|
+
var _a, _b, _c, _d;
|
231
|
+
const result = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
|
232
|
+
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER];
|
233
|
+
const metadata = {
|
234
|
+
id: metadataPath.id,
|
235
|
+
state: metadataPath.state.type,
|
236
|
+
creation_time: +metadataPath.thread_metadata.creation_time,
|
237
|
+
name: metadataPath.thread_metadata.name.text,
|
238
|
+
nameTime: +metadataPath.thread_metadata.name.update_time,
|
239
|
+
description: metadataPath.thread_metadata.description.text,
|
240
|
+
descriptionTime: +metadataPath.thread_metadata.description.update_time,
|
241
|
+
invite: metadataPath.thread_metadata.invite,
|
242
|
+
handle: metadataPath.thread_metadata.handle,
|
243
|
+
picture: ((_c = metadataPath.thread_metadata.picture) === null || _c === void 0 ? void 0 : _c.direct_path) || null,
|
244
|
+
preview: ((_d = metadataPath.thread_metadata.preview) === null || _d === void 0 ? void 0 : _d.direct_path) || null,
|
245
|
+
reaction_codes: metadataPath.thread_metadata.settings.reaction_codes.value,
|
246
|
+
subscribers: +metadataPath.thread_metadata.subscribers_count,
|
247
|
+
verification: metadataPath.thread_metadata.verification,
|
248
|
+
viewer_metadata: metadataPath.viewer_metadata
|
249
|
+
};
|
250
|
+
return metadata;
|
251
|
+
};
|
252
|
+
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|
package/lib/Socket/socket.d.ts
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
/// <reference types="node" />
|
3
1
|
import { Boom } from '@hapi/boom';
|
4
2
|
import { SocketConfig } from '../Types';
|
5
3
|
import { BinaryNode } from '../WABinary';
|
@@ -14,10 +12,10 @@ export declare const makeSocket: (config: SocketConfig) => {
|
|
14
12
|
type: "md";
|
15
13
|
ws: WebSocketClient;
|
16
14
|
ev: import("../Types").BaileysEventEmitter & {
|
17
|
-
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
15
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
18
16
|
buffer(): void;
|
19
|
-
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T
|
20
|
-
flush(force?: boolean
|
17
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
|
18
|
+
flush(force?: boolean): boolean;
|
21
19
|
isBuffering(): boolean;
|
22
20
|
};
|
23
21
|
authState: {
|
@@ -27,8 +25,8 @@ export declare const makeSocket: (config: SocketConfig) => {
|
|
27
25
|
signalRepository: import("../Types").SignalRepository;
|
28
26
|
readonly user: import("../Types").Contact | undefined;
|
29
27
|
generateMessageTag: () => string;
|
30
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<
|
31
|
-
waitForMessage: <
|
28
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
29
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
32
30
|
waitForSocketOpen: () => Promise<void>;
|
33
31
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
34
32
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
@@ -37,9 +35,9 @@ export declare const makeSocket: (config: SocketConfig) => {
|
|
37
35
|
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
38
36
|
uploadPreKeys: (count?: number) => Promise<void>;
|
39
37
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
40
|
-
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
38
|
+
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
41
39
|
/** Waits for the connection to WA to reach a state */
|
42
|
-
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number
|
43
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
40
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
41
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
44
42
|
};
|
45
43
|
export type Socket = ReturnType<typeof makeSocket>;
|
package/lib/Socket/socket.js
CHANGED
@@ -114,7 +114,7 @@ const makeSocket = (config) => {
|
|
114
114
|
let onRecv;
|
115
115
|
let onErr;
|
116
116
|
try {
|
117
|
-
|
117
|
+
const result = await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
|
118
118
|
onRecv = resolve;
|
119
119
|
onErr = err => {
|
120
120
|
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
@@ -123,6 +123,7 @@ const makeSocket = (config) => {
|
|
123
123
|
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
124
124
|
ws.off('error', onErr);
|
125
125
|
});
|
126
|
+
return result;
|
126
127
|
}
|
127
128
|
finally {
|
128
129
|
ws.off(`TAG:${msgId}`, onRecv);
|
@@ -136,9 +137,10 @@ const makeSocket = (config) => {
|
|
136
137
|
node.attrs.id = generateMessageTag();
|
137
138
|
}
|
138
139
|
const msgId = node.attrs.id;
|
139
|
-
const
|
140
|
-
|
141
|
-
|
140
|
+
const [result] = await Promise.all([
|
141
|
+
waitForMessage(msgId, timeoutMs),
|
142
|
+
sendNode(node)
|
143
|
+
]);
|
142
144
|
if ('tag' in result) {
|
143
145
|
(0, WABinary_1.assertNodeErrorFree)(result);
|
144
146
|
}
|
@@ -360,11 +362,16 @@ const makeSocket = (config) => {
|
|
360
362
|
}
|
361
363
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
362
364
|
};
|
363
|
-
const requestPairingCode = async (phoneNumber) => {
|
364
|
-
|
365
|
+
const requestPairingCode = async (phoneNumber, pairCode) => {
|
366
|
+
if (pairCode) {
|
367
|
+
authState.creds.pairingCode = pairCode.substring(0, 8).toUpperCase();
|
368
|
+
}
|
369
|
+
else {
|
370
|
+
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
371
|
+
}
|
365
372
|
authState.creds.me = {
|
366
373
|
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
367
|
-
name: '
|
374
|
+
name: 'ANYA WEB'
|
368
375
|
};
|
369
376
|
ev.emit('creds.update', authState.creds);
|
370
377
|
await sendNode({
|
@@ -506,12 +513,18 @@ const makeSocket = (config) => {
|
|
506
513
|
});
|
507
514
|
// login complete
|
508
515
|
ws.on('CB:success', async (node) => {
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
516
|
+
try {
|
517
|
+
await uploadPreKeysToServerIfRequired();
|
518
|
+
await sendPassiveIq('active');
|
519
|
+
logger.info('opened connection to WA');
|
520
|
+
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
521
|
+
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
|
522
|
+
ev.emit('connection.update', { connection: 'open' });
|
523
|
+
}
|
524
|
+
catch (err) {
|
525
|
+
logger.error({ err }, 'error opening connection');
|
526
|
+
end(err);
|
527
|
+
}
|
515
528
|
});
|
516
529
|
ws.on('CB:stream:error', (node) => {
|
517
530
|
logger.error({ node }, 'stream errored out');
|
package/lib/Socket/usync.d.ts
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
/// <reference types="node" />
|
3
1
|
import { Boom } from '@hapi/boom';
|
4
2
|
import { SocketConfig } from '../Types';
|
5
3
|
import { BinaryNode } from '../WABinary';
|
@@ -9,10 +7,10 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
9
7
|
type: "md";
|
10
8
|
ws: import("./Client").WebSocketClient;
|
11
9
|
ev: import("../Types").BaileysEventEmitter & {
|
12
|
-
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
10
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
13
11
|
buffer(): void;
|
14
|
-
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T
|
15
|
-
flush(force?: boolean
|
12
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
|
13
|
+
flush(force?: boolean): boolean;
|
16
14
|
isBuffering(): boolean;
|
17
15
|
};
|
18
16
|
authState: {
|
@@ -22,17 +20,17 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
22
20
|
signalRepository: import("../Types").SignalRepository;
|
23
21
|
user: import("../Types").Contact | undefined;
|
24
22
|
generateMessageTag: () => string;
|
25
|
-
query: (node: BinaryNode, timeoutMs?: number
|
26
|
-
waitForMessage: <
|
23
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
24
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
27
25
|
waitForSocketOpen: () => Promise<void>;
|
28
26
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
29
27
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
30
|
-
logout: (msg?: string
|
28
|
+
logout: (msg?: string) => Promise<void>;
|
31
29
|
end: (error: Error | undefined) => void;
|
32
|
-
onUnexpectedError: (err: Error | Boom
|
30
|
+
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
33
31
|
uploadPreKeys: (count?: number) => Promise<void>;
|
34
32
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
35
|
-
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
36
|
-
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number
|
37
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
33
|
+
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
34
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
35
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
38
36
|
};
|
package/lib/Socket/usync.js
CHANGED
@@ -6,7 +6,7 @@ const WABinary_1 = require("../WABinary");
|
|
6
6
|
const socket_1 = require("./socket");
|
7
7
|
const makeUSyncSocket = (config) => {
|
8
8
|
const sock = (0, socket_1.makeSocket)(config);
|
9
|
-
const { generateMessageTag, query
|
9
|
+
const { generateMessageTag, query } = sock;
|
10
10
|
const executeUSyncQuery = async (usyncQuery) => {
|
11
11
|
if (usyncQuery.protocols.length === 0) {
|
12
12
|
throw new boom_1.Boom('USyncQuery must have at least one protocol');
|
@@ -14,15 +14,13 @@ const makeUSyncSocket = (config) => {
|
|
14
14
|
// todo: validate users, throw WARNING on no valid users
|
15
15
|
// variable below has only validated users
|
16
16
|
const validUsers = usyncQuery.users;
|
17
|
-
const userNodes = validUsers.map(
|
17
|
+
const userNodes = validUsers.map(user => {
|
18
18
|
return {
|
19
19
|
tag: 'user',
|
20
20
|
attrs: {
|
21
|
-
jid: !user.phone ? user.id : undefined
|
21
|
+
jid: !user.phone ? user.id : undefined
|
22
22
|
},
|
23
|
-
content: usyncQuery.protocols
|
24
|
-
.map((a) => a.getUserElement(user))
|
25
|
-
.filter(a => a !== null)
|
23
|
+
content: usyncQuery.protocols.map(a => a.getUserElement(user)).filter(a => a !== null)
|
26
24
|
};
|
27
25
|
});
|
28
26
|
const listNode = {
|
@@ -33,14 +31,14 @@ const makeUSyncSocket = (config) => {
|
|
33
31
|
const queryNode = {
|
34
32
|
tag: 'query',
|
35
33
|
attrs: {},
|
36
|
-
content: usyncQuery.protocols.map(
|
34
|
+
content: usyncQuery.protocols.map(a => a.getQueryElement())
|
37
35
|
};
|
38
36
|
const iq = {
|
39
37
|
tag: 'iq',
|
40
38
|
attrs: {
|
41
39
|
to: WABinary_1.S_WHATSAPP_NET,
|
42
40
|
type: 'get',
|
43
|
-
xmlns: 'usync'
|
41
|
+
xmlns: 'usync'
|
44
42
|
},
|
45
43
|
content: [
|
46
44
|
{
|
@@ -50,21 +48,18 @@ const makeUSyncSocket = (config) => {
|
|
50
48
|
mode: usyncQuery.mode,
|
51
49
|
sid: generateMessageTag(),
|
52
50
|
last: 'true',
|
53
|
-
index: '0'
|
51
|
+
index: '0'
|
54
52
|
},
|
55
|
-
content: [
|
56
|
-
queryNode,
|
57
|
-
listNode
|
58
|
-
]
|
53
|
+
content: [queryNode, listNode]
|
59
54
|
}
|
60
|
-
]
|
55
|
+
]
|
61
56
|
};
|
62
57
|
const result = await query(iq);
|
63
58
|
return usyncQuery.parseUSyncQueryResult(result);
|
64
59
|
};
|
65
60
|
return {
|
66
61
|
...sock,
|
67
|
-
executeUSyncQuery
|
62
|
+
executeUSyncQuery
|
68
63
|
};
|
69
64
|
};
|
70
65
|
exports.makeUSyncSocket = makeUSyncSocket;
|
package/lib/Store/index.d.ts
CHANGED
package/lib/Store/index.js
CHANGED
@@ -3,8 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.
|
7
|
-
const make_cache_manager_store_1 = __importDefault(require("./make-cache-manager-store"));
|
8
|
-
exports.makeCacheManagerAuthState = make_cache_manager_store_1.default;
|
6
|
+
exports.makeInMemoryStore = void 0;
|
9
7
|
const make_in_memory_store_1 = __importDefault(require("./make-in-memory-store"));
|
10
8
|
exports.makeInMemoryStore = make_in_memory_store_1.default;
|
@@ -56,6 +56,14 @@ exports.default = (config) => {
|
|
56
56
|
labels.upsertById(label.id, label);
|
57
57
|
}
|
58
58
|
};
|
59
|
+
const getValidContacts = () => {
|
60
|
+
for (const contact of Object.keys(contacts)) {
|
61
|
+
if (contact.indexOf('@') < 0) {
|
62
|
+
delete contacts[contact];
|
63
|
+
}
|
64
|
+
}
|
65
|
+
return Object.keys(contacts);
|
66
|
+
};
|
59
67
|
/**
|
60
68
|
* binds to a BaileysEventEmitter.
|
61
69
|
* It listens to all events and constructs a state that you can query accurate data from.
|
@@ -104,10 +112,11 @@ exports.default = (config) => {
|
|
104
112
|
contact = contacts[update.id];
|
105
113
|
}
|
106
114
|
else {
|
107
|
-
const
|
115
|
+
const validContacts = getValidContacts();
|
116
|
+
const contactHashes = validContacts.map((contactId) => {
|
108
117
|
const { user } = (0, WABinary_1.jidDecode)(contactId);
|
109
|
-
return [contactId, (
|
110
|
-
})
|
118
|
+
return [contactId, ((0, Utils_1.md5)(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)];
|
119
|
+
});
|
111
120
|
contact = contacts[((_a = contactHashes.find(([, b]) => b === update.id)) === null || _a === void 0 ? void 0 : _a[0]) || '']; // find contact by attrs.hash, when user is not saved as a contact
|
112
121
|
}
|
113
122
|
if (contact) {
|
@@ -117,11 +126,11 @@ exports.default = (config) => {
|
|
117
126
|
else if (update.imgUrl === 'removed') {
|
118
127
|
delete contact.imgUrl;
|
119
128
|
}
|
129
|
+
Object.assign(contacts[contact.id], contact);
|
120
130
|
}
|
121
131
|
else {
|
122
|
-
|
132
|
+
logger.debug({ update }, 'got update for non-existant contact');
|
123
133
|
}
|
124
|
-
Object.assign(contacts[contact.id], contact);
|
125
134
|
}
|
126
135
|
});
|
127
136
|
ev.on('chats.upsert', newChats => {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
declare function makeOrderedDictionary<T>(idGetter: (item: T) => string): {
|
2
2
|
array: T[];
|
3
3
|
get: (id: string) => T | undefined;
|
4
|
-
upsert: (item: T, mode:
|
4
|
+
upsert: (item: T, mode: "append" | "prepend") => void;
|
5
5
|
update: (item: T) => boolean;
|
6
6
|
remove: (item: T) => boolean;
|
7
7
|
updateAssign: (id: string, update: Partial<T>) => boolean;
|
package/lib/Types/Auth.d.ts
CHANGED
package/lib/Types/Chat.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { proto } from '../../WAProto';
|
2
2
|
import type { AccountSettings } from './Auth';
|
3
|
+
import type { ContactAction } from './Contact';
|
3
4
|
import type { BufferedEventData } from './Events';
|
4
5
|
import type { LabelActionBody } from './Label';
|
5
6
|
import type { ChatLabelAssociationActionBody } from './LabelAssociation';
|
@@ -20,6 +21,10 @@ export interface PresenceData {
|
|
20
21
|
lastKnownPresence: WAPresence;
|
21
22
|
lastSeen?: number;
|
22
23
|
}
|
24
|
+
export type BotListInfo = {
|
25
|
+
jid: string;
|
26
|
+
personaId: string;
|
27
|
+
};
|
23
28
|
export type ChatMutation = {
|
24
29
|
syncAction: proto.ISyncActionData;
|
25
30
|
index: string[];
|
@@ -84,6 +89,8 @@ export type ChatModification = {
|
|
84
89
|
} | {
|
85
90
|
delete: true;
|
86
91
|
lastMessages: LastMessageList;
|
92
|
+
} | {
|
93
|
+
contact: ContactAction | null;
|
87
94
|
} | {
|
88
95
|
addLabel: LabelActionBody;
|
89
96
|
} | {
|
package/lib/Types/Contact.d.ts
CHANGED
package/lib/Types/Events.d.ts
CHANGED
@@ -9,6 +9,7 @@ import { Label } from './Label';
|
|
9
9
|
import { LabelAssociation } from './LabelAssociation';
|
10
10
|
import { MessageUpsertType, MessageUserReceiptUpdate, WAMessage, WAMessageKey, WAMessageUpdate } from './Message';
|
11
11
|
import { ConnectionState } from './State';
|
12
|
+
import { NewsletterSettingsUpdate, SubscriberAction, NewsletterViewRole } from './Newsletter';
|
12
13
|
export type BaileysEventMap = {
|
13
14
|
/** connection state has been updated -- WS closed, opened, connecting etc. */
|
14
15
|
'connection.update': Partial<ConnectionState>;
|
@@ -90,6 +91,32 @@ export type BaileysEventMap = {
|
|
90
91
|
action: RequestJoinAction;
|
91
92
|
method: RequestJoinMethod;
|
92
93
|
};
|
94
|
+
'newsletter.reaction': {
|
95
|
+
id: string;
|
96
|
+
server_id: string;
|
97
|
+
reaction: {
|
98
|
+
code?: string;
|
99
|
+
count?: number;
|
100
|
+
removed?: boolean;
|
101
|
+
};
|
102
|
+
};
|
103
|
+
'newsletter.view': {
|
104
|
+
id: string;
|
105
|
+
server_id: string;
|
106
|
+
count: number;
|
107
|
+
};
|
108
|
+
/**don't handles subscribe/unsubscribe actions */
|
109
|
+
'newsletter-participants.update': {
|
110
|
+
id: string;
|
111
|
+
author: string;
|
112
|
+
user: string;
|
113
|
+
new_role: NewsletterViewRole;
|
114
|
+
action: SubscriberAction;
|
115
|
+
};
|
116
|
+
'newsletter-settings.update': {
|
117
|
+
id: string;
|
118
|
+
update: NewsletterSettingsUpdate;
|
119
|
+
};
|
93
120
|
'blocklist.set': {
|
94
121
|
blocklist: string[];
|
95
122
|
};
|