const { Client, LocalAuth } = require('whatsapp-web.js'); const axios = require('axios'); class WhasAppClient { constructor(be) { this.clientId = be; this.isGenerateQr = false; this.client = new Client({ puppeteer: { args: ['--no-sandbox'], }, authStrategy: new LocalAuth({ clientId: this.clientId }), webVersionCache: { type: "remote", remotePath: "https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/2.2412.54.html", }, }); this.client.initialize().catch(_ => _); this.client.on('authenticated', async () => { console.log(`be:${this.clientId}:Authenticated`); }); let that = this.client; this.client.on('message', async (msg) => { console.log(`be:${this.clientId}:message:${JSON.stringify(msg)}`); if (msg.body.startsWith('!bot ')) { let message = msg.body.slice(5, msg.body.length); let chat = await msg.getChat(); chat.sendSeen(); console.log(`message:${message}`); axios.post('https://nexilis.io/chatgpt/gptnexilis', [{ role: 'user', content: message }], { headers: { 'User-Agent': 'easySoftIndonesia', 'Cookie': 'PHPSESSID=123;MOBILE=123' } }) .then(function (response) { console.log(`response:${JSON.stringify(response.data)}`); that.sendMessage(msg.from, response.data.content); }) .catch(function (error) { console.log(error); }); } }); } } module.exports.WhasAppClient = WhasAppClient;