UNPKG

@fatihjr/wa-wrapper

Version:

Baileys WhatsApp Web API wrapper.

50 lines (49 loc) 2.09 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const BlastBot_1 = __importDefault(require("./BlastBot")); const dbHandler_1 = __importDefault(require("./dbHandler")); const path_1 = __importDefault(require("path")); const node_events_1 = __importDefault(require("node:events")); class runCaster extends node_events_1.default { constructor({ sessionList, dbList }) { super(); this.sessionList = sessionList; this.dbList = dbList; } async sessionStart({ connectionName, folderPath }) { if (!this.sessionList.get(connectionName)) { console.log("Session Doesn't Exists!"); try { const ChatBot = new BlastBot_1.default({ folderPath, connectionName }); ChatBot.on("qr-string", qr => { this.emit("qr-string", qr); }); const waSock = ChatBot.connectToWhatsApp(); const chatsDB = new dbHandler_1.default(path_1.default.join(folderPath, "wapi_store.json")); this.sessionList.set(connectionName, await waSock); this.dbList.set(connectionName, chatsDB); this.dbList.get(connectionName).readFromFile(); this.dbList.get(connectionName).bind(await waSock.then(done => done.ev)); return true; } catch (err) { console.log("An Error has occurred!", err); return false; } } else { console.log("Session Already Exists!"); return false; } } async sessionEnd(connectionName) { this.dbList.get(connectionName).end(this.sessionList.get(connectionName).ev); this.sessionList.get(connectionName).end(new Error("DIMATIKAN")); this.sessionList.delete(connectionName); this.dbList.delete(connectionName); } } exports.default = runCaster;