wa-multi-mongodb 3.10.2 → 3.10.3
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/dist/Defaults/index.js +4 -9
- package/dist/Error/index.js +1 -5
- package/dist/Messaging/index.d.ts +1 -1
- package/dist/Messaging/index.js +123 -137
- package/dist/Profile/index.d.ts +1 -1
- package/dist/Profile/index.js +6 -10
- package/dist/Socket/index.d.ts +1 -1
- package/dist/Socket/index.d.ts.map +1 -1
- package/dist/Socket/index.js +134 -200
- package/dist/Types/index.js +1 -2
- package/dist/Types/profile.js +1 -2
- package/dist/Utils/create-delay.js +2 -7
- package/dist/Utils/error.js +1 -4
- package/dist/Utils/group-cache.js +8 -15
- package/dist/Utils/index.d.ts +5 -5
- package/dist/Utils/index.js +5 -21
- package/dist/Utils/is-exist.d.ts +1 -1
- package/dist/Utils/is-exist.js +7 -10
- package/dist/Utils/lid-utils.js +13 -20
- package/dist/Utils/message-status.d.ts +1 -1
- package/dist/Utils/message-status.js +7 -11
- package/dist/Utils/mongo-auth-state.js +10 -13
- package/dist/Utils/phone-to-jid.js +6 -14
- package/dist/Utils/save-media.d.ts +1 -1
- package/dist/Utils/save-media.js +16 -26
- package/dist/cjs/Defaults/index.d.ts +21 -0
- package/dist/cjs/Defaults/index.d.ts.map +1 -0
- package/dist/cjs/Defaults/index.js +31 -0
- package/dist/cjs/Error/index.d.ts +5 -0
- package/dist/cjs/Error/index.d.ts.map +1 -0
- package/dist/cjs/Error/index.js +14 -0
- package/dist/cjs/Messaging/index.d.ts +45 -0
- package/dist/cjs/Messaging/index.d.ts.map +1 -0
- package/dist/cjs/Messaging/index.js +784 -0
- package/dist/cjs/Profile/index.d.ts +9 -0
- package/dist/cjs/Profile/index.d.ts.map +1 -0
- package/dist/cjs/Profile/index.js +34 -0
- package/dist/cjs/Socket/index.d.ts +105 -0
- package/dist/cjs/Socket/index.d.ts.map +1 -0
- package/dist/cjs/Socket/index.js +875 -0
- package/dist/cjs/Types/index.d.ts +74 -0
- package/dist/cjs/Types/index.d.ts.map +1 -0
- package/dist/cjs/Types/index.js +2 -0
- package/dist/cjs/Types/profile.d.ts +5 -0
- package/dist/cjs/Types/profile.d.ts.map +1 -0
- package/dist/cjs/Types/profile.js +2 -0
- package/dist/cjs/Utils/create-delay.d.ts +17 -0
- package/dist/cjs/Utils/create-delay.d.ts.map +1 -0
- package/dist/cjs/Utils/create-delay.js +38 -0
- package/dist/cjs/Utils/error.d.ts +4 -0
- package/dist/cjs/Utils/error.d.ts.map +1 -0
- package/dist/cjs/Utils/error.js +8 -0
- package/dist/cjs/Utils/group-cache.d.ts +23 -0
- package/dist/cjs/Utils/group-cache.d.ts.map +1 -0
- package/dist/cjs/Utils/group-cache.js +176 -0
- package/dist/cjs/Utils/index.d.ts +6 -0
- package/dist/cjs/Utils/index.d.ts.map +1 -0
- package/dist/cjs/Utils/index.js +23 -0
- package/dist/cjs/Utils/is-exist.d.ts +6 -0
- package/dist/cjs/Utils/is-exist.d.ts.map +1 -0
- package/dist/cjs/Utils/is-exist.js +53 -0
- package/dist/cjs/Utils/lid-utils.d.ts +26 -0
- package/dist/cjs/Utils/lid-utils.d.ts.map +1 -0
- package/dist/cjs/Utils/lid-utils.js +81 -0
- package/dist/cjs/Utils/message-status.d.ts +4 -0
- package/dist/cjs/Utils/message-status.d.ts.map +1 -0
- package/dist/cjs/Utils/message-status.js +18 -0
- package/dist/cjs/Utils/mongo-auth-state.d.ts +15 -0
- package/dist/cjs/Utils/mongo-auth-state.d.ts.map +1 -0
- package/dist/cjs/Utils/mongo-auth-state.js +109 -0
- package/dist/cjs/Utils/phone-to-jid.d.ts +17 -0
- package/dist/cjs/Utils/phone-to-jid.d.ts.map +1 -0
- package/dist/cjs/Utils/phone-to-jid.js +51 -0
- package/dist/cjs/Utils/save-media.d.ts +6 -0
- package/dist/cjs/Utils/save-media.d.ts.map +1 -0
- package/dist/cjs/Utils/save-media.js +55 -0
- package/dist/cjs/index.d.ts +8 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +46 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +7 -46
- package/package.json +57 -42
package/dist/Types/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/Types/profile.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withTimeout = exports.createDelay = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Create delay for certain milliseconds
|
|
6
3
|
*
|
|
7
4
|
* @param ms - Delay in milliseconds
|
|
8
5
|
* @returns Promise that resolves after the specified delay
|
|
9
6
|
*/
|
|
10
|
-
const createDelay = (ms) => {
|
|
7
|
+
export const createDelay = (ms) => {
|
|
11
8
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
12
9
|
};
|
|
13
|
-
exports.createDelay = createDelay;
|
|
14
10
|
/**
|
|
15
11
|
* Execute a promise with a timeout
|
|
16
12
|
*
|
|
@@ -19,7 +15,7 @@ exports.createDelay = createDelay;
|
|
|
19
15
|
* @param errorMessage - Custom error message for timeout
|
|
20
16
|
* @returns Promise that resolves with the result or rejects with timeout error
|
|
21
17
|
*/
|
|
22
|
-
const withTimeout = (promise, timeoutMs = 10000, errorMessage = 'Operation timed out') => {
|
|
18
|
+
export const withTimeout = (promise, timeoutMs = 10000, errorMessage = 'Operation timed out') => {
|
|
23
19
|
return new Promise((resolve, reject) => {
|
|
24
20
|
const timeoutId = setTimeout(() => {
|
|
25
21
|
reject(new Error(errorMessage));
|
|
@@ -35,4 +31,3 @@ const withTimeout = (promise, timeoutMs = 10000, errorMessage = 'Operation timed
|
|
|
35
31
|
});
|
|
36
32
|
});
|
|
37
33
|
};
|
|
38
|
-
exports.withTimeout = withTimeout;
|
package/dist/Utils/error.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,23 +7,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.groupCache = exports.GroupMetadataCache = void 0;
|
|
16
|
-
const node_cache_1 = __importDefault(require("node-cache"));
|
|
17
|
-
const mongodb_1 = require("mongodb");
|
|
18
|
-
const Defaults_1 = require("../Defaults");
|
|
10
|
+
import NodeCache from "node-cache";
|
|
11
|
+
import { MongoClient } from "mongodb";
|
|
12
|
+
import { CREDENTIALS } from "../Defaults/index.js";
|
|
19
13
|
// Class untuk mengelola cache group metadata dengan pendekatan hybrid (NodeCache + MongoDB)
|
|
20
|
-
class GroupMetadataCache {
|
|
14
|
+
export class GroupMetadataCache {
|
|
21
15
|
// Konstruktor private untuk singleton pattern
|
|
22
16
|
constructor() {
|
|
23
17
|
this.mongoClient = null;
|
|
24
18
|
this.mongoCollection = null;
|
|
25
19
|
this.mongoURI = null;
|
|
26
20
|
// Inisialisasi node-cache dengan standar TTL 5 menit
|
|
27
|
-
this.cache = new
|
|
21
|
+
this.cache = new NodeCache({
|
|
28
22
|
stdTTL: 5 * 60, // 5 menit dalam detik
|
|
29
23
|
checkperiod: 60, // Cek expired keys setiap 1 menit
|
|
30
24
|
useClones: false // Untuk performa lebih baik
|
|
@@ -46,10 +40,10 @@ class GroupMetadataCache {
|
|
|
46
40
|
if (this.mongoClient) {
|
|
47
41
|
yield this.mongoClient.close();
|
|
48
42
|
}
|
|
49
|
-
this.mongoClient = new
|
|
43
|
+
this.mongoClient = new MongoClient(uri);
|
|
50
44
|
yield this.mongoClient.connect();
|
|
51
45
|
// Inisialisasi collection
|
|
52
|
-
const dbName =
|
|
46
|
+
const dbName = CREDENTIALS.MONGO_DB_NAME;
|
|
53
47
|
const collectionName = "group_metadata";
|
|
54
48
|
this.mongoCollection = this.mongoClient.db(dbName).collection(collectionName);
|
|
55
49
|
// Buat indeks pada id grup dan sessionId untuk performa query
|
|
@@ -171,6 +165,5 @@ class GroupMetadataCache {
|
|
|
171
165
|
this.cache.flushAll();
|
|
172
166
|
}
|
|
173
167
|
}
|
|
174
|
-
exports.GroupMetadataCache = GroupMetadataCache;
|
|
175
168
|
// Export singleton instance
|
|
176
|
-
|
|
169
|
+
export const groupCache = GroupMetadataCache.getInstance();
|
package/dist/Utils/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./phone-to-jid";
|
|
2
|
-
export * from "./is-exist";
|
|
3
|
-
export * from "./create-delay";
|
|
4
|
-
export * from "./group-cache";
|
|
5
|
-
export * from "./lid-utils";
|
|
1
|
+
export * from "./phone-to-jid.js";
|
|
2
|
+
export * from "./is-exist.js";
|
|
3
|
+
export * from "./create-delay.js";
|
|
4
|
+
export * from "./group-cache.js";
|
|
5
|
+
export * from "./lid-utils.js";
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/Utils/index.js
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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("./phone-to-jid"), exports);
|
|
18
|
-
__exportStar(require("./is-exist"), exports);
|
|
19
|
-
__exportStar(require("./create-delay"), exports);
|
|
20
|
-
__exportStar(require("./group-cache"), exports);
|
|
21
|
-
__exportStar(require("./lid-utils"), exports);
|
|
1
|
+
export * from "./phone-to-jid.js";
|
|
2
|
+
export * from "./is-exist.js";
|
|
3
|
+
export * from "./create-delay.js";
|
|
4
|
+
export * from "./group-cache.js";
|
|
5
|
+
export * from "./lid-utils.js";
|
|
22
6
|
// Note: setCredentialsDir & setMongoDBNames have been moved to src/Socket/index.ts
|
|
23
7
|
// Please import them directly from there instead
|
package/dist/Utils/is-exist.d.ts
CHANGED
package/dist/Utils/is-exist.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,12 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const phone_to_jid_1 = require("./phone-to-jid");
|
|
16
|
-
function isExist(mediaOrParams) {
|
|
10
|
+
import { WhatsappError } from "../Error/index.js";
|
|
11
|
+
import { getSession } from "../Socket/index.js";
|
|
12
|
+
import { phoneToJid } from "./phone-to-jid.js";
|
|
13
|
+
export function isExist(mediaOrParams) {
|
|
17
14
|
// Jika parameter adalah SendMessageTypes, gunakan fungsi asli
|
|
18
15
|
if (typeof mediaOrParams === 'object' && 'sessionId' in mediaOrParams) {
|
|
19
16
|
return isExistSession(mediaOrParams);
|
|
@@ -30,10 +27,10 @@ function isExistSession(_a) {
|
|
|
30
27
|
return __awaiter(this, arguments, void 0, function* ({ sessionId, to, isGroup = false, }) {
|
|
31
28
|
var _b, _c;
|
|
32
29
|
try {
|
|
33
|
-
const session =
|
|
30
|
+
const session = getSession(sessionId);
|
|
34
31
|
if (!session)
|
|
35
|
-
throw new
|
|
36
|
-
const receiver =
|
|
32
|
+
throw new WhatsappError("Session ID Not Found!");
|
|
33
|
+
const receiver = phoneToJid({
|
|
37
34
|
to: to,
|
|
38
35
|
isGroup: isGroup,
|
|
39
36
|
});
|
package/dist/Utils/lid-utils.js
CHANGED
|
@@ -1,42 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.isValidJid = exports.normalizeJid = exports.extractPhoneNumber = exports.isPnJid = void 0;
|
|
4
|
-
const Error_1 = require("../Error");
|
|
5
|
-
const phone_to_jid_1 = require("./phone-to-jid");
|
|
1
|
+
import { WhatsappError } from "../Error/index.js";
|
|
2
|
+
import { isLidJid } from "./phone-to-jid.js";
|
|
6
3
|
/**
|
|
7
4
|
* Fungsi untuk mendeteksi apakah sebuah JID menggunakan format PN (@s.whatsapp.net)
|
|
8
5
|
* @param jid JID yang akan dicek
|
|
9
6
|
* @returns true jika JID menggunakan format PN
|
|
10
7
|
*/
|
|
11
|
-
const isPnJid = (jid) => {
|
|
8
|
+
export const isPnJid = (jid) => {
|
|
12
9
|
return jid.includes("@s.whatsapp.net");
|
|
13
10
|
};
|
|
14
|
-
exports.isPnJid = isPnJid;
|
|
15
11
|
/**
|
|
16
12
|
* Fungsi untuk mengekstrak nomor telepon dari JID (baik format @s.whatsapp.net atau @lid)
|
|
17
13
|
* @param jid JID yang akan diekstrak
|
|
18
14
|
* @returns nomor telepon tanpa suffix
|
|
19
15
|
*/
|
|
20
|
-
const extractPhoneNumber = (jid) => {
|
|
16
|
+
export const extractPhoneNumber = (jid) => {
|
|
21
17
|
if (!jid)
|
|
22
|
-
throw new
|
|
18
|
+
throw new WhatsappError('parameter "jid" is required');
|
|
23
19
|
// Hapus suffix @s.whatsapp.net atau @lid
|
|
24
20
|
const phoneNumber = jid.replace(/@(s\.whatsapp\.net|lid)$/, '');
|
|
25
21
|
// Hapus karakter non-digit
|
|
26
22
|
return phoneNumber.replace(/\D/g, '');
|
|
27
23
|
};
|
|
28
|
-
exports.extractPhoneNumber = extractPhoneNumber;
|
|
29
24
|
/**
|
|
30
25
|
* Fungsi untuk konversi JID dari format LID ke format PN jika diperlukan
|
|
31
26
|
* Catatan: Fungsi ini hanya untuk kompatibilitas, karena WhatsApp sekarang mendukung kedua format
|
|
32
27
|
* @param jid JID yang akan dikonversi
|
|
33
28
|
* @returns JID dalam format yang sesuai
|
|
34
29
|
*/
|
|
35
|
-
const normalizeJid = (jid) => {
|
|
30
|
+
export const normalizeJid = (jid) => {
|
|
36
31
|
if (!jid)
|
|
37
|
-
throw new
|
|
32
|
+
throw new WhatsappError('parameter "jid" is required');
|
|
38
33
|
// Jika sudah dalam format yang valid, kembalikan apa adanya
|
|
39
|
-
if (
|
|
34
|
+
if (isLidJid(jid) || isPnJid(jid) || jid.includes('@g.us') || jid.includes('@broadcast')) {
|
|
40
35
|
return jid;
|
|
41
36
|
}
|
|
42
37
|
// Jika hanya nomor telepon, tambahkan suffix default
|
|
@@ -44,24 +39,23 @@ const normalizeJid = (jid) => {
|
|
|
44
39
|
if (phoneNumber.length > 0) {
|
|
45
40
|
return `${phoneNumber}@s.whatsapp.net`;
|
|
46
41
|
}
|
|
47
|
-
throw new
|
|
42
|
+
throw new WhatsappError(`Invalid JID format: ${jid}`);
|
|
48
43
|
};
|
|
49
|
-
exports.normalizeJid = normalizeJid;
|
|
50
44
|
/**
|
|
51
45
|
* Fungsi untuk memvalidasi format JID
|
|
52
46
|
* @param jid JID yang akan divalidasi
|
|
53
47
|
* @returns true jika JID valid
|
|
54
48
|
*/
|
|
55
|
-
const isValidJid = (jid) => {
|
|
49
|
+
export const isValidJid = (jid) => {
|
|
56
50
|
if (!jid)
|
|
57
51
|
return false;
|
|
58
52
|
// Validasi format @s.whatsapp.net
|
|
59
|
-
if (
|
|
60
|
-
const phoneNumber =
|
|
53
|
+
if (isPnJid(jid)) {
|
|
54
|
+
const phoneNumber = extractPhoneNumber(jid);
|
|
61
55
|
return phoneNumber.length >= 10 && phoneNumber.length <= 15;
|
|
62
56
|
}
|
|
63
57
|
// Validasi format @lid
|
|
64
|
-
if (
|
|
58
|
+
if (isLidJid(jid)) {
|
|
65
59
|
const lidPart = jid.split('@')[0];
|
|
66
60
|
return lidPart.length > 0;
|
|
67
61
|
}
|
|
@@ -78,4 +72,3 @@ const isValidJid = (jid) => {
|
|
|
78
72
|
}
|
|
79
73
|
return false;
|
|
80
74
|
};
|
|
81
|
-
exports.isValidJid = isValidJid;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { proto } from "baileys";
|
|
2
|
-
import { MessageUpdated } from "../Types";
|
|
2
|
+
import { MessageUpdated } from "../Types/index.js";
|
|
3
3
|
export declare const parseMessageStatusCodeToReadable: (code: proto.WebMessageInfo.Status) => MessageUpdated["messageStatus"];
|
|
4
4
|
//# sourceMappingURL=message-status.d.ts.map
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const baileys_1 = require("baileys");
|
|
5
|
-
const parseMessageStatusCodeToReadable = (code) => {
|
|
6
|
-
if (code == baileys_1.proto.WebMessageInfo.Status.PENDING)
|
|
1
|
+
import { proto } from "baileys";
|
|
2
|
+
export const parseMessageStatusCodeToReadable = (code) => {
|
|
3
|
+
if (code == proto.WebMessageInfo.Status.PENDING)
|
|
7
4
|
return "pending";
|
|
8
|
-
if (code ==
|
|
5
|
+
if (code == proto.WebMessageInfo.Status.SERVER_ACK)
|
|
9
6
|
return "server";
|
|
10
|
-
if (code ==
|
|
7
|
+
if (code == proto.WebMessageInfo.Status.DELIVERY_ACK)
|
|
11
8
|
return "delivered";
|
|
12
|
-
if (code ==
|
|
9
|
+
if (code == proto.WebMessageInfo.Status.READ)
|
|
13
10
|
return "read";
|
|
14
|
-
if (code ==
|
|
11
|
+
if (code == proto.WebMessageInfo.Status.PLAYED)
|
|
15
12
|
return "played";
|
|
16
13
|
return "error";
|
|
17
14
|
};
|
|
18
|
-
exports.parseMessageStatusCodeToReadable = parseMessageStatusCodeToReadable;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,11 +7,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const crypto_1 = require("baileys/lib/Utils/crypto");
|
|
15
|
-
const generics_1 = require("baileys/lib/Utils/generics");
|
|
10
|
+
import { proto } from "baileys/WAProto/index.js";
|
|
11
|
+
import { Curve, signedKeyPair } from "baileys/lib/Utils/crypto.js";
|
|
12
|
+
import { generateRegistrationId } from "baileys/lib/Utils/generics.js";
|
|
16
13
|
const BufferJSON = {
|
|
17
14
|
replacer: (_, value) => {
|
|
18
15
|
if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === "Buffer") {
|
|
@@ -29,13 +26,13 @@ const BufferJSON = {
|
|
|
29
26
|
},
|
|
30
27
|
};
|
|
31
28
|
const initAuthCreds = () => {
|
|
32
|
-
const identityKey =
|
|
29
|
+
const identityKey = Curve.generateKeyPair();
|
|
33
30
|
return {
|
|
34
|
-
noiseKey:
|
|
35
|
-
pairingEphemeralKeyPair:
|
|
31
|
+
noiseKey: Curve.generateKeyPair(),
|
|
32
|
+
pairingEphemeralKeyPair: Curve.generateKeyPair(),
|
|
36
33
|
signedIdentityKey: identityKey,
|
|
37
|
-
signedPreKey:
|
|
38
|
-
registrationId:
|
|
34
|
+
signedPreKey: signedKeyPair(identityKey, 1),
|
|
35
|
+
registrationId: generateRegistrationId(),
|
|
39
36
|
advSecretKey: Buffer.from(Array(32)).toString("base64"),
|
|
40
37
|
processedHistoryMessages: [],
|
|
41
38
|
nextPreKeyId: 1,
|
|
@@ -48,7 +45,7 @@ const initAuthCreds = () => {
|
|
|
48
45
|
routingInfo: undefined,
|
|
49
46
|
};
|
|
50
47
|
};
|
|
51
|
-
function useMongoAuthState(sessionId, collection) {
|
|
48
|
+
export function useMongoAuthState(sessionId, collection) {
|
|
52
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
50
|
const readState = () => __awaiter(this, void 0, void 0, function* () {
|
|
54
51
|
const doc = yield collection.findOne({ sessionId });
|
|
@@ -77,7 +74,7 @@ function useMongoAuthState(sessionId, collection) {
|
|
|
77
74
|
for (const id of ids) {
|
|
78
75
|
let data = keys === null || keys === void 0 ? void 0 : keys[`${type}-${id}`];
|
|
79
76
|
if (type === "app-state-sync-key" && data) {
|
|
80
|
-
data =
|
|
77
|
+
data = proto.Message.AppStateSyncKeyData.fromObject(data);
|
|
81
78
|
}
|
|
82
79
|
result[id] = data;
|
|
83
80
|
}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.phoneToJid = exports.isLidJid = void 0;
|
|
7
|
-
const Error_1 = require("../Error");
|
|
8
|
-
const baileys_1 = __importDefault(require("baileys"));
|
|
1
|
+
import { WhatsappError } from "../Error/index.js";
|
|
2
|
+
import PHONENUMBER_MCC from "baileys";
|
|
9
3
|
const isPhoneNumberValidCountry = (phone) => {
|
|
10
|
-
return Object.keys(
|
|
4
|
+
return Object.keys(PHONENUMBER_MCC).some((key) => {
|
|
11
5
|
return phone.startsWith(key);
|
|
12
6
|
});
|
|
13
7
|
};
|
|
@@ -16,19 +10,18 @@ const isPhoneNumberValidCountry = (phone) => {
|
|
|
16
10
|
* @param jid JID yang akan dicek
|
|
17
11
|
* @returns true jika JID menggunakan format LID
|
|
18
12
|
*/
|
|
19
|
-
const isLidJid = (jid) => {
|
|
13
|
+
export const isLidJid = (jid) => {
|
|
20
14
|
return jid.includes("@lid");
|
|
21
15
|
};
|
|
22
|
-
exports.isLidJid = isLidJid;
|
|
23
16
|
/**
|
|
24
17
|
* Fungsi untuk normalisasi JID, mendukung format @s.whatsapp.net dan @lid
|
|
25
18
|
* @param to Nomor telepon atau JID tujuan
|
|
26
19
|
* @param isGroup Apakah ini adalah grup
|
|
27
20
|
* @returns JID yang sudah dinormalisasi
|
|
28
21
|
*/
|
|
29
|
-
const phoneToJid = ({ to, isGroup = false, }) => {
|
|
22
|
+
export const phoneToJid = ({ to, isGroup = false, }) => {
|
|
30
23
|
if (!to)
|
|
31
|
-
throw new
|
|
24
|
+
throw new WhatsappError('parameter "to" is required');
|
|
32
25
|
let number = to.toString();
|
|
33
26
|
if (isGroup) {
|
|
34
27
|
number = number.replace(/\s|[+]|[-]/gim, "");
|
|
@@ -48,4 +41,3 @@ const phoneToJid = ({ to, isGroup = false, }) => {
|
|
|
48
41
|
}
|
|
49
42
|
return number;
|
|
50
43
|
};
|
|
51
|
-
exports.phoneToJid = phoneToJid;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MessageReceived } from "../Types";
|
|
1
|
+
import { MessageReceived } from "../Types/index.js";
|
|
2
2
|
export declare const saveImageHandler: (msg: MessageReceived, path: string) => Promise<void>;
|
|
3
3
|
export declare const saveVideoHandler: (msg: MessageReceived, path: string) => Promise<void>;
|
|
4
4
|
export declare const saveDocumentHandler: (msg: MessageReceived, path: string) => Promise<void>;
|
package/dist/Utils/save-media.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,48 +7,39 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.saveAudioHandler = exports.saveDocumentHandler = exports.saveVideoHandler = exports.saveImageHandler = void 0;
|
|
16
|
-
const baileys_1 = require("baileys");
|
|
17
|
-
const error_1 = __importDefault(require("./error"));
|
|
18
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
10
|
+
import { downloadMediaMessage } from "baileys";
|
|
11
|
+
import ValidationError from "./error.js";
|
|
12
|
+
import fs from "fs/promises";
|
|
19
13
|
const saveMedia = (path, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
yield
|
|
14
|
+
yield fs.writeFile(path, data.toString("base64"), "base64");
|
|
21
15
|
});
|
|
22
|
-
const saveImageHandler = (msg, path) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
export const saveImageHandler = (msg, path) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
17
|
var _a;
|
|
24
18
|
if (!((_a = msg.message) === null || _a === void 0 ? void 0 : _a.imageMessage))
|
|
25
|
-
throw new
|
|
26
|
-
const buf = yield
|
|
19
|
+
throw new ValidationError("Message is not contain Image");
|
|
20
|
+
const buf = yield downloadMediaMessage(msg, "buffer", {});
|
|
27
21
|
return saveMedia(path, buf);
|
|
28
22
|
});
|
|
29
|
-
|
|
30
|
-
const saveVideoHandler = (msg, path) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
export const saveVideoHandler = (msg, path) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
24
|
var _a;
|
|
32
25
|
if (!((_a = msg.message) === null || _a === void 0 ? void 0 : _a.videoMessage))
|
|
33
|
-
throw new
|
|
34
|
-
const buf = yield
|
|
26
|
+
throw new ValidationError("Message is not contain Video");
|
|
27
|
+
const buf = yield downloadMediaMessage(msg, "buffer", {});
|
|
35
28
|
return saveMedia(path, buf);
|
|
36
29
|
});
|
|
37
|
-
|
|
38
|
-
const saveDocumentHandler = (msg, path) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
export const saveDocumentHandler = (msg, path) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
31
|
var _a, _b;
|
|
40
32
|
if (!((_a = msg.message) === null || _a === void 0 ? void 0 : _a.documentMessage))
|
|
41
|
-
throw new
|
|
42
|
-
const buf = yield
|
|
33
|
+
throw new ValidationError("Message is not contain Document");
|
|
34
|
+
const buf = yield downloadMediaMessage(msg, "buffer", {});
|
|
43
35
|
const ext = (_b = msg.message.documentMessage.fileName) === null || _b === void 0 ? void 0 : _b.split(".").pop();
|
|
44
36
|
path += "." + ext;
|
|
45
37
|
return saveMedia(path, buf);
|
|
46
38
|
});
|
|
47
|
-
|
|
48
|
-
const saveAudioHandler = (msg, path) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
export const saveAudioHandler = (msg, path) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
40
|
var _a;
|
|
50
41
|
if (!((_a = msg.message) === null || _a === void 0 ? void 0 : _a.audioMessage))
|
|
51
|
-
throw new
|
|
52
|
-
const buf = yield
|
|
42
|
+
throw new ValidationError("Message is not contain Audio");
|
|
43
|
+
const buf = yield downloadMediaMessage(msg, "buffer", {});
|
|
53
44
|
return saveMedia(path, buf);
|
|
54
45
|
});
|
|
55
|
-
exports.saveAudioHandler = saveAudioHandler;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare abstract class CREDENTIALS {
|
|
2
|
+
static DIR_NAME: string;
|
|
3
|
+
static PREFIX: string;
|
|
4
|
+
static MONGO_DB_NAME: string;
|
|
5
|
+
static MONGO_COLLECTION_NAME: string;
|
|
6
|
+
}
|
|
7
|
+
export declare enum CALLBACK_KEY {
|
|
8
|
+
ON_MESSAGE_RECEIVED = "on-message-received",
|
|
9
|
+
ON_QR = "on-qr",
|
|
10
|
+
ON_CONNECTED = "on-connected",
|
|
11
|
+
ON_DISCONNECTED = "on-disconnected",
|
|
12
|
+
ON_CONNECTING = "on-connecting",
|
|
13
|
+
ON_MESSAGE_UPDATED = "on-message-updated",
|
|
14
|
+
ON_PAIRING_CODE = "on-pairing-code"
|
|
15
|
+
}
|
|
16
|
+
export declare abstract class Messages {
|
|
17
|
+
static sessionAlreadyExist: (sessionId: string) => string;
|
|
18
|
+
static sessionNotFound: (sessionId: string) => string;
|
|
19
|
+
static paremetersRequired: (props: string[] | string) => string;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Defaults/index.ts"],"names":[],"mappings":"AAAA,8BAAsB,WAAW;IAC/B,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAoB;IAC3C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAkB;IAGvC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAgB;IAC5C,MAAM,CAAC,qBAAqB,EAAE,MAAM,CAAU;CAC/C;AAED,oBAAY,YAAY;IACtB,mBAAmB,wBAAwB;IAC3C,KAAK,UAAU;IACf,YAAY,iBAAiB;IAC7B,eAAe,oBAAoB;IACnC,aAAa,kBAAkB;IAC/B,kBAAkB,uBAAuB;IACzC,eAAe,oBAAoB;CACpC;AAED,8BAAsB,QAAQ;IAC5B,MAAM,CAAC,mBAAmB,GAAI,WAAW,MAAM,KAAG,MAAM,CACe;IAEvE,MAAM,CAAC,eAAe,GAAI,WAAW,MAAM,KAAG,MAAM,CACP;IAE7C,MAAM,CAAC,kBAAkB,GAAI,OAAO,MAAM,EAAE,GAAG,MAAM,YAOpC;CAClB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Messages = exports.CALLBACK_KEY = exports.CREDENTIALS = void 0;
|
|
4
|
+
class CREDENTIALS {
|
|
5
|
+
}
|
|
6
|
+
exports.CREDENTIALS = CREDENTIALS;
|
|
7
|
+
CREDENTIALS.DIR_NAME = "wa_credentials";
|
|
8
|
+
CREDENTIALS.PREFIX = "_credentials";
|
|
9
|
+
// Konfigurasi MongoDB
|
|
10
|
+
CREDENTIALS.MONGO_DB_NAME = "wa_session";
|
|
11
|
+
CREDENTIALS.MONGO_COLLECTION_NAME = "auth";
|
|
12
|
+
var CALLBACK_KEY;
|
|
13
|
+
(function (CALLBACK_KEY) {
|
|
14
|
+
CALLBACK_KEY["ON_MESSAGE_RECEIVED"] = "on-message-received";
|
|
15
|
+
CALLBACK_KEY["ON_QR"] = "on-qr";
|
|
16
|
+
CALLBACK_KEY["ON_CONNECTED"] = "on-connected";
|
|
17
|
+
CALLBACK_KEY["ON_DISCONNECTED"] = "on-disconnected";
|
|
18
|
+
CALLBACK_KEY["ON_CONNECTING"] = "on-connecting";
|
|
19
|
+
CALLBACK_KEY["ON_MESSAGE_UPDATED"] = "on-message-updated";
|
|
20
|
+
CALLBACK_KEY["ON_PAIRING_CODE"] = "on-pairing-code";
|
|
21
|
+
})(CALLBACK_KEY || (exports.CALLBACK_KEY = CALLBACK_KEY = {}));
|
|
22
|
+
class Messages {
|
|
23
|
+
}
|
|
24
|
+
exports.Messages = Messages;
|
|
25
|
+
Messages.sessionAlreadyExist = (sessionId) => `Session ID :${sessionId} is already exist, Try another Session ID.`;
|
|
26
|
+
Messages.sessionNotFound = (sessionId) => `Session with ID: ${sessionId} Not Exist!`;
|
|
27
|
+
Messages.paremetersRequired = (props) => `Parameter ${typeof props == "string"
|
|
28
|
+
? props
|
|
29
|
+
: props instanceof Array
|
|
30
|
+
? props.join(", ")
|
|
31
|
+
: ""} is required`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Error/index.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;IAM3B,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,aAAa;CAG3D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WhatsappError = void 0;
|
|
4
|
+
class WhatsappError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "WhatsappError";
|
|
8
|
+
Object.setPrototypeOf(this, WhatsappError.prototype);
|
|
9
|
+
}
|
|
10
|
+
static isWhatsappError(error) {
|
|
11
|
+
return error instanceof WhatsappError || error instanceof Error;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.WhatsappError = WhatsappError;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { proto } from "baileys";
|
|
2
|
+
import { SendMediaTypes, SendMessageTypes, SendReadTypes, SendTypingTypes, SendMessageWithMentionTypes } from "../Types";
|
|
3
|
+
export declare const sendTextMessage: ({ sessionId, to, text, isGroup, ...props }: SendMessageTypes) => Promise<proto.WebMessageInfo | undefined>;
|
|
4
|
+
/**
|
|
5
|
+
* Kirim pesan teks dengan mention
|
|
6
|
+
*
|
|
7
|
+
* @param sessionId - ID sesi WhatsApp
|
|
8
|
+
* @param to - Nomor telepon atau JID tujuan
|
|
9
|
+
* @param text - Teks pesan (bisa mengandung @nomor untuk mention)
|
|
10
|
+
* @param mentions - Array JID yang akan di-mention
|
|
11
|
+
* @param isGroup - Apakah ini adalah grup
|
|
12
|
+
* @param props - Properti tambahan seperti answering
|
|
13
|
+
*/
|
|
14
|
+
export declare const sendTextMessageWithMention: ({ sessionId, to, text, mentions, isGroup, ...props }: SendMessageWithMentionTypes) => Promise<proto.WebMessageInfo | undefined>;
|
|
15
|
+
export declare const sendMedia: ({ sessionId, to, media, type, caption, fileName, isGroup, answering, }: SendMediaTypes) => Promise<proto.WebMessageInfo | undefined>;
|
|
16
|
+
export declare const sendVoiceNote: ({ sessionId, to, isGroup, media, ...props }: Omit<SendMediaTypes, "text">) => Promise<proto.WebMessageInfo | undefined>;
|
|
17
|
+
export declare const sendSticker: ({ sessionId, to, isGroup, media, ...props }: SendMediaTypes) => Promise<proto.WebMessageInfo | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* Give typing effect to target
|
|
20
|
+
*
|
|
21
|
+
* Looks like human typing
|
|
22
|
+
*
|
|
23
|
+
* @param sessionId - Session ID
|
|
24
|
+
* @param to - Target
|
|
25
|
+
* @param duration - Duration in miliseconds typing effect will appear
|
|
26
|
+
* @param isGroup - Whether the chat is a group
|
|
27
|
+
*/
|
|
28
|
+
export declare const sendTyping: ({ sessionId, to, duration, isGroup, }: SendTypingTypes) => Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Mark message as read
|
|
31
|
+
*
|
|
32
|
+
* @param sessionId - Session ID
|
|
33
|
+
* @param key - Message key to mark as read
|
|
34
|
+
*/
|
|
35
|
+
export declare const readMessage: ({ sessionId, key, }: SendReadTypes) => Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Menghapus pesan yang telah dikirim
|
|
38
|
+
*
|
|
39
|
+
* Dapat digunakan untuk menghapus pesan bot sendiri atau menghapus pesan orang lain (jika bot adalah admin di grup)
|
|
40
|
+
*
|
|
41
|
+
* @param sessionId - Session ID
|
|
42
|
+
* @param key - Message key dari pesan yang akan dihapus
|
|
43
|
+
*/
|
|
44
|
+
export declare const deleteMessage: ({ sessionId, key, }: SendReadTypes) => Promise<void>;
|
|
45
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Messaging/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,SAAS,CAAC;AAGnD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,2BAA2B,EAC5B,MAAM,UAAU,CAAC;AAQlB,eAAO,MAAM,eAAe,GAAU,4CAMnC,gBAAgB,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CA8I7D,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,0BAA0B,GAAU,sDAO9C,2BAA2B,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CAoKxE,CAAC;AAaF,eAAO,MAAM,SAAS,GAAU,wEAS7B,cAAc,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CAqM3D,CAAC;AAEF,eAAO,MAAM,aAAa,GAAU,6CAMjC,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CA6HzE,CAAC;AAEF,eAAO,MAAM,WAAW,GAAU,6CAM/B,cAAc,KAAG,OAAO,CAAC,KAAK,CAAC,cAAc,GAAG,SAAS,CA2H3D,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,GAAU,uCAK9B,eAAe,KAAG,OAAO,CAAC,IAAI,CA4EhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAU,qBAG/B,aAAa,KAAG,OAAO,CAAC,IAAI,CA6B9B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GAAU,qBAGjC,aAAa,KAAG,OAAO,CAAC,IAAI,CAsC9B,CAAC"}
|