UNPKG

@kamuridesu/whatframework

Version:

A simple WhatsApp Bot Framework on top of Baileys

37 lines (36 loc) 1.37 kB
#!/usr/bin/env node import fs from 'fs'; import path from 'path'; import { load } from './src/modules/dynamicModules.js'; import { botFactory } from './libs/util.js'; import { MessageHandler } from './src/modules/messageHandler.js'; const SUPPORTED_LANGUAGES = ["en-us", "pt-br"]; async function initializeFramework(entrypointFile = undefined) { const rootPath = process.cwd(); const modulesPath = process.env.DEBUG ? path.join(rootPath, 'test_modules') : path.join(rootPath, 'modules'); fs.mkdirSync('./temp', { recursive: true }); if (entrypointFile == undefined) { entrypointFile = path.join(modulesPath, "entrypoint.js"); } else { entrypointFile = path.resolve(entrypointFile); } const entryPoint = path.join(entrypointFile); const entryPointModule = await load(entryPoint); const entryPointClass = new entryPointModule.Entrypoint(); if (entryPointClass.language) { if (!SUPPORTED_LANGUAGES.includes(entryPointClass.language)) { throw new Error("Language is not supported!"); } } else { entryPointClass.language = "en-us"; } const messageHandler = new MessageHandler(entryPointClass); const bot = botFactory(entryPointClass); await bot.init(messageHandler); } initializeFramework(process.argv[2]); export { initializeFramework };