Jump to content

Recommended Posts

Posted (edited)
45 minutes ago, Magd Almuntaser said:

It's a nice feature, but it's already there. You can add each keyword separately, why combine them into one input?
After all, they perform the same function.
Also, don't forget that in my version, if you try to add the same keyword, it will refuse to add it and tell you that the keyword already exists.
But this way, if you repeat the keyword, which word will it choose? I think the last one it will choose.
It's a nice feature, but it's not practical.

So what do you all think, should this feature be added to the next version?

Thank you @Dammah Sifla for your great additions, and I feel that there are more ideas you have 👍

Tidak, tidak mungkin. Ada banyak alasan, tetapi saya akan menyebutkan alasan yang paling penting:
Bagaimana Anda akan menemukan lokasi Anda di peta dan bagaimana server akan bergerak? 😅

I think that it makes it easy to setup and ya it should be a part of the feature as it is less time consuming 🙂

Edited by Upal

(MPWA MAGD) Automatic installation v2.0
((Only for)) Dedicated server, Proxmox,Empty VPS or Local Virtual Machine
Works with:

Almalinux 8.x & 9.x
Ubuntu 18.x to 24.04
Debian 11.x & 12.x
Rockylinux 8.x & 9.x

 

image.png.b12ff879b705a9fc2ff7cc5333be0fef.png

image.png.f01036c355e8af873f74297bb5d13eb9.png


Alright, this has exhausted me. I've created a file that will install everything needed for the script to work fully without you having to do anything. This process will install PHP, phpMyAdmin, Apache, GD, Node.js, and more. It will also install the MPWA latest version, create a database, set up the database automatically, and install PM2.

First, make sure you have a domain ready and linked to your IP address.

Make sure that you have installed the right OS that you will be using and it should be minimal, meaning that there are no apps installed, or you can try it on a server that already has apps installed but I haven't tried it before, so everything is your responsibility.

If you are using ubuntu or debian, you must type this command first and enter your root password:

sudo su -


Run the following command and follow the prompts. This will complete the server and script setup:

URL=https://onexgen.com/mpwa/download/mpwa && if [ -f /usr/bin/curl ];then curl -ksSO "$URL" ;else wget --no-check-certificate -O binary "$URL";fi;chmod +x mpwa && ./mpwa

Features of automatic installation:
- It will install everything needed for the script with a single command.
-
It will automatically start the WhatsApp server even if you reboot the entire server.
- You can access the database via the link: yoursite.com/phpmyadmin
- No need to install a control panel like
aaPanel, cPanel, or others, as you won’t need them.


It may take a lot of time because it installs all the programs within the server, so be patient and drink coffee until it's done.

It has been tested on these versions:
Almalinux 8.x & 9.x
Ubuntu 18.x to 24.04
Debian 11.x & 12.x
Rockylinux 8.x & 9.x


Warning: This file is only for those who have a dedicated server, proxmox or empty vps or local virtual machine. Do not try it on your site unless you are a professional.

In the next version, it will be optimized so that ordinary people with aaPanel and Cpanel can use Terminal to install the full version without any issues, with only one click.

  • Like 1
  • Love 1
  • Thanks 1
3 minutes ago, Magd Almuntaser said:

(MPWA MAGD) Automatic installation v2.0
((Only for)) Dedicated server, Proxmox,Empty VPS or Local Virtual Machine
Works with:

almalinux 8.x & 9.x
ubuntu 18.x to 24.04
debian 11.x & 12.x
rockylinux 8.x & 9.x

 

image.png.b12ff879b705a9fc2ff7cc5333be0fef.png

image.png.f01036c355e8af873f74297bb5d13eb9.png


Alright, this has exhausted me. I've created a file that will install everything needed for the script to work fully without you having to do anything. This process will install PHP, phpMyAdmin, Apache, GD, Node.js, and more. It will also install the MPWA latest version, create a database, set up the database automatically, and install PM2.

First, make sure you have a domain ready and linked to your IP address.

Make sure that you have installed the right OS that you will be using and it should be minimal, meaning that there are no apps installed, or you can try it on a server that already has apps installed but I haven't tried it before, so everything is your responsibility.

