whatsapp-client.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const { Client, LocalAuth } = require('whatsapp-web.js');
  2. const axios = require('axios');
  3. class WhasAppClient {
  4. constructor(be) {
  5. this.clientId = be;
  6. this.isGenerateQr = false;
  7. this.client = new Client({
  8. puppeteer: {
  9. args: ['--no-sandbox'],
  10. },
  11. authStrategy: new LocalAuth({
  12. clientId: this.clientId
  13. }),
  14. webVersionCache: {
  15. type: "remote",
  16. remotePath:
  17. "https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/2.2412.54.html",
  18. },
  19. });
  20. this.client.initialize().catch(_ => _);
  21. this.client.on('authenticated', async () => {
  22. console.log(`be:${this.clientId}:Authenticated`);
  23. });
  24. let that = this.client;
  25. this.client.on('message', async (msg) => {
  26. // console.log(`be:${this.clientId}:message:${JSON.stringify(msg)}`);
  27. // axios.post('https://nexilis.io/chatgpt/gptnexilis', [{
  28. // role: 'user',
  29. // content: msg.body
  30. // }], {
  31. // headers: {
  32. // 'User-Agent': 'easySoftIndonesia',
  33. // 'Cookie': 'PHPSESSID=123;MOBILE=123'
  34. // }
  35. // })
  36. // .then(function (response) {
  37. // console.log(`response:${JSON.stringify(response.data)}`);
  38. // that.sendMessage(msg.from, response.data.content);
  39. // })
  40. // .catch(function (error) {
  41. // console.log(error);
  42. // });
  43. });
  44. }
  45. }
  46. module.exports.WhasAppClient = WhasAppClient;