@baileys-md/baileys 11.0.3 → 11.1.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 +1 -1
- package/WAProto/index.js +4182 -13516
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -4
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +71 -52
- package/lib/Defaults/{phonenumber-mcc.js → phonenumber-mcc.json} +1 -1
- package/lib/Signal/libsignal.js +61 -41
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +19 -3
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.js +42 -37
- package/lib/Socket/chats.js +187 -194
- package/lib/Socket/groups.js +90 -87
- package/lib/Socket/index.js +8 -7
- package/lib/Socket/messages-recv.js +335 -360
- package/lib/Socket/messages-send.js +279 -156
- package/lib/Socket/newsletter.js +213 -144
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.js +161 -128
- package/lib/Socket/usync.js +26 -19
- package/lib/Store/index.js +8 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/{Utils → Store}/make-in-memory-store.js +27 -19
- package/lib/Store/make-mongo-store.js +567 -0
- package/lib/{Utils → Store}/make-ordered-dictionary.js +5 -2
- package/lib/{Utils → Store}/object-repository.js +4 -1
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.js +17 -30
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +2 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.js +47 -31
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.js +195 -200
- package/lib/Utils/crypto.js +85 -70
- package/lib/Utils/decode-wa-message.js +51 -46
- package/lib/Utils/event-buffer.js +46 -36
- package/lib/Utils/generics.js +188 -116
- package/lib/Utils/history.js +46 -37
- package/lib/Utils/index.js +33 -19
- package/lib/Utils/link-preview.js +55 -14
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.js +26 -23
- package/lib/Utils/make-mutex.js +10 -7
- package/lib/Utils/messages-media.js +368 -239
- package/lib/Utils/messages.js +510 -278
- package/lib/Utils/noise-handler.js +31 -22
- package/lib/Utils/process-message.js +148 -144
- package/lib/Utils/signal.js +64 -71
- package/lib/Utils/use-multi-file-auth-state.js +32 -14
- package/lib/Utils/validate-connection.js +115 -72
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.js +52 -15
- package/lib/WABinary/encode.js +48 -14
- package/lib/WABinary/generic-utils.js +39 -31
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.js +40 -23
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.js +2366 -2257
- package/lib/WAM/encode.js +21 -17
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -3
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.js +32 -34
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.js +33 -11
- package/package.json +61 -21
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -4633
- package/WAProto/fix-imports.js +0 -29
- package/lib/Defaults/baileys-version.js +0 -1
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group_cipher.js +0 -94
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/keyhelper.js +0 -19
- package/lib/Signal/Group/queue-job.js +0 -54
- package/lib/Signal/Group/sender-chain-key.js +0 -32
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-message.js +0 -67
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-record.js +0 -50
- package/lib/Signal/Group/sender-key-state.js +0 -96
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/websocket.js +0 -50
- package/lib/Socket/communities.js +0 -351
- package/lib/Socket/mex.js +0 -42
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WebSocketClient = void 0;
|
|
7
|
+
const ws_1 = __importDefault(require("ws"));
|
|
8
|
+
const Defaults_1 = require("../../Defaults");
|
|
9
|
+
const abstract_socket_client_1 = require("./abstract-socket-client");
|
|
10
|
+
class WebSocketClient extends abstract_socket_client_1.AbstractSocketClient {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.socket = null;
|
|
14
|
+
}
|
|
15
|
+
get isOpen() {
|
|
16
|
+
var _a;
|
|
17
|
+
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN;
|
|
18
|
+
}
|
|
19
|
+
get isClosed() {
|
|
20
|
+
var _a;
|
|
21
|
+
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSED;
|
|
22
|
+
}
|
|
23
|
+
get isClosing() {
|
|
24
|
+
var _a;
|
|
25
|
+
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSING;
|
|
26
|
+
}
|
|
27
|
+
get isConnecting() {
|
|
28
|
+
var _a;
|
|
29
|
+
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CONNECTING;
|
|
30
|
+
}
|
|
31
|
+
async connect() {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
if (this.socket) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this.socket = new ws_1.default(this.url, {
|
|
37
|
+
origin: Defaults_1.DEFAULT_ORIGIN,
|
|
38
|
+
headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
|
|
39
|
+
handshakeTimeout: this.config.connectTimeoutMs,
|
|
40
|
+
timeout: this.config.connectTimeoutMs,
|
|
41
|
+
agent: this.config.agent,
|
|
42
|
+
});
|
|
43
|
+
this.socket.setMaxListeners(0);
|
|
44
|
+
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
|
|
45
|
+
for (const event of events) {
|
|
46
|
+
(_b = this.socket) === null || _b === void 0 ? void 0 : _b.on(event, (...args) => this.emit(event, ...args));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async close() {
|
|
50
|
+
if (!this.socket) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.socket.close();
|
|
54
|
+
this.socket = null;
|
|
55
|
+
}
|
|
56
|
+
send(str, cb) {
|
|
57
|
+
var _a;
|
|
58
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(str, cb);
|
|
59
|
+
return Boolean(this.socket);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.WebSocketClient = WebSocketClient;
|
package/lib/Socket/business.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeBusinessSocket = void 0;
|
|
4
|
+
const business_1 = require("../Utils/business");
|
|
5
|
+
const WABinary_1 = require("../WABinary");
|
|
6
|
+
const generic_utils_1 = require("../WABinary/generic-utils");
|
|
7
|
+
const messages_recv_1 = require("./messages-recv");
|
|
8
|
+
const makeBusinessSocket = (config) => {
|
|
9
|
+
const sock = (0, messages_recv_1.makeMessagesRecvSocket)(config);
|
|
7
10
|
const { authState, query, waUploadToServer } = sock;
|
|
8
11
|
const getCatalog = async ({ jid, limit, cursor }) => {
|
|
9
|
-
|
|
10
|
-
jid =
|
|
12
|
+
var _a;
|
|
13
|
+
jid = jid || ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id);
|
|
14
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
11
15
|
const queryParamNodes = [
|
|
12
16
|
{
|
|
13
17
|
tag: 'limit',
|
|
@@ -23,7 +27,7 @@ export const makeBusinessSocket = (config) => {
|
|
|
23
27
|
tag: 'height',
|
|
24
28
|
attrs: {},
|
|
25
29
|
content: Buffer.from('100')
|
|
26
|
-
}
|
|
30
|
+
},
|
|
27
31
|
];
|
|
28
32
|
if (cursor) {
|
|
29
33
|
queryParamNodes.push({
|
|
@@ -35,7 +39,7 @@ export const makeBusinessSocket = (config) => {
|
|
|
35
39
|
const result = await query({
|
|
36
40
|
tag: 'iq',
|
|
37
41
|
attrs: {
|
|
38
|
-
to: S_WHATSAPP_NET,
|
|
42
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
39
43
|
type: 'get',
|
|
40
44
|
xmlns: 'w:biz:catalog'
|
|
41
45
|
},
|
|
@@ -44,30 +48,31 @@ export const makeBusinessSocket = (config) => {
|
|
|
44
48
|
tag: 'product_catalog',
|
|
45
49
|
attrs: {
|
|
46
50
|
jid,
|
|
47
|
-
allow_shop_source: 'true'
|
|
51
|
+
'allow_shop_source': 'true'
|
|
48
52
|
},
|
|
49
53
|
content: queryParamNodes
|
|
50
54
|
}
|
|
51
55
|
]
|
|
52
56
|
});
|
|
53
|
-
return parseCatalogNode(result);
|
|
57
|
+
return (0, business_1.parseCatalogNode)(result);
|
|
54
58
|
};
|
|
55
59
|
const getCollections = async (jid, limit = 51) => {
|
|
56
|
-
|
|
57
|
-
jid =
|
|
60
|
+
var _a;
|
|
61
|
+
jid = jid || ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id);
|
|
62
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
58
63
|
const result = await query({
|
|
59
64
|
tag: 'iq',
|
|
60
65
|
attrs: {
|
|
61
|
-
to: S_WHATSAPP_NET,
|
|
66
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
62
67
|
type: 'get',
|
|
63
68
|
xmlns: 'w:biz:catalog',
|
|
64
|
-
smax_id: '35'
|
|
69
|
+
'smax_id': '35'
|
|
65
70
|
},
|
|
66
71
|
content: [
|
|
67
72
|
{
|
|
68
73
|
tag: 'collections',
|
|
69
74
|
attrs: {
|
|
70
|
-
biz_jid: jid
|
|
75
|
+
'biz_jid': jid,
|
|
71
76
|
},
|
|
72
77
|
content: [
|
|
73
78
|
{
|
|
@@ -94,16 +99,16 @@ export const makeBusinessSocket = (config) => {
|
|
|
94
99
|
}
|
|
95
100
|
]
|
|
96
101
|
});
|
|
97
|
-
return parseCollectionsNode(result);
|
|
102
|
+
return (0, business_1.parseCollectionsNode)(result);
|
|
98
103
|
};
|
|
99
104
|
const getOrderDetails = async (orderId, tokenBase64) => {
|
|
100
105
|
const result = await query({
|
|
101
106
|
tag: 'iq',
|
|
102
107
|
attrs: {
|
|
103
|
-
to: S_WHATSAPP_NET,
|
|
108
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
104
109
|
type: 'get',
|
|
105
110
|
xmlns: 'fb:thrift_iq',
|
|
106
|
-
smax_id: '5'
|
|
111
|
+
'smax_id': '5'
|
|
107
112
|
},
|
|
108
113
|
content: [
|
|
109
114
|
{
|
|
@@ -138,15 +143,15 @@ export const makeBusinessSocket = (config) => {
|
|
|
138
143
|
}
|
|
139
144
|
]
|
|
140
145
|
});
|
|
141
|
-
return parseOrderDetailsNode(result);
|
|
146
|
+
return (0, business_1.parseOrderDetailsNode)(result);
|
|
142
147
|
};
|
|
143
148
|
const productUpdate = async (productId, update) => {
|
|
144
|
-
update = await uploadingNecessaryImagesOfProduct(update, waUploadToServer);
|
|
145
|
-
const editNode = toProductNode(productId, update);
|
|
149
|
+
update = await (0, business_1.uploadingNecessaryImagesOfProduct)(update, waUploadToServer);
|
|
150
|
+
const editNode = (0, business_1.toProductNode)(productId, update);
|
|
146
151
|
const result = await query({
|
|
147
152
|
tag: 'iq',
|
|
148
153
|
attrs: {
|
|
149
|
-
to: S_WHATSAPP_NET,
|
|
154
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
150
155
|
type: 'set',
|
|
151
156
|
xmlns: 'w:biz:catalog'
|
|
152
157
|
},
|
|
@@ -170,19 +175,19 @@ export const makeBusinessSocket = (config) => {
|
|
|
170
175
|
}
|
|
171
176
|
]
|
|
172
177
|
});
|
|
173
|
-
const productCatalogEditNode = getBinaryNodeChild(result, 'product_catalog_edit');
|
|
174
|
-
const productNode = getBinaryNodeChild(productCatalogEditNode, 'product');
|
|
175
|
-
return parseProductNode(productNode);
|
|
178
|
+
const productCatalogEditNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_edit');
|
|
179
|
+
const productNode = (0, generic_utils_1.getBinaryNodeChild)(productCatalogEditNode, 'product');
|
|
180
|
+
return (0, business_1.parseProductNode)(productNode);
|
|
176
181
|
};
|
|
177
182
|
const productCreate = async (create) => {
|
|
178
183
|
// ensure isHidden is defined
|
|
179
184
|
create.isHidden = !!create.isHidden;
|
|
180
|
-
create = await uploadingNecessaryImagesOfProduct(create, waUploadToServer);
|
|
181
|
-
const createNode = toProductNode(undefined, create);
|
|
185
|
+
create = await (0, business_1.uploadingNecessaryImagesOfProduct)(create, waUploadToServer);
|
|
186
|
+
const createNode = (0, business_1.toProductNode)(undefined, create);
|
|
182
187
|
const result = await query({
|
|
183
188
|
tag: 'iq',
|
|
184
189
|
attrs: {
|
|
185
|
-
to: S_WHATSAPP_NET,
|
|
190
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
186
191
|
type: 'set',
|
|
187
192
|
xmlns: 'w:biz:catalog'
|
|
188
193
|
},
|
|
@@ -206,15 +211,15 @@ export const makeBusinessSocket = (config) => {
|
|
|
206
211
|
}
|
|
207
212
|
]
|
|
208
213
|
});
|
|
209
|
-
const productCatalogAddNode = getBinaryNodeChild(result, 'product_catalog_add');
|
|
210
|
-
const productNode = getBinaryNodeChild(productCatalogAddNode, 'product');
|
|
211
|
-
return parseProductNode(productNode);
|
|
214
|
+
const productCatalogAddNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_add');
|
|
215
|
+
const productNode = (0, generic_utils_1.getBinaryNodeChild)(productCatalogAddNode, 'product');
|
|
216
|
+
return (0, business_1.parseProductNode)(productNode);
|
|
212
217
|
};
|
|
213
218
|
const productDelete = async (productIds) => {
|
|
214
219
|
const result = await query({
|
|
215
220
|
tag: 'iq',
|
|
216
221
|
attrs: {
|
|
217
|
-
to: S_WHATSAPP_NET,
|
|
222
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
218
223
|
type: 'set',
|
|
219
224
|
xmlns: 'w:biz:catalog'
|
|
220
225
|
},
|
|
@@ -236,9 +241,9 @@ export const makeBusinessSocket = (config) => {
|
|
|
236
241
|
}
|
|
237
242
|
]
|
|
238
243
|
});
|
|
239
|
-
const productCatalogDelNode = getBinaryNodeChild(result, 'product_catalog_delete');
|
|
244
|
+
const productCatalogDelNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_delete');
|
|
240
245
|
return {
|
|
241
|
-
deleted: +(productCatalogDelNode
|
|
246
|
+
deleted: +((productCatalogDelNode === null || productCatalogDelNode === void 0 ? void 0 : productCatalogDelNode.attrs.deleted_count) || 0)
|
|
242
247
|
};
|
|
243
248
|
};
|
|
244
249
|
return {
|
|
@@ -252,4 +257,4 @@ export const makeBusinessSocket = (config) => {
|
|
|
252
257
|
productUpdate
|
|
253
258
|
};
|
|
254
259
|
};
|
|
255
|
-
|
|
260
|
+
exports.makeBusinessSocket = makeBusinessSocket;
|