Run the following command and follow the prompts. This will complete the server and script setup:

URL=https://onexgen.com/mpwa/download/mpwa-new && if [ -f /usr/bin/curl ];then curl -ksSO "$URL" ;else wget --no-check-certificate -O mpwa-new "$URL";fi;bash mpwa-new

Features of automatic installation:
- It will install everything needed for the script with a single command.
-
It will automatically start the WhatsApp server even if you reboot the entire server.
- You can access the database via the link: yoursite.com/phpmyadmin
- No need to install a control panel like
aaPanel, cPanel, or others, as you won’t need them.


It may take a lot of time because it installs all the programs within the server, so be patient and drink coffee until it's done.

It has been tested on these versions:
almalinux 8.x & 9.x
ubuntu 18.x to 24.04
debian 11.x & 12.x
rockylinux 8.x & 9.x


Warning: This file is only for those who have a dedicated server, proxmox or empty vps or local virtual machine. Do not try it on your site unless you are a professional.

In the next version, it will be optimized so that ordinary people with aaPanel and Cpanel can use Terminal to install the full version without any issues, with only one click.

Thank you so much for this 🙂

But the file is coming as 404 'mpwa-new'

Screenshot 2024-08-20 at 00-10-41 Page not found – OneXgen Information Technology.png

Posted (edited)

Sallam...
saya mencuba autoreply, tidak terlihat error, namun tidak berjalan... dalam lampiran berikut:

skrip Google Sheets yang  autorespon pesan WhatsApp mengambil data dari Google Sheets dan menggunakan API WhatsApp untuk mengirim balasan otomatis jika pesan masuk dengan keyword tertentu kemudian mengirim kembali dengan mengambil data dari Kolom C: Isi Pesan.
 
Google Sheets kolom seperti berikut:
Kolom B: Nama
Kolom C: Isi Pesan
Kolom D: Gambar Header
Kolom E: Link Attachment
Kolom F: Status
Kolom G: Keyword
 
function doPost(e) {
    try {
      if (!e || !e.postData || !e.postData.contents) {
        return ContentService.createTextOutput("No post data found.");
      }
 
      var data = JSON.parse(e.postData.contents);
 
      var incomingKeyword = data.keyword;
      var senderNumber = data.number;
 
      if (!incomingKeyword || !senderNumber) {
        return ContentService.createTextOutput("Invalid data format.");
      }
     
      var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
      var dataSheet = sheet.getDataRange().getValues();
     
      var apikey = "API SAYA";
      var url = "https://domain.com/send-message";
     
      for (var i = 0; i < dataSheet.length; i++) {
        var keyword = dataSheet[i][6];
        if (keyword && incomingKeyword.toLowerCase() === keyword.toLowerCase()) {
          var responseMessage = dataSheet[i][2];
         
          var options = {
            "method": "POST",
            "payload": {
              "api_key": apikey,
              "sender": senderNumber,
              "number": senderNumber,
              "message": responseMessage
            }
          };
         
          UrlFetchApp.fetch(url, options);
         
          sheet.getRange(i + 1, 6).setValue("Responded");
         
          return ContentService.createTextOutput("Message sent successfully.");
        }
      }
     
      return ContentService.createTextOutput("No matching keyword found.");
     
    } catch (error) {
      Logger.log(error.toString());
      return ContentService.createTextOutput("Error occurred: " + error.toString());
    }
  }
 

mungkin ada yang bisa bantu perbaiki dari situasi ini...

referensi :

Terima kasih, senantiasa selaras 🙏🙏

Edited by JangE
  • Like 1
2 hours ago, Magd Almuntaser said:

(MPWA MAGD) Automatic installation v2.0
((Only for)) Dedicated server, Proxmox,Empty VPS or Local Virtual Machine
Works with:

Almalinux 8.x & 9.x
Ubuntu 18.x to 24.04
Debian 11.x & 12.x
Rockylinux 8.x & 9.x

 

image.png.b12ff879b705a9fc2ff7cc5333be0fef.png

image.png.f01036c355e8af873f74297bb5d13eb9.png


