@queenanya/baileys 6.7.0 → 6.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WASignalGroup/readme.md +6 -0
- package/lib/Defaults/baileys-version.json +3 -3
- package/lib/Defaults/index.d.ts +284 -284
- package/lib/Defaults/index.js +120 -120
- package/lib/Defaults/phonenumber-mcc.json +223 -223
- package/lib/Signal/libsignal.d.ts +3 -3
- package/lib/Signal/libsignal.js +152 -152
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -17
- package/lib/Socket/Client/abstract-socket-client.js +13 -13
- package/lib/Socket/Client/index.d.ts +3 -3
- package/lib/Socket/Client/index.js +19 -19
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -13
- package/lib/Socket/Client/mobile-socket-client.js +65 -65
- package/lib/Socket/Client/web-socket-client.d.ts +12 -12
- package/lib/Socket/Client/web-socket-client.js +62 -62
- package/lib/Socket/business.d.ts +135 -135
- package/lib/Socket/business.js +259 -259
- package/lib/Socket/chats.d.ts +79 -79
- package/lib/Socket/chats.js +854 -854
- package/lib/Socket/groups.d.ts +113 -113
- package/lib/Socket/groups.js +302 -302
- package/lib/Socket/index.d.ts +137 -137
- package/lib/Socket/index.js +10 -10
- package/lib/Socket/messages-recv.d.ts +124 -124
- package/lib/Socket/messages-recv.js +747 -747
- package/lib/Socket/messages-send.d.ts +119 -119
- package/lib/Socket/messages-send.js +663 -663
- package/lib/Socket/registration.d.ts +232 -232
- package/lib/Socket/registration.js +166 -166
- package/lib/Socket/socket.d.ts +42 -42
- package/lib/Socket/socket.js +588 -588
- package/lib/Store/index.d.ts +3 -3
- package/lib/Store/index.js +10 -10
- package/lib/Store/make-cache-manager-store.d.ts +13 -13
- package/lib/Store/make-cache-manager-store.js +83 -83
- package/lib/Store/make-in-memory-store.d.ts +117 -117
- package/lib/Store/make-in-memory-store.js +437 -437
- package/lib/Store/make-ordered-dictionary.d.ts +13 -13
- package/lib/Store/make-ordered-dictionary.js +81 -81
- package/lib/Store/object-repository.d.ts +10 -10
- package/lib/Store/object-repository.js +27 -27
- package/lib/Types/Auth.d.ts +108 -108
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +13 -13
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +102 -102
- package/lib/Types/Chat.js +4 -4
- package/lib/Types/Contact.d.ts +19 -19
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +157 -157
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +52 -52
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +35 -35
- package/lib/Types/Label.js +27 -27
- package/lib/Types/LabelAssociation.d.ts +29 -29
- package/lib/Types/LabelAssociation.js +9 -9
- package/lib/Types/Message.d.ts +261 -261
- package/lib/Types/Message.js +9 -9
- package/lib/Types/Product.d.ts +78 -78
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +57 -57
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +111 -111
- package/lib/Types/Socket.js +2 -2
- package/lib/Types/State.d.ts +27 -27
- package/lib/Types/State.js +2 -2
- package/lib/Types/index.d.ts +56 -56
- package/lib/Types/index.js +41 -41
- package/lib/Utils/auth-utils.d.ts +18 -18
- package/lib/Utils/auth-utils.js +204 -204
- package/lib/Utils/baileys-event-stream.d.ts +16 -16
- package/lib/Utils/baileys-event-stream.js +63 -63
- package/lib/Utils/business.d.ts +22 -22
- package/lib/Utils/business.js +234 -234
- package/lib/Utils/chat-utils.d.ts +71 -71
- package/lib/Utils/chat-utils.js +724 -724
- package/lib/Utils/crypto.d.ts +41 -41
- package/lib/Utils/crypto.js +151 -151
- package/lib/Utils/decode-wa-message.d.ts +19 -19
- package/lib/Utils/decode-wa-message.js +174 -174
- package/lib/Utils/event-buffer.d.ts +35 -35
- package/lib/Utils/event-buffer.js +514 -514
- package/lib/Utils/generics.d.ts +94 -94
- package/lib/Utils/generics.js +367 -367
- package/lib/Utils/history.d.ts +15 -15
- package/lib/Utils/history.js +91 -91
- package/lib/Utils/index.d.ts +17 -17
- package/lib/Utils/index.js +33 -33
- package/lib/Utils/link-preview.d.ts +21 -21
- package/lib/Utils/link-preview.js +93 -93
- package/lib/Utils/logger.d.ts +4 -4
- package/lib/Utils/logger.js +7 -7
- package/lib/Utils/lt-hash.d.ts +12 -12
- package/lib/Utils/lt-hash.js +51 -51
- package/lib/Utils/make-mutex.d.ts +7 -7
- package/lib/Utils/make-mutex.js +43 -43
- package/lib/Utils/messages-media.d.ts +107 -107
- package/lib/Utils/messages-media.js +680 -680
- package/lib/Utils/messages.d.ts +76 -76
- package/lib/Utils/messages.js +768 -768
- package/lib/Utils/noise-handler.d.ts +20 -20
- package/lib/Utils/noise-handler.js +142 -142
- package/lib/Utils/process-message.d.ts +41 -41
- package/lib/Utils/process-message.js +320 -320
- package/lib/Utils/signal.d.ts +32 -32
- package/lib/Utils/signal.js +151 -151
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -12
- package/lib/Utils/use-multi-file-auth-state.js +80 -80
- package/lib/Utils/validate-connection.d.ts +11 -11
- package/lib/Utils/validate-connection.js +191 -222
- package/lib/WABinary/constants.d.ts +27 -27
- package/lib/WABinary/constants.js +40 -40
- package/lib/WABinary/decode.d.ts +7 -7
- package/lib/WABinary/decode.js +252 -252
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +228 -228
- package/lib/WABinary/generic-utils.d.ts +15 -15
- package/lib/WABinary/generic-utils.js +110 -110
- package/lib/WABinary/index.d.ts +5 -5
- package/lib/WABinary/index.js +21 -21
- package/lib/WABinary/jid-utils.d.ts +29 -29
- package/lib/WABinary/jid-utils.js +59 -59
- package/lib/WABinary/types.d.ts +18 -18
- package/lib/WABinary/types.js +2 -2
- package/lib/index.d.ts +10 -10
- package/lib/index.js +29 -29
- package/package.json +1 -1
- package/CHANGELOG.md +0 -4
package/lib/Utils/history.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { proto } from '../../WAProto';
|
|
3
|
-
import { Chat, Contact } from '../Types';
|
|
4
|
-
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
|
|
5
|
-
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
6
|
-
chats: Chat[];
|
|
7
|
-
contacts: Contact[];
|
|
8
|
-
messages: proto.IWebMessageInfo[];
|
|
9
|
-
};
|
|
10
|
-
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
|
|
11
|
-
chats: Chat[];
|
|
12
|
-
contacts: Contact[];
|
|
13
|
-
messages: proto.IWebMessageInfo[];
|
|
14
|
-
}>;
|
|
15
|
-
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { proto } from '../../WAProto';
|
|
3
|
+
import { Chat, Contact } from '../Types';
|
|
4
|
+
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
|
|
5
|
+
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
6
|
+
chats: Chat[];
|
|
7
|
+
contacts: Contact[];
|
|
8
|
+
messages: proto.IWebMessageInfo[];
|
|
9
|
+
};
|
|
10
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
|
|
11
|
+
chats: Chat[];
|
|
12
|
+
contacts: Contact[];
|
|
13
|
+
messages: proto.IWebMessageInfo[];
|
|
14
|
+
}>;
|
|
15
|
+
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
|
package/lib/Utils/history.js
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getHistoryMsg = exports.downloadAndProcessHistorySyncNotification = exports.processHistoryMessage = exports.downloadHistory = void 0;
|
|
4
|
-
const util_1 = require("util");
|
|
5
|
-
const zlib_1 = require("zlib");
|
|
6
|
-
const WAProto_1 = require("../../WAProto");
|
|
7
|
-
const Types_1 = require("../Types");
|
|
8
|
-
const WABinary_1 = require("../WABinary");
|
|
9
|
-
const generics_1 = require("./generics");
|
|
10
|
-
const messages_1 = require("./messages");
|
|
11
|
-
const messages_media_1 = require("./messages-media");
|
|
12
|
-
const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
|
|
13
|
-
const downloadHistory = async (msg, options) => {
|
|
14
|
-
const stream = await (0, messages_media_1.downloadContentFromMessage)(msg, 'md-msg-hist', { options });
|
|
15
|
-
const bufferArray = [];
|
|
16
|
-
for await (const chunk of stream) {
|
|
17
|
-
bufferArray.push(chunk);
|
|
18
|
-
}
|
|
19
|
-
let buffer = Buffer.concat(bufferArray);
|
|
20
|
-
// decompress buffer
|
|
21
|
-
buffer = await inflatePromise(buffer);
|
|
22
|
-
const syncData = WAProto_1.proto.HistorySync.decode(buffer);
|
|
23
|
-
return syncData;
|
|
24
|
-
};
|
|
25
|
-
exports.downloadHistory = downloadHistory;
|
|
26
|
-
const processHistoryMessage = (item) => {
|
|
27
|
-
var _a, _b, _c;
|
|
28
|
-
const messages = [];
|
|
29
|
-
const contacts = [];
|
|
30
|
-
const chats = [];
|
|
31
|
-
switch (item.syncType) {
|
|
32
|
-
case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
33
|
-
case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
|
|
34
|
-
case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
|
|
35
|
-
for (const chat of item.conversations) {
|
|
36
|
-
contacts.push({ id: chat.id, name: chat.name || undefined });
|
|
37
|
-
const msgs = chat.messages || [];
|
|
38
|
-
delete chat.messages;
|
|
39
|
-
delete chat.archived;
|
|
40
|
-
delete chat.muteEndTime;
|
|
41
|
-
delete chat.pinned;
|
|
42
|
-
for (const item of msgs) {
|
|
43
|
-
const message = item.message;
|
|
44
|
-
messages.push(message);
|
|
45
|
-
if (!((_a = chat.messages) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
46
|
-
// keep only the most recent message in the chat array
|
|
47
|
-
chat.messages = [{ message }];
|
|
48
|
-
}
|
|
49
|
-
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
50
|
-
chat.lastMessageRecvTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
|
|
51
|
-
}
|
|
52
|
-
if ((message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
|
|
53
|
-
|| message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB)
|
|
54
|
-
&& ((_b = message.messageStubParameters) === null || _b === void 0 ? void 0 : _b[0])) {
|
|
55
|
-
contacts.push({
|
|
56
|
-
id: message.key.participant || message.key.remoteJid,
|
|
57
|
-
verifiedName: (_c = message.messageStubParameters) === null || _c === void 0 ? void 0 : _c[0],
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if ((0, WABinary_1.isJidUser)(chat.id) && chat.readOnly && chat.archived) {
|
|
62
|
-
delete chat.readOnly;
|
|
63
|
-
}
|
|
64
|
-
chats.push({ ...chat });
|
|
65
|
-
}
|
|
66
|
-
break;
|
|
67
|
-
case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
68
|
-
for (const c of item.pushnames) {
|
|
69
|
-
contacts.push({ id: c.id, notify: c.pushname });
|
|
70
|
-
}
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
chats,
|
|
75
|
-
contacts,
|
|
76
|
-
messages,
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
exports.processHistoryMessage = processHistoryMessage;
|
|
80
|
-
const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
81
|
-
const historyMsg = await (0, exports.downloadHistory)(msg, options);
|
|
82
|
-
return (0, exports.processHistoryMessage)(historyMsg);
|
|
83
|
-
};
|
|
84
|
-
exports.downloadAndProcessHistorySyncNotification = downloadAndProcessHistorySyncNotification;
|
|
85
|
-
const getHistoryMsg = (message) => {
|
|
86
|
-
var _a;
|
|
87
|
-
const normalizedContent = !!message ? (0, messages_1.normalizeMessageContent)(message) : undefined;
|
|
88
|
-
const anyHistoryMsg = (_a = normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.protocolMessage) === null || _a === void 0 ? void 0 : _a.historySyncNotification;
|
|
89
|
-
return anyHistoryMsg;
|
|
90
|
-
};
|
|
91
|
-
exports.getHistoryMsg = getHistoryMsg;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHistoryMsg = exports.downloadAndProcessHistorySyncNotification = exports.processHistoryMessage = exports.downloadHistory = void 0;
|
|
4
|
+
const util_1 = require("util");
|
|
5
|
+
const zlib_1 = require("zlib");
|
|
6
|
+
const WAProto_1 = require("../../WAProto");
|
|
7
|
+
const Types_1 = require("../Types");
|
|
8
|
+
const WABinary_1 = require("../WABinary");
|
|
9
|
+
const generics_1 = require("./generics");
|
|
10
|
+
const messages_1 = require("./messages");
|
|
11
|
+
const messages_media_1 = require("./messages-media");
|
|
12
|
+
const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
|
|
13
|
+
const downloadHistory = async (msg, options) => {
|
|
14
|
+
const stream = await (0, messages_media_1.downloadContentFromMessage)(msg, 'md-msg-hist', { options });
|
|
15
|
+
const bufferArray = [];
|
|
16
|
+
for await (const chunk of stream) {
|
|
17
|
+
bufferArray.push(chunk);
|
|
18
|
+
}
|
|
19
|
+
let buffer = Buffer.concat(bufferArray);
|
|
20
|
+
// decompress buffer
|
|
21
|
+
buffer = await inflatePromise(buffer);
|
|
22
|
+
const syncData = WAProto_1.proto.HistorySync.decode(buffer);
|
|
23
|
+
return syncData;
|
|
24
|
+
};
|
|
25
|
+
exports.downloadHistory = downloadHistory;
|
|
26
|
+
const processHistoryMessage = (item) => {
|
|
27
|
+
var _a, _b, _c;
|
|
28
|
+
const messages = [];
|
|
29
|
+
const contacts = [];
|
|
30
|
+
const chats = [];
|
|
31
|
+
switch (item.syncType) {
|
|
32
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
33
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
|
|
34
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
|
|
35
|
+
for (const chat of item.conversations) {
|
|
36
|
+
contacts.push({ id: chat.id, name: chat.name || undefined });
|
|
37
|
+
const msgs = chat.messages || [];
|
|
38
|
+
delete chat.messages;
|
|
39
|
+
delete chat.archived;
|
|
40
|
+
delete chat.muteEndTime;
|
|
41
|
+
delete chat.pinned;
|
|
42
|
+
for (const item of msgs) {
|
|
43
|
+
const message = item.message;
|
|
44
|
+
messages.push(message);
|
|
45
|
+
if (!((_a = chat.messages) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
46
|
+
// keep only the most recent message in the chat array
|
|
47
|
+
chat.messages = [{ message }];
|
|
48
|
+
}
|
|
49
|
+
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
50
|
+
chat.lastMessageRecvTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
|
|
51
|
+
}
|
|
52
|
+
if ((message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
|
|
53
|
+
|| message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB)
|
|
54
|
+
&& ((_b = message.messageStubParameters) === null || _b === void 0 ? void 0 : _b[0])) {
|
|
55
|
+
contacts.push({
|
|
56
|
+
id: message.key.participant || message.key.remoteJid,
|
|
57
|
+
verifiedName: (_c = message.messageStubParameters) === null || _c === void 0 ? void 0 : _c[0],
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if ((0, WABinary_1.isJidUser)(chat.id) && chat.readOnly && chat.archived) {
|
|
62
|
+
delete chat.readOnly;
|
|
63
|
+
}
|
|
64
|
+
chats.push({ ...chat });
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
68
|
+
for (const c of item.pushnames) {
|
|
69
|
+
contacts.push({ id: c.id, notify: c.pushname });
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
chats,
|
|
75
|
+
contacts,
|
|
76
|
+
messages,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
exports.processHistoryMessage = processHistoryMessage;
|
|
80
|
+
const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
81
|
+
const historyMsg = await (0, exports.downloadHistory)(msg, options);
|
|
82
|
+
return (0, exports.processHistoryMessage)(historyMsg);
|
|
83
|
+
};
|
|
84
|
+
exports.downloadAndProcessHistorySyncNotification = downloadAndProcessHistorySyncNotification;
|
|
85
|
+
const getHistoryMsg = (message) => {
|
|
86
|
+
var _a;
|
|
87
|
+
const normalizedContent = !!message ? (0, messages_1.normalizeMessageContent)(message) : undefined;
|
|
88
|
+
const anyHistoryMsg = (_a = normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.protocolMessage) === null || _a === void 0 ? void 0 : _a.historySyncNotification;
|
|
89
|
+
return anyHistoryMsg;
|
|
90
|
+
};
|
|
91
|
+
exports.getHistoryMsg = getHistoryMsg;
|
package/lib/Utils/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export * from './generics';
|
|
2
|
-
export * from './decode-wa-message';
|
|
3
|
-
export * from './messages';
|
|
4
|
-
export * from './messages-media';
|
|
5
|
-
export * from './validate-connection';
|
|
6
|
-
export * from './crypto';
|
|
7
|
-
export * from './signal';
|
|
8
|
-
export * from './noise-handler';
|
|
9
|
-
export * from './history';
|
|
10
|
-
export * from './chat-utils';
|
|
11
|
-
export * from './lt-hash';
|
|
12
|
-
export * from './auth-utils';
|
|
13
|
-
export * from './baileys-event-stream';
|
|
14
|
-
export * from './use-multi-file-auth-state';
|
|
15
|
-
export * from './link-preview';
|
|
16
|
-
export * from './event-buffer';
|
|
17
|
-
export * from './process-message';
|
|
1
|
+
export * from './generics';
|
|
2
|
+
export * from './decode-wa-message';
|
|
3
|
+
export * from './messages';
|
|
4
|
+
export * from './messages-media';
|
|
5
|
+
export * from './validate-connection';
|
|
6
|
+
export * from './crypto';
|
|
7
|
+
export * from './signal';
|
|
8
|
+
export * from './noise-handler';
|
|
9
|
+
export * from './history';
|
|
10
|
+
export * from './chat-utils';
|
|
11
|
+
export * from './lt-hash';
|
|
12
|
+
export * from './auth-utils';
|
|
13
|
+
export * from './baileys-event-stream';
|
|
14
|
+
export * from './use-multi-file-auth-state';
|
|
15
|
+
export * from './link-preview';
|
|
16
|
+
export * from './event-buffer';
|
|
17
|
+
export * from './process-message';
|
package/lib/Utils/index.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./generics"), exports);
|
|
18
|
-
__exportStar(require("./decode-wa-message"), exports);
|
|
19
|
-
__exportStar(require("./messages"), exports);
|
|
20
|
-
__exportStar(require("./messages-media"), exports);
|
|
21
|
-
__exportStar(require("./validate-connection"), exports);
|
|
22
|
-
__exportStar(require("./crypto"), exports);
|
|
23
|
-
__exportStar(require("./signal"), exports);
|
|
24
|
-
__exportStar(require("./noise-handler"), exports);
|
|
25
|
-
__exportStar(require("./history"), exports);
|
|
26
|
-
__exportStar(require("./chat-utils"), exports);
|
|
27
|
-
__exportStar(require("./lt-hash"), exports);
|
|
28
|
-
__exportStar(require("./auth-utils"), exports);
|
|
29
|
-
__exportStar(require("./baileys-event-stream"), exports);
|
|
30
|
-
__exportStar(require("./use-multi-file-auth-state"), exports);
|
|
31
|
-
__exportStar(require("./link-preview"), exports);
|
|
32
|
-
__exportStar(require("./event-buffer"), exports);
|
|
33
|
-
__exportStar(require("./process-message"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./generics"), exports);
|
|
18
|
+
__exportStar(require("./decode-wa-message"), exports);
|
|
19
|
+
__exportStar(require("./messages"), exports);
|
|
20
|
+
__exportStar(require("./messages-media"), exports);
|
|
21
|
+
__exportStar(require("./validate-connection"), exports);
|
|
22
|
+
__exportStar(require("./crypto"), exports);
|
|
23
|
+
__exportStar(require("./signal"), exports);
|
|
24
|
+
__exportStar(require("./noise-handler"), exports);
|
|
25
|
+
__exportStar(require("./history"), exports);
|
|
26
|
+
__exportStar(require("./chat-utils"), exports);
|
|
27
|
+
__exportStar(require("./lt-hash"), exports);
|
|
28
|
+
__exportStar(require("./auth-utils"), exports);
|
|
29
|
+
__exportStar(require("./baileys-event-stream"), exports);
|
|
30
|
+
__exportStar(require("./use-multi-file-auth-state"), exports);
|
|
31
|
+
__exportStar(require("./link-preview"), exports);
|
|
32
|
+
__exportStar(require("./event-buffer"), exports);
|
|
33
|
+
__exportStar(require("./process-message"), exports);
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { Logger } from 'pino';
|
|
3
|
-
import { WAMediaUploadFunction, WAUrlInfo } from '../Types';
|
|
4
|
-
export type URLGenerationOptions = {
|
|
5
|
-
thumbnailWidth: number;
|
|
6
|
-
fetchOpts: {
|
|
7
|
-
/** Timeout in ms */
|
|
8
|
-
timeout: number;
|
|
9
|
-
proxyUrl?: string;
|
|
10
|
-
headers?: AxiosRequestConfig<{}>['headers'];
|
|
11
|
-
};
|
|
12
|
-
uploadImage?: WAMediaUploadFunction;
|
|
13
|
-
logger?: Logger;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
17
|
-
* Return undefined if the fetch failed or no URL was found
|
|
18
|
-
* @param text first matched URL in text
|
|
19
|
-
* @returns the URL info required to generate link preview
|
|
20
|
-
*/
|
|
21
|
-
export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>;
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { Logger } from 'pino';
|
|
3
|
+
import { WAMediaUploadFunction, WAUrlInfo } from '../Types';
|
|
4
|
+
export type URLGenerationOptions = {
|
|
5
|
+
thumbnailWidth: number;
|
|
6
|
+
fetchOpts: {
|
|
7
|
+
/** Timeout in ms */
|
|
8
|
+
timeout: number;
|
|
9
|
+
proxyUrl?: string;
|
|
10
|
+
headers?: AxiosRequestConfig<{}>['headers'];
|
|
11
|
+
};
|
|
12
|
+
uploadImage?: WAMediaUploadFunction;
|
|
13
|
+
logger?: Logger;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
17
|
+
* Return undefined if the fetch failed or no URL was found
|
|
18
|
+
* @param text first matched URL in text
|
|
19
|
+
* @returns the URL info required to generate link preview
|
|
20
|
+
*/
|
|
21
|
+
export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>;
|
|
@@ -1,93 +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: 'manual',
|
|
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;
|
|
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: 'manual',
|
|
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;
|
package/lib/Utils/logger.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const _default: import("pino").Logger<{
|
|
2
|
-
timestamp: () => string;
|
|
3
|
-
}>;
|
|
4
|
-
export default _default;
|
|
1
|
+
declare const _default: import("pino").Logger<{
|
|
2
|
+
timestamp: () => string;
|
|
3
|
+
}>;
|
|
4
|
+
export default _default;
|
package/lib/Utils/logger.js
CHANGED
|
@@ -1,7 +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()}"` });
|
|
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()}"` });
|
package/lib/Utils/lt-hash.d.ts
CHANGED
|
@@ -1,12 +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 {};
|
|
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 {};
|