@wenzyx1/bails 1.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/README.md +231 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +79257 -0
- package/WAProto/index.js +242946 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +53 -0
- package/lib/Defaults/index.js +147 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +93 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +53 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +29 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +454 -0
- package/lib/Signal/lid-mapping.js +280 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +19 -0
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +171 -0
- package/lib/Socket/business.js +342 -0
- package/lib/Socket/chats.d.ts +267 -0
- package/lib/Socket/chats.js +978 -0
- package/lib/Socket/communities.mjs +428 -0
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +558 -0
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/groups.js +380 -0
- package/lib/Socket/index.d.ts +173 -0
- package/lib/Socket/index.js +32 -0
- package/lib/Socket/luxu.js +545 -0
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-recv.js +1124 -0
- package/lib/Socket/messages-send.d.ts +149 -0
- package/lib/Socket/messages-send.js +1476 -0
- package/lib/Socket/mex.mjs +50 -0
- package/lib/Socket/newsletter.d.ts +134 -0
- package/lib/Socket/newsletter.js +351 -0
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/socket.js +904 -0
- package/lib/Socket/username.mjs +132 -0
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/keyed-db.d.ts +30 -0
- package/lib/Store/keyed-db.js +233 -0
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +427 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +110 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +102 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.d.ts +19 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +157 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +55 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +35 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.d.ts +273 -0
- package/lib/Types/Message.js +9 -0
- package/lib/Types/Mex.js +39 -0
- package/lib/Types/Newsletter.d.ts +103 -0
- package/lib/Types/Newsletter.js +38 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.d.ts +111 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +57 -0
- package/lib/Types/index.js +43 -0
- package/lib/Utils/Mex.js +39 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +206 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +57 -0
- package/lib/Utils/browser-presets.js +64 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +234 -0
- package/lib/Utils/chat-utils.d.ts +71 -0
- package/lib/Utils/chat-utils.js +726 -0
- package/lib/Utils/companion-reg-client-utils.js +40 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +151 -0
- package/lib/Utils/decode-wa-message.d.ts +19 -0
- package/lib/Utils/decode-wa-message.js +198 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +514 -0
- package/lib/Utils/extended-messages.js +231 -0
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +425 -0
- package/lib/Utils/history.d.ts +15 -0
- package/lib/Utils/history.js +96 -0
- package/lib/Utils/identity-change-handler.js +52 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +40 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +93 -0
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +51 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +43 -0
- package/lib/Utils/message-composer.js +293 -0
- package/lib/Utils/message-retry-manager.js +226 -0
- package/lib/Utils/messages-media.d.ts +116 -0
- package/lib/Utils/messages-media.js +815 -0
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +888 -0
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +155 -0
- package/lib/Utils/offline-node-processor.js +46 -0
- package/lib/Utils/pre-key-manager.js +95 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +321 -0
- package/lib/Utils/reporting-utils.js +272 -0
- package/lib/Utils/signal.d.ts +32 -0
- package/lib/Utils/signal.js +160 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/sync-action-utils.js +50 -0
- package/lib/Utils/tc-token-utils.js +169 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +119 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +229 -0
- package/lib/WABinary/constants.d.ts +30 -0
- package/lib/WABinary/constants.js +40 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +252 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +265 -0
- package/lib/WABinary/generic-utils.d.ts +17 -0
- package/lib/WABinary/generic-utils.js +204 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/jid-utils.js +132 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +17 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/constants.js +15350 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +155 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +55 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +27 -0
- 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/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +21 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncQuery.js +93 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/USyncUser.js +34 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +52 -0
- package/package.json +112 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUrlInfo = void 0;
|
|
4
|
+
const messages_1 = require("./messages");
|
|
5
|
+
const messages_media_1 = require("./messages-media");
|
|
6
|
+
const THUMBNAIL_WIDTH_PX = 192;
|
|
7
|
+
/** Fetches an image and generates a thumbnail for it */
|
|
8
|
+
const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
|
|
9
|
+
const stream = await (0, messages_media_1.getHttpStream)(url, fetchOpts);
|
|
10
|
+
const result = await (0, messages_media_1.extractImageThumb)(stream, thumbnailWidth);
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
15
|
+
* Return undefined if the fetch failed or no URL was found
|
|
16
|
+
* @param text first matched URL in text
|
|
17
|
+
* @returns the URL info required to generate link preview
|
|
18
|
+
*/
|
|
19
|
+
const getUrlInfo = async (text, opts = {
|
|
20
|
+
thumbnailWidth: THUMBNAIL_WIDTH_PX,
|
|
21
|
+
fetchOpts: { timeout: 3000 }
|
|
22
|
+
}) => {
|
|
23
|
+
var _a;
|
|
24
|
+
try {
|
|
25
|
+
// retries
|
|
26
|
+
const retries = 0;
|
|
27
|
+
const maxRetry = 5;
|
|
28
|
+
const { getLinkPreview } = await import('link-preview-js');
|
|
29
|
+
let previewLink = text;
|
|
30
|
+
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
31
|
+
previewLink = 'https://' + previewLink;
|
|
32
|
+
}
|
|
33
|
+
const info = await getLinkPreview(previewLink, {
|
|
34
|
+
...opts.fetchOpts,
|
|
35
|
+
followRedirects: 'follow',
|
|
36
|
+
handleRedirects: (baseURL, forwardedURL) => {
|
|
37
|
+
const urlObj = new URL(baseURL);
|
|
38
|
+
const forwardedURLObj = new URL(forwardedURL);
|
|
39
|
+
if (retries >= maxRetry) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (forwardedURLObj.hostname === urlObj.hostname
|
|
43
|
+
|| forwardedURLObj.hostname === 'www.' + urlObj.hostname
|
|
44
|
+
|| 'www.' + forwardedURLObj.hostname === urlObj.hostname) {
|
|
45
|
+
retries + 1;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
headers: opts.fetchOpts
|
|
53
|
+
});
|
|
54
|
+
if (info && 'title' in info && info.title) {
|
|
55
|
+
const [image] = info.images;
|
|
56
|
+
const urlInfo = {
|
|
57
|
+
'canonical-url': info.url,
|
|
58
|
+
'matched-text': text,
|
|
59
|
+
title: info.title,
|
|
60
|
+
description: info.description,
|
|
61
|
+
originalThumbnailUrl: image
|
|
62
|
+
};
|
|
63
|
+
if (opts.uploadImage) {
|
|
64
|
+
const { imageMessage } = await (0, messages_1.prepareWAMessageMedia)({ image: { url: image } }, {
|
|
65
|
+
upload: opts.uploadImage,
|
|
66
|
+
mediaTypeOverride: 'thumbnail-link',
|
|
67
|
+
options: opts.fetchOpts
|
|
68
|
+
});
|
|
69
|
+
urlInfo.jpegThumbnail = (imageMessage === null || imageMessage === void 0 ? void 0 : imageMessage.jpegThumbnail)
|
|
70
|
+
? Buffer.from(imageMessage.jpegThumbnail)
|
|
71
|
+
: undefined;
|
|
72
|
+
urlInfo.highQualityThumbnail = imageMessage || undefined;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
try {
|
|
76
|
+
urlInfo.jpegThumbnail = image
|
|
77
|
+
? (await getCompressedJpegThumbnail(image, opts)).buffer
|
|
78
|
+
: undefined;
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
(_a = opts.logger) === null || _a === void 0 ? void 0 : _a.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return urlInfo;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (!error.message.includes('receive a valid')) {
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
exports.getUrlInfo = getUrlInfo;
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
const pino_1 = __importDefault(require("pino"));
|
|
7
|
+
exports.default = (0, pino_1.default)({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare class d {
|
|
2
|
+
salt: string;
|
|
3
|
+
constructor(e: string);
|
|
4
|
+
add(e: any, t: any): any;
|
|
5
|
+
subtract(e: any, t: any): any;
|
|
6
|
+
subtractThenAdd(e: any, t: any, r: any): any;
|
|
7
|
+
_addSingle(e: any, t: any): ArrayBuffer;
|
|
8
|
+
_subtractSingle(e: any, t: any): ArrayBuffer;
|
|
9
|
+
performPointwiseWithOverflow(e: any, t: any, r: any): ArrayBuffer;
|
|
10
|
+
}
|
|
11
|
+
export declare const LT_HASH_ANTI_TAMPERING: d;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LT_HASH_ANTI_TAMPERING = void 0;
|
|
4
|
+
const crypto_1 = require("./crypto");
|
|
5
|
+
/**
|
|
6
|
+
* LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
|
|
7
|
+
* over a series of mutations. You can add/remove mutations and it'll return a hash equal to
|
|
8
|
+
* if the same series of mutations was made sequentially.
|
|
9
|
+
*/
|
|
10
|
+
const o = 128;
|
|
11
|
+
class d {
|
|
12
|
+
constructor(e) {
|
|
13
|
+
this.salt = e;
|
|
14
|
+
}
|
|
15
|
+
add(e, t) {
|
|
16
|
+
var r = this;
|
|
17
|
+
for (const item of t) {
|
|
18
|
+
e = r._addSingle(e, item);
|
|
19
|
+
}
|
|
20
|
+
return e;
|
|
21
|
+
}
|
|
22
|
+
subtract(e, t) {
|
|
23
|
+
var r = this;
|
|
24
|
+
for (const item of t) {
|
|
25
|
+
e = r._subtractSingle(e, item);
|
|
26
|
+
}
|
|
27
|
+
return e;
|
|
28
|
+
}
|
|
29
|
+
subtractThenAdd(e, t, r) {
|
|
30
|
+
var n = this;
|
|
31
|
+
return n.add(n.subtract(e, r), t);
|
|
32
|
+
}
|
|
33
|
+
_addSingle(e, t) {
|
|
34
|
+
var r = this;
|
|
35
|
+
const n = new Uint8Array((0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
|
|
36
|
+
return r.performPointwiseWithOverflow(e, n, ((e, t) => e + t));
|
|
37
|
+
}
|
|
38
|
+
_subtractSingle(e, t) {
|
|
39
|
+
var r = this;
|
|
40
|
+
const n = new Uint8Array((0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
|
|
41
|
+
return r.performPointwiseWithOverflow(e, n, ((e, t) => e - t));
|
|
42
|
+
}
|
|
43
|
+
performPointwiseWithOverflow(e, t, r) {
|
|
44
|
+
const n = new DataView(e), i = new DataView(t), a = new ArrayBuffer(n.byteLength), s = new DataView(a);
|
|
45
|
+
for (let e = 0; e < n.byteLength; e += 2) {
|
|
46
|
+
s.setUint16(e, r(n.getUint16(e, !0), i.getUint16(e, !0)), !0);
|
|
47
|
+
}
|
|
48
|
+
return a;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.LT_HASH_ANTI_TAMPERING = new d('WhatsApp Patch Integrity');
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeKeyedMutex = exports.makeMutex = void 0;
|
|
4
|
+
const makeMutex = () => {
|
|
5
|
+
let task = Promise.resolve();
|
|
6
|
+
let taskTimeout;
|
|
7
|
+
return {
|
|
8
|
+
mutex(code) {
|
|
9
|
+
task = (async () => {
|
|
10
|
+
// wait for the previous task to complete
|
|
11
|
+
// if there is an error, we swallow so as to not block the queue
|
|
12
|
+
try {
|
|
13
|
+
await task;
|
|
14
|
+
}
|
|
15
|
+
catch (_a) { }
|
|
16
|
+
try {
|
|
17
|
+
// execute the current task
|
|
18
|
+
const result = await code();
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
clearTimeout(taskTimeout);
|
|
23
|
+
}
|
|
24
|
+
})();
|
|
25
|
+
// we replace the existing task, appending the new piece of execution to it
|
|
26
|
+
// so the next task will have to wait for this one to finish
|
|
27
|
+
return task;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
exports.makeMutex = makeMutex;
|
|
32
|
+
const makeKeyedMutex = () => {
|
|
33
|
+
const map = {};
|
|
34
|
+
return {
|
|
35
|
+
mutex(key, task) {
|
|
36
|
+
if (!map[key]) {
|
|
37
|
+
map[key] = (0, exports.makeMutex)();
|
|
38
|
+
}
|
|
39
|
+
return map[key].mutex(task);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
exports.makeKeyedMutex = makeKeyedMutex;
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LANGUAGE_KEYWORDS = exports.PYTHON_KEYWORDS = exports.JS_KEYWORDS = exports.RichSubMessageType = exports.CodeHighlightType = void 0;
|
|
4
|
+
exports.tokenizeCode = tokenizeCode;
|
|
5
|
+
exports.buildRichContextInfo = buildRichContextInfo;
|
|
6
|
+
exports.buildBotForwardedMessage = buildBotForwardedMessage;
|
|
7
|
+
exports.generateTableContent = generateTableContent;
|
|
8
|
+
exports.generateListContent = generateListContent;
|
|
9
|
+
exports.generateCodeBlockContent = generateCodeBlockContent;
|
|
10
|
+
exports.generateLatexContent = generateLatexContent;
|
|
11
|
+
exports.generateLatexImageContent = generateLatexImageContent;
|
|
12
|
+
exports.generateLatexInlineImageContent = generateLatexInlineImageContent;
|
|
13
|
+
exports.captureUnifiedResponse = captureUnifiedResponse;
|
|
14
|
+
exports.generateUnifiedResponseContent = generateUnifiedResponseContent;
|
|
15
|
+
exports.generateRichMessageContent = generateRichMessageContent;
|
|
16
|
+
const generics_1 = require("./generics");
|
|
17
|
+
const JS_KEYWORDS = new Set([
|
|
18
|
+
'import', 'export', 'from', 'default', 'as', 'const', 'let', 'var',
|
|
19
|
+
'function', 'class', 'extends', 'new', 'return', 'if', 'else', 'for',
|
|
20
|
+
'while', 'do', 'switch', 'case', 'break', 'continue', 'try', 'catch',
|
|
21
|
+
'finally', 'throw', 'async', 'await', 'yield', 'typeof', 'instanceof',
|
|
22
|
+
'in', 'of', 'delete', 'void', 'true', 'false', 'null', 'undefined',
|
|
23
|
+
'NaN', 'Infinity', 'this', 'super', 'static', 'get', 'set', 'debugger', 'with'
|
|
24
|
+
]);
|
|
25
|
+
exports.JS_KEYWORDS = JS_KEYWORDS;
|
|
26
|
+
const PYTHON_KEYWORDS = new Set([
|
|
27
|
+
'import', 'from', 'as', 'def', 'class', 'return', 'if', 'elif', 'else',
|
|
28
|
+
'for', 'while', 'break', 'continue', 'try', 'except', 'finally', 'raise',
|
|
29
|
+
'with', 'yield', 'lambda', 'pass', 'del', 'global', 'nonlocal', 'assert',
|
|
30
|
+
'True', 'False', 'None', 'and', 'or', 'not', 'in', 'is', 'async', 'await',
|
|
31
|
+
'self', 'print'
|
|
32
|
+
]);
|
|
33
|
+
exports.PYTHON_KEYWORDS = PYTHON_KEYWORDS;
|
|
34
|
+
const LANGUAGE_KEYWORDS = {
|
|
35
|
+
javascript: JS_KEYWORDS,
|
|
36
|
+
typescript: JS_KEYWORDS,
|
|
37
|
+
js: JS_KEYWORDS,
|
|
38
|
+
ts: JS_KEYWORDS,
|
|
39
|
+
python: PYTHON_KEYWORDS,
|
|
40
|
+
py: PYTHON_KEYWORDS
|
|
41
|
+
};
|
|
42
|
+
exports.LANGUAGE_KEYWORDS = LANGUAGE_KEYWORDS;
|
|
43
|
+
var CodeHighlightType;
|
|
44
|
+
(function (CodeHighlightType) {
|
|
45
|
+
CodeHighlightType[CodeHighlightType['DEFAULT'] = 0] = 'DEFAULT';
|
|
46
|
+
CodeHighlightType[CodeHighlightType['KEYWORD'] = 1] = 'KEYWORD';
|
|
47
|
+
CodeHighlightType[CodeHighlightType['METHOD'] = 2] = 'METHOD';
|
|
48
|
+
CodeHighlightType[CodeHighlightType['STRING'] = 3] = 'STRING';
|
|
49
|
+
CodeHighlightType[CodeHighlightType['NUMBER'] = 4] = 'NUMBER';
|
|
50
|
+
CodeHighlightType[CodeHighlightType['COMMENT'] = 5] = 'COMMENT';
|
|
51
|
+
})(CodeHighlightType || (exports.CodeHighlightType = CodeHighlightType = {}));
|
|
52
|
+
var RichSubMessageType;
|
|
53
|
+
(function (RichSubMessageType) {
|
|
54
|
+
RichSubMessageType[RichSubMessageType['UNKNOWN'] = 0] = 'UNKNOWN';
|
|
55
|
+
RichSubMessageType[RichSubMessageType['GRID_IMAGE'] = 1] = 'GRID_IMAGE';
|
|
56
|
+
RichSubMessageType[RichSubMessageType['TEXT'] = 2] = 'TEXT';
|
|
57
|
+
RichSubMessageType[RichSubMessageType['INLINE_IMAGE'] = 3] = 'INLINE_IMAGE';
|
|
58
|
+
RichSubMessageType[RichSubMessageType['TABLE'] = 4] = 'TABLE';
|
|
59
|
+
RichSubMessageType[RichSubMessageType['CODE'] = 5] = 'CODE';
|
|
60
|
+
RichSubMessageType[RichSubMessageType['DYNAMIC'] = 6] = 'DYNAMIC';
|
|
61
|
+
RichSubMessageType[RichSubMessageType['MAP'] = 7] = 'MAP';
|
|
62
|
+
RichSubMessageType[RichSubMessageType['LATEX'] = 8] = 'LATEX';
|
|
63
|
+
RichSubMessageType[RichSubMessageType['CONTENT_ITEMS'] = 9] = 'CONTENT_ITEMS';
|
|
64
|
+
})(RichSubMessageType || (exports.RichSubMessageType = RichSubMessageType = {}));
|
|
65
|
+
function tokenizeCode(codeStr, language = 'javascript') {
|
|
66
|
+
const keywords = LANGUAGE_KEYWORDS[language] || JS_KEYWORDS;
|
|
67
|
+
const blocks = [];
|
|
68
|
+
const lines = codeStr.split('\n');
|
|
69
|
+
for (let li = 0; li < lines.length; li++) {
|
|
70
|
+
const line = lines[li];
|
|
71
|
+
const isLast = li === lines.length - 1;
|
|
72
|
+
const nl = isLast ? '' : '\n';
|
|
73
|
+
if (!line.trim()) {
|
|
74
|
+
blocks.push({ highlightType: CodeHighlightType.DEFAULT, codeContent: line + nl });
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (line.trim().startsWith('//') || line.trim().startsWith('#')) {
|
|
78
|
+
blocks.push({ highlightType: CodeHighlightType.COMMENT, codeContent: line + nl });
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const regex = /(\/\/.*$|#.*$)|(["'`](?:[^"'`\\]|\\.)*["'`])|(\b\d+(?:\.\d+)?\b)|(\b[a-zA-Z_$][\w$]*\b)|([^\s\w$"'`]+)|(\s+)/g;
|
|
82
|
+
let match;
|
|
83
|
+
const tokens = [];
|
|
84
|
+
while ((match = regex.exec(line)) !== null) {
|
|
85
|
+
const val = match[0];
|
|
86
|
+
if (match[1]) {
|
|
87
|
+
tokens.push({ highlightType: CodeHighlightType.COMMENT, codeContent: val });
|
|
88
|
+
}
|
|
89
|
+
else if (match[2]) {
|
|
90
|
+
tokens.push({ highlightType: CodeHighlightType.STRING, codeContent: val });
|
|
91
|
+
}
|
|
92
|
+
else if (match[3]) {
|
|
93
|
+
tokens.push({ highlightType: CodeHighlightType.NUMBER, codeContent: val });
|
|
94
|
+
}
|
|
95
|
+
else if (match[4]) {
|
|
96
|
+
if (keywords.has(val)) {
|
|
97
|
+
tokens.push({ highlightType: CodeHighlightType.KEYWORD, codeContent: val });
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
const after = line.slice(regex.lastIndex).trimStart();
|
|
101
|
+
if (after.startsWith('(')) {
|
|
102
|
+
tokens.push({ highlightType: CodeHighlightType.METHOD, codeContent: val });
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
tokens.push({ highlightType: CodeHighlightType.DEFAULT, codeContent: val });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
tokens.push({ highlightType: CodeHighlightType.DEFAULT, codeContent: val });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (tokens.length === 0) {
|
|
114
|
+
blocks.push({ highlightType: CodeHighlightType.DEFAULT, codeContent: line + nl });
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const merged = [];
|
|
118
|
+
for (const t of tokens) {
|
|
119
|
+
const prev = merged.length > 0 ? merged[merged.length - 1] : undefined;
|
|
120
|
+
if (prev && prev.highlightType === t.highlightType) {
|
|
121
|
+
prev.codeContent += t.codeContent;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
merged.push({ ...t });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (merged.length > 0) {
|
|
128
|
+
merged[merged.length - 1].codeContent += nl;
|
|
129
|
+
}
|
|
130
|
+
blocks.push(...merged);
|
|
131
|
+
}
|
|
132
|
+
return blocks;
|
|
133
|
+
}
|
|
134
|
+
function buildRichContextInfo(quoted, options) {
|
|
135
|
+
const ctxInfo = {
|
|
136
|
+
forwardingScore: 1,
|
|
137
|
+
isForwarded: true,
|
|
138
|
+
forwardedAiBotMessageInfo: { botJid: (options === null || options === void 0 ? void 0 : options.botJid) ? options.botJid : '867051314767696@bot' },
|
|
139
|
+
forwardOrigin: 4,
|
|
140
|
+
...((options === null || options === void 0 ? void 0 : options.mentions) ? { mentionedJid: options.mentions } : {})
|
|
141
|
+
};
|
|
142
|
+
if (quoted === null || quoted === void 0 ? void 0 : quoted.key) {
|
|
143
|
+
ctxInfo.stanzaId = quoted.key.id;
|
|
144
|
+
ctxInfo.participant = quoted.key.participant || quoted.sender || quoted.key.remoteJid;
|
|
145
|
+
ctxInfo.quotedMessage = quoted.message;
|
|
146
|
+
}
|
|
147
|
+
return ctxInfo;
|
|
148
|
+
}
|
|
149
|
+
function buildBotForwardedMessage(submessages, contextInfo, unifiedResponse) {
|
|
150
|
+
const richResponse = { messageType: 1, submessages, contextInfo };
|
|
151
|
+
if (unifiedResponse) {
|
|
152
|
+
richResponse.unifiedResponse = unifiedResponse;
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
botForwardedMessage: {
|
|
156
|
+
message: { richResponseMessage: richResponse }
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function generateTableContent(title, headers, rows, quoted, options = {}) {
|
|
161
|
+
const { footer, headerText } = options;
|
|
162
|
+
const tableRows = [{ items: headers, isHeading: true }, ...rows.map(row => ({ items: row.map(String) }))];
|
|
163
|
+
const submessages = [];
|
|
164
|
+
if (headerText)
|
|
165
|
+
submessages.push({ messageType: 2, messageText: headerText });
|
|
166
|
+
submessages.push({ messageType: 4, tableMetadata: { title, rows: tableRows } });
|
|
167
|
+
if (footer)
|
|
168
|
+
submessages.push({ messageType: 2, messageText: footer });
|
|
169
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
170
|
+
return { message: buildBotForwardedMessage(submessages, ctxInfo), messageId: (0, generics_1.generateMessageIDV2)() };
|
|
171
|
+
}
|
|
172
|
+
function generateListContent(title, items, quoted, options = {}) {
|
|
173
|
+
const { footer, headerText } = options;
|
|
174
|
+
const tableRows = items.map(item => ({
|
|
175
|
+
items: Array.isArray(item) ? item.map(String) : [String(item)]
|
|
176
|
+
}));
|
|
177
|
+
const submessages = [];
|
|
178
|
+
if (headerText)
|
|
179
|
+
submessages.push({ messageType: 2, messageText: headerText });
|
|
180
|
+
submessages.push({ messageType: 4, tableMetadata: { title, rows: tableRows } });
|
|
181
|
+
if (footer)
|
|
182
|
+
submessages.push({ messageType: 2, messageText: footer });
|
|
183
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
184
|
+
return { message: buildBotForwardedMessage(submessages, ctxInfo), messageId: (0, generics_1.generateMessageIDV2)() };
|
|
185
|
+
}
|
|
186
|
+
function generateCodeBlockContent(code, quoted, options = {}) {
|
|
187
|
+
const { title, footer, language = 'javascript' } = options;
|
|
188
|
+
const submessages = [];
|
|
189
|
+
if (title)
|
|
190
|
+
submessages.push({ messageType: 2, messageText: title });
|
|
191
|
+
submessages.push({
|
|
192
|
+
messageType: 5,
|
|
193
|
+
codeMetadata: { codeLanguage: language, codeBlocks: tokenizeCode(code, language) }
|
|
194
|
+
});
|
|
195
|
+
if (footer)
|
|
196
|
+
submessages.push({ messageType: 2, messageText: footer });
|
|
197
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
198
|
+
return { message: buildBotForwardedMessage(submessages, ctxInfo), messageId: (0, generics_1.generateMessageIDV2)() };
|
|
199
|
+
}
|
|
200
|
+
function generateLatexContent(quoted, options) {
|
|
201
|
+
const { text, expressions, headerText, footer } = options;
|
|
202
|
+
const submessages = [];
|
|
203
|
+
if (headerText)
|
|
204
|
+
submessages.push({ messageType: 2, messageText: headerText });
|
|
205
|
+
const latexExpressions = expressions.map(expr => {
|
|
206
|
+
const entry = {
|
|
207
|
+
latexExpression: expr.latexExpression,
|
|
208
|
+
url: expr.url,
|
|
209
|
+
width: expr.width,
|
|
210
|
+
height: expr.height
|
|
211
|
+
};
|
|
212
|
+
if (expr.fontHeight !== undefined)
|
|
213
|
+
entry.fontHeight = expr.fontHeight;
|
|
214
|
+
if (expr.imageTopPadding !== undefined)
|
|
215
|
+
entry.imageTopPadding = expr.imageTopPadding;
|
|
216
|
+
if (expr.imageLeadingPadding !== undefined)
|
|
217
|
+
entry.imageLeadingPadding = expr.imageLeadingPadding;
|
|
218
|
+
if (expr.imageBottomPadding !== undefined)
|
|
219
|
+
entry.imageBottomPadding = expr.imageBottomPadding;
|
|
220
|
+
if (expr.imageTrailingPadding !== undefined)
|
|
221
|
+
entry.imageTrailingPadding = expr.imageTrailingPadding;
|
|
222
|
+
return entry;
|
|
223
|
+
});
|
|
224
|
+
submessages.push({ messageType: 8, latexMetadata: { text: text || '', expressions: latexExpressions } });
|
|
225
|
+
if (footer)
|
|
226
|
+
submessages.push({ messageType: 2, messageText: footer });
|
|
227
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
228
|
+
return { message: buildBotForwardedMessage(submessages, ctxInfo), messageId: (0, generics_1.generateMessageIDV2)() };
|
|
229
|
+
}
|
|
230
|
+
async function generateLatexImageContent(quoted, options, uploadFn, renderLatexToPng) {
|
|
231
|
+
const { text, expressions, headerText, footer } = options;
|
|
232
|
+
const submessages = [];
|
|
233
|
+
if (headerText)
|
|
234
|
+
submessages.push({ messageType: 2, messageText: headerText });
|
|
235
|
+
const latexExpressions = await Promise.all(expressions.map(async (expr) => {
|
|
236
|
+
const { buffer, width, height } = await renderLatexToPng(expr.latexExpression);
|
|
237
|
+
const uploadResult = await uploadFn(buffer, 'image');
|
|
238
|
+
const imageUrl = uploadResult.url || uploadResult.directPath;
|
|
239
|
+
return { latexExpression: expr.latexExpression, url: imageUrl, width, height };
|
|
240
|
+
}));
|
|
241
|
+
submessages.push({ messageType: 8, latexMetadata: { text: text || '', expressions: latexExpressions } });
|
|
242
|
+
if (footer)
|
|
243
|
+
submessages.push({ messageType: 2, messageText: footer });
|
|
244
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
245
|
+
return { message: buildBotForwardedMessage(submessages, ctxInfo), messageId: (0, generics_1.generateMessageIDV2)() };
|
|
246
|
+
}
|
|
247
|
+
async function generateLatexInlineImageContent(quoted, options, uploadFn, renderLatexToPng) {
|
|
248
|
+
const { text, expressions, headerText, footer } = options;
|
|
249
|
+
const submessages = [];
|
|
250
|
+
if (headerText)
|
|
251
|
+
submessages.push({ messageType: 2, messageText: headerText });
|
|
252
|
+
if (text)
|
|
253
|
+
submessages.push({ messageType: 2, messageText: text });
|
|
254
|
+
for (const expr of expressions) {
|
|
255
|
+
const { buffer, width, height } = await renderLatexToPng(expr.latexExpression);
|
|
256
|
+
const uploadResult = await uploadFn(buffer, 'image');
|
|
257
|
+
const imageUrl = uploadResult.url || uploadResult.directPath;
|
|
258
|
+
submessages.push({
|
|
259
|
+
messageType: 3,
|
|
260
|
+
imageMetadata: {
|
|
261
|
+
imageUrl: { imagePreviewUrl: imageUrl, imageHighResUrl: imageUrl },
|
|
262
|
+
imageText: expr.latexExpression,
|
|
263
|
+
alignment: 2
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
if (footer)
|
|
268
|
+
submessages.push({ messageType: 2, messageText: footer });
|
|
269
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
270
|
+
return { message: buildBotForwardedMessage(submessages, ctxInfo), messageId: (0, generics_1.generateMessageIDV2)() };
|
|
271
|
+
}
|
|
272
|
+
function captureUnifiedResponse(msg) {
|
|
273
|
+
var _a, _b;
|
|
274
|
+
const botFwd = msg === null || msg === void 0 ? void 0 : (_a = msg.botForwardedMessage) === null || _a === void 0 ? void 0 : _a.message;
|
|
275
|
+
if (!botFwd)
|
|
276
|
+
return null;
|
|
277
|
+
const rich = botFwd.richResponseMessage;
|
|
278
|
+
if (!(rich === null || rich === void 0 ? void 0 : (_b = rich.unifiedResponse) === null || _b === void 0 ? void 0 : _b.data))
|
|
279
|
+
return null;
|
|
280
|
+
return {
|
|
281
|
+
unifiedResponse: { data: rich.unifiedResponse.data },
|
|
282
|
+
submessages: rich.submessages || [],
|
|
283
|
+
contextInfo: rich.contextInfo || {}
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function generateUnifiedResponseContent(quoted, captured) {
|
|
287
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
288
|
+
return { message: buildBotForwardedMessage(captured.submessages, ctxInfo, captured.unifiedResponse), messageId: (0, generics_1.generateMessageIDV2)() };
|
|
289
|
+
}
|
|
290
|
+
function generateRichMessageContent(submessages, quoted, options) {
|
|
291
|
+
const ctxInfo = buildRichContextInfo(quoted, options);
|
|
292
|
+
return { message: buildBotForwardedMessage(submessages, ctxInfo), messageId: (0, generics_1.generateMessageIDV2)() };
|
|
293
|
+
}
|