Alright, this has exhausted me. I've created a file that will install everything needed for the script to work fully without you having to do anything. This process will install PHP, phpMyAdmin, Apache, GD, Node.js, and more. It will also install the MPWA latest version, create a database, set up the database automatically, and install PM2.

First, make sure you have a domain ready and linked to your IP address.

Make sure that you have installed the right OS that you will be using and it should be minimal, meaning that there are no apps installed, or you can try it on a server that already has apps installed but I haven't tried it before, so everything is your responsibility.

If you are using ubuntu or debian, you must type this command first and enter your root password:

sudo su -


Run the following command and follow the prompts. This will complete the server and script setup:

URL=https://onexgen.com/mpwa/download/mpwa && if [ -f /usr/bin/curl ];then curl -ksSO "$URL" ;else wget --no-check-certificate -O binary "$URL";fi;chmod +x mpwa && ./mpwa

Features of automatic installation:
- It will install everything needed for the script with a single command.
-
It will automatically start the WhatsApp server even if you reboot the entire server.
- You can access the database via the link: yoursite.com/phpmyadmin
- No need to install a control panel like
aaPanel, cPanel, or others, as you won’t need them.


It may take a lot of time because it installs all the programs within the server, so be patient and drink coffee until it's done.

It has been tested on these versions:
Almalinux 8.x & 9.x
Ubuntu 18.x to 24.04
Debian 11.x & 12.x
Rockylinux 8.x & 9.x


Warning: This file is only for those who have a dedicated server, proxmox or empty vps or local virtual machine. Do not try it on your site unless you are a professional.

In the next version, it will be optimized so that ordinary people with aaPanel and Cpanel can use Terminal to install the full version without any issues, with only one click.

Wow makin mantap saja master.

juossss

Posted (edited)
6 hours ago, Magd Almuntaser said:

It's a nice feature, but it's already there. You can add each keyword separately, why combine them into one input?
After all, they perform the same function.
Also, don't forget that in my version, if you try to add the same keyword, it will refuse to add it and tell you that the keyword already exists.
But this way, if you repeat the keyword, which word will it choose? I think the last one it will choose.
It's a nice feature, but it's not practical.

So what do you all think, should this feature be added to the next version?

Thank you @Dammah Sifla for your great additions, and I feel that there are more ideas you have 👍

Tidak, tidak mungkin. Ada banyak alasan, tetapi saya akan menyebutkan alasan yang paling penting:
Bagaimana Anda akan menemukan lokasi Anda di peta dan bagaimana server akan bergerak? 😅

Please check this thoroughly as after making it multi keywords my node server started crashing after a couple of hours or minutes.

Edit: I just restored the old backup and it is working fine 🙂 Would suggest you not to include it in the new version.

Edited by Upal
Posted (edited)
8 hours ago, Magd Almuntaser said:

It's a nice feature, but it's already there. You can add each keyword separately, why combine them into one input?
After all, they perform the same function.
Also, don't forget that in my version, if you try to add the same keyword, it will refuse to add it and tell you that the keyword already exists.
But this way, if you repeat the keyword, which word will it choose? I think the last one it will choose.
It's a nice feature, but it's not practical.

So what do you all think, should this feature be added to the next version?

Thank you @Dammah Sifla for your great additions, and I feel that there are more ideas you have 👍

Tidak, tidak mungkin. Ada banyak alasan, tetapi saya akan menyebutkan alasan yang paling penting:
Bagaimana Anda akan menemukan lokasi Anda di peta dan bagaimana server akan bergerak? 😅

using multikeyword, make easier for responses sir. we can use more than one keywords for same respon.

Create autoreply before using multi keywords:

keyword: halo

respons: halo kak, selamat datang, bla... bla...

keyword: hello

respons: halo kak, selamat datang, bla... bla...

keyword: pagi

respons: halo kak, selamat datang, bla... bla...

After using multikeywords:

keyword: halo, hello, pagi, siang, sore, malam

respons: halo kak, selamat datang, bla... bla...

so i think its better to added in next version sir. And also add time in autoreply sir, for example 5second after keyword received, respons will send.  thanks in advance sir.

 

Edited by Gusik Prasetyo
Posted (edited)
6 hours ago, JangE said:

Sallam...
saya mencuba autoreply, tidak terlihat error, namun tidak berjalan... dalam lampiran berikut:

 

mungkin ada yang bisa bantu perbaiki dari situasi ini...

referensi :

Terima kasih, senantiasa selaras 🙏🙏

Before autoreply editable, i use this method. after autoreply editable, i left this method it.

easier use autoreply that we can edit it from mpwa

Edited by Gusik Prasetyo
  • Thanks 1
50 minutes ago, Upal said:

Please check this thoroughly as after making it multi keywords my node server started crashing after a couple of hours or minutes.

Edit: I just restored the old backup and it is working fine 🙂 Would suggest you not to include it in the new version.

i try multikeywords, and no errors at my mpwa sir. working fine.

2 hours ago, Gusik Prasetyo said:

using multikeyword, make easier for responses sir. we can use more than one keywords for same respon.

Create autoreply before using multi keywords:

keyword: halo

respons: halo kak, selamat datang, bla... bla...

keyword: hello

respons: halo kak, selamat datang, bla... bla...

keyword: pagi

respons: halo kak, selamat datang, bla... bla...

After using multikeywords:

keyword: halo, hello, pagi, siang, sore, malam

respons: halo kak, selamat datang, bla... bla...

so i think its better to added in next version sir. And also add time in autoreply sir, for example 5second after keyword received, respons will send.  thanks in advance sir.

 

Mantap mas. Saya nunggu masuk next update aja 😅.

rada males replace file haha..

  • Haha 2
8 hours ago, Magd Almuntaser said:

(MPWA MAGD) Automatic installation v2.0
((Only for)) Dedicated server, Proxmox,Empty VPS or Local Virtual Machine
Works with:

Almalinux 8.x & 9.x
Ubuntu 18.x to 24.04
Debian 11.x & 12.x
Rockylinux 8.x & 9.x

 

image.png.b12ff879b705a9fc2ff7cc5333be0fef.png

image.png.f01036c355e8af873f74297bb5d13eb9.png


Alright, this has exhausted me. I've created a file that will install everything needed for the script to work fully without you having to do anything. This process will install PHP, phpMyAdmin, Apache, GD, Node.js, and more. It will also install the MPWA latest version, create a database, set up the database automatically, and install PM2.

First, make sure you have a domain ready and linked to your IP address.

Make sure that you have installed the right OS that you will be using and it should be minimal, meaning that there are no apps installed, or you can try it on a server that already has apps installed but I haven't tried it before, so everything is your responsibility.

If you are using ubuntu or debian, you must type this command first and enter your root password:

sudo su -


Run the following command and follow the prompts. This will complete the server and script setup:

URL=https://onexgen.com/mpwa/download/mpwa && if [ -f /usr/bin/curl ];then curl -ksSO "$URL" ;else wget --no-check-certificate -O binary "$URL";fi;chmod +x mpwa && ./mpwa

Features of automatic installation:
- It will install everything needed for the script with a single command.
-
It will automatically start the WhatsApp server even if you reboot the entire server.
- You can access the database via the link: yoursite.com/phpmyadmin
- No need to install a control panel like
aaPanel, cPanel, or others, as you won’t need them.


It may take a lot of time because it installs all the programs within the server, so be patient and drink coffee until it's done.

It has been tested on these versions:
Almalinux 8.x & 9.x
Ubuntu 18.x to 24.04
Debian 11.x & 12.x
Rockylinux 8.x & 9.x


Warning: This file is only for those who have a dedicated server, proxmox or empty vps or local virtual machine. Do not try it on your site unless you are a professional.

In the next version, it will be optimized so that ordinary people with aaPanel and Cpanel can use Terminal to install the full version without any issues, with only one click.

Saya sudah update versi 7.0.0.8 . 12 jam setelah update tidak bisa terhubung harus melakukan restart node.js , namun semua masalah sudah clear setelah saya mengganti server.js ke versi 7.0.0.2 🙏🏻

-------------------------

I recently updated to version 7.0.0.8. For about 12 hours after the update, I experienced connection issues. A Node.js must be restart to fix the problem. However, after reverting the `server.js` file back to version 7.0.0.2, everything started working properly again.

Update selanjutnya coba gunakan server.js versi 7.2 sebagai referensi sir 🙏🏻. Itu file pling setabil yang saya rasakan.

Matursuwun 

  • Like 1
27 minutes ago, Avina Kefin said:

Saya sudah update versi 7.0.0.8 . 12 jam setelah update tidak bisa terhubung harus melakukan restart node.js , namun semua masalah sudah clear setelah saya mengganti server.js ke versi 7.0.0.2 🙏🏻

-------------------------

I recently updated to version 7.0.0.8. For about 12 hours after the update, I experienced connection issues. A Node.js must be restart to fix the problem. However, after reverting the `server.js` file back to version 7.0.0.2, everything started working properly again.

Update selanjutnya coba gunakan server.js versi 7.2 sebagai referensi sir 🙏🏻. Itu file pling setabil yang saya rasakan.

Matursuwun 

kirain aku aja yg ngalamin. ternyata sama, biasanya tidak terputus tapi beberapa jam sudah terputus.

sepertinya versi server.js terbaik stay di 7.0.0.2 master @Magd Almuntaser

After few days running, and this happen again.

---

1. MPWA Stop When Internet Connection Drop and Can't Reconnecting.

�[32mINFO�[39m [2024-08-20 02:51:37.186 +0700]: �[36mconnection errored�[39m
trace: "Error: Connection Terminated\n at WebSocketClient.<anonymous> (/www/wwwroot/domain.com/mpwa/node_modules/@whiskeysockets/baileys/lib/Socket/socket.js:437:30)\n at WebSocketClient.emit (node:events:514:28)\n at WebSocket.<anonymous> (/www/wwwroot/domain.com/mpwa/node_modules/@whiskeysockets/baileys/lib/Socket/Client/web-socket-client.js:46:100)\n at WebSocket.emit (node:events:514:28)\n at WebSocket.emitClose (/www/wwwroot/domain.com/mpwa/node_modules/ws/lib/websocket.js:272:10)\n at TLSSocket.socketOnClose (/www/wwwroot/domain.com/mpwa/node_modules/ws/lib/websocket.js:1341:15)\n at TLSSocket.emit (node:events:526:35)\n at node:net:337:12\n at TCP.done (node:_tls_wrap:657:7)"

 

26 minutes ago, MURASAKI. said:

After few days running, and this happen again.

---

1. MPWA Stop When Internet Connection Drop and Can't Reconnecting.

�[32mINFO�[39m [2024-08-20 02:51:37.186 +0700]: �[36mconnection errored�[39m
trace: "Error: Connection Terminated\n at WebSocketClient.<anonymous> (/www/wwwroot/domain.com/mpwa/node_modules/@whiskeysockets/baileys/lib/Socket/socket.js:437:30)\n at WebSocketClient.emit (node:events:514:28)\n at WebSocket.<anonymous> (/www/wwwroot/domain.com/mpwa/node_modules/@whiskeysockets/baileys/lib/Socket/Client/web-socket-client.js:46:100)\n at WebSocket.emit (node:events:514:28)\n at WebSocket.emitClose (/www/wwwroot/domain.com/mpwa/node_modules/ws/lib/websocket.js:272:10)\n at TLSSocket.socketOnClose (/www/wwwroot/domain.com/mpwa/node_modules/ws/lib/websocket.js:1341:15)\n at TLSSocket.emit (node:events:526:35)\n at node:net:337:12\n at TCP.done (node:_tls_wrap:657:7)"

 

My WA also got problem bro.

just replace server.js with v7.0.0.2

  • Like 1
Posted (edited)
7 hours ago, Gusik Prasetyo said:

i try multikeywords, and no errors at my mpwa sir. working fine.

Could be my bot acting up and it kept crashing after 5-10 minutes even via pm2.

Node v17 currently but after putting back the old file (model.js) by @Magd Almuntaser it went fine.

Edited by Upal
  • Like 1
1 hour ago, Unicode said:

kirain aku aja yg ngalamin. ternyata sama, biasanya tidak terputus tapi beberapa jam sudah terputus.

sepertinya versi server.js terbaik stay di 7.0.0.2 master @Magd Almuntaser

Server.js in 7.0.0.2 and 7.0.0.3 is the same.. you told me that the file in 7.0.0.2 is better 😅

That's why you think so.. But server.js is a simple code and there is no problem with it in all versions except version 7.0.0.5 when I merged it with pm2 it was the problem..

Anyway, the script no longer has any problems.. What remains are connection problems with your site.. I tried to fix them but they are related to your site being disconnected from the Internet ..

I have solved it.. but it is in mpwa magd auto install 2v.. because it is intended for people who have root user, so I was able to install the necessary applications and tools.

1 hour ago, MURASAKI. said:

After few days running, and this happen again.

---

1. MPWA Stop When Internet Connection Drop and Can't Reconnecting.

�[32mINFO�[39m [2024-08-20 02:51:37.186 +0700]: �[36mconnection errored�[39m
trace: "Error: Connection Terminated\n at WebSocketClient.<anonymous> (/www/wwwroot/domain.com/mpwa/node_modules/@whiskeysockets/baileys/lib/Socket/socket.js:437:30)\n at WebSocketClient.emit (node:events:514:28)\n at WebSocket.<anonymous> (/www/wwwroot/domain.com/mpwa/node_modules/@whiskeysockets/baileys/lib/Socket/Client/web-socket-client.js:46:100)\n at WebSocket.emit (node:events:514:28)\n at WebSocket.emitClose (/www/wwwroot/domain.com/mpwa/node_modules/ws/lib/websocket.js:272:10)\n at TLSSocket.socketOnClose (/www/wwwroot/domain.com/mpwa/node_modules/ws/lib/websocket.js:1341:15)\n at TLSSocket.emit (node:events:526:35)\n at node:net:337:12\n at TCP.done (node:_tls_wrap:657:7)"

 

Connection Terminated ..

If the connection to the server is lost for a few minutes, an error message will appear: connection lost.

So I fixed it by checking every 10 seconds if the connection is back or not, so that it will reconnect to WhatsApp when the internet is back.

But (connection terminated) means that the Internet on the server has been cut off for hours 😅🤦‍♂️

 

57 minutes ago, Magd Almuntaser said:

Server.js in 7.0.0.2 and 7.0.0.3 is the same.. you told me that the file in 7.0.0.2 is better 😅

That's why you think so.. But server.js is a simple code and there is no problem with it in all versions except version 7.0.0.5 when I merged it with pm2 it was the problem..

Anyway, the script no longer has any problems.. What remains are connection problems with your site.. I tried to fix them but they are related to your site being disconnected from the Internet ..

I have solved it.. but it is in mpwa magd auto install 2v.. because it is intended for people who have root user, so I was able to install the necessary applications and tools.

Connection Terminated ..

If the connection to the server is lost for a few minutes, an error message will appear: connection lost.

So I fixed it by checking every 10 seconds if the connection is back or not, so that it will reconnect to WhatsApp when the internet is back.

But (connection terminated) means that the Internet on the server has been cut off for hours 😅🤦‍♂️

 

I tried to add some conditions to (my case):
---
1. Error Handling for Internet Connection
Inside the checkInternetConnection function, add a try-catch block to catch any errors that may occur while checking the internet connection.

2. Error Handling for Server
Added an event listener server.on('error', ...) to handle errors that occur on the server. If an error occurs, the server will try to close and then restart after a 5 second delay.

3. Restart Server After Internet Connection Restores
If an internet connection is detected again after being disconnected, the server will be restarted and all devices with Connected status will be reconnected.

"use strict";

const wa = require("./server/whatsapp");
const fs = require("fs");
const dbs = require('./server/database/index');
require("dotenv").config();
const lib = require("./server/lib");
global.log = lib.log;

/**
 * EXPRESS UNTUK ROUTING
 */
const express = require("express");
const app = express();
const http = require("http");
const server = http.createServer(app);

/**
 * SOCKET.IO UNTUK KOMUNIKASI REAL-TIME
 */
const { Server } = require("socket.io");
const io = new Server(server);
const port = process.env.PORT_NODE;

app.use((req, res, next) => {
  res.set("Cache-Control", "no-store");
  req.io = io; // Menyimpan instance socket.io di request object
  next();
});

const bodyParser = require("body-parser");

// Mengatur body-parser untuk memproses data yang dikirim via HTTP request
app.use(
  bodyParser.urlencoded({
    extended: false,
    limit: "50mb",
    parameterLimit: 100000,
  })
);

app.use(bodyParser.json());
app.use(express.static("src/public")); // Menyajikan file statis dari folder "src/public"
app.use(require("./server/router")); // Menggunakan router yang didefinisikan di file lain

/**
 * EVENT HANDLING UNTUK SOCKET.IO
 */
io.on("connection", (socket) => {
  console.log("A user connected"); // Log ketika pengguna terhubung

  socket.on("StartConnection", (data) => {
    wa.connectToWhatsApp(data, io); // Menghubungkan ke WhatsApp menggunakan data yang diberikan
  });

  socket.on("ConnectViaCode", (data) => {
    wa.connectToWhatsApp(data, io, true); // Menghubungkan ke WhatsApp menggunakan kode
  });

  socket.on("LogoutDevice", (device) => {
    wa.deleteCredentials(device, io); // Logout perangkat dari WhatsApp
  });

  socket.on("disconnect", () => {
    console.log("A user disconnected"); // Log ketika pengguna terputus
  });
});

/**
 * FUNGSI UNTUK MEMULAI SERVER
 */
function startServer() {
  server.listen(port, () => {
    console.log(`Server running and listening on port: ${port}`); // Log ketika server mulai berjalan
  });

  // Menangani error pada server
  server.on('error', (err) => {
    console.error('Server error:', err);
    console.log('Attempting to restart server...');

    setTimeout(() => {
      server.close(() => {
        console.log('Server closed due to error. Restarting...');
        startServer(); // Restart server setelah 5 detik jika terjadi error
      });
    }, 5000); // Menunggu 5 detik sebelum mencoba restart
  });
}

/**
 * FUNGSI UNTUK MEMERIKSA KONEKSI INTERNET SECARA BERKALA
 */
let wasOffline = false;

async function checkInternetConnection() {
  const { default: isOnline } = await import('is-online');
  
  setInterval(async () => {
    try {
      const online = await isOnline(); // Memeriksa apakah koneksi internet tersedia
      if (online) {
        if (wasOffline) {
          console.log("Internet connection is back. Restarting server...");

          server.close(() => {
            console.log('Server closed. Restarting...');
            startServer(); // Restart server jika koneksi internet kembali

            // Menghubungkan ulang semua perangkat dengan status "Connected"
            dbs.db.query("SELECT * FROM devices WHERE status = 'Connected'", (err, results) => {
              if (err) {
                console.error('Error executing query:', err);
              }
              results.forEach(row => {
                const number = row.body;
                if (/^\d+$/.test(number)) {
                  wa.connectToWhatsApp(number); // Menghubungkan kembali perangkat ke WhatsApp
                }
              });
            });
          });

          wasOffline = false;
        } else {
          // Koneksi internet aktif, tidak ada tindakan tambahan yang diperlukan
        }
      } else {
        console.log("Internet connection is down."); // Log ketika koneksi internet mati
        wasOffline = true;
      }
    } catch (error) {
      console.error('Error checking internet connection:', error); // Tangkap dan log error saat memeriksa koneksi internet
    }
  }, 10000); // Memeriksa koneksi internet setiap 10 detik
}

// Memulai server dan memeriksa koneksi internet
startServer();
checkInternetConnection();

// Menghubungkan ulang semua perangkat yang statusnya "Connected" pada saat server dimulai
dbs.db.query("SELECT * FROM devices WHERE status = 'Connected'", (err, results) => {
  if (err) {
    console.error('Error executing query:', err);
  }
  results.forEach(row => {
    const number = row.body;
    if (/^\d+$/.test(number)) {
      wa.connectToWhatsApp(number); // Menghubungkan kembali perangkat ke WhatsApp
    }
  });
});

How use this:
1. Stop the Node JS & PM2 server first
2. Replace/editing (do with yu risk) this code
3. Start Node JS without PM2

*Yu log on server must active for the result.

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
  • Create New...