Example of preparing a server environment on Ubuntu operating system#
After creating a machine for the server, you have to configure a firewall on it, install the necessary components and start up the server.
Ubuntu 20.04 and higher are supplied with Python 3 pre-installed . Update the system:
sudo apt update
sudo apt -y upgrade
You should set up firewall rules. In Ubuntu, the UFW firewall is installed by default, but if for some reason it is not installed, install it:
sudo apt install ufw
sudo ufw allow ssh
First, create the default firewall rules:
sudo ufw default deny incoming
sudo ufw default allow outgoing
Allow HTTP and HTTPS connections:
sudo ufw allow ssh
sudo ufw allow http
If your server has a public network interface named eth0, you can allow HTTP traffic (port 80) to that interface with the following command:
sudo ufw allow in on eth0 to any port 80
You can find the network interface name using the command:
ip addr
UFW firewall activation:
sudo ufw enable
Now our server can accept incoming requests on the port we have specified.
Install the pip package management system if the OS distribution doesn't contain it:
sudo apt install python3-pip
Now we can install our library.
Library installation:
python3 -m pip install whatsapp-api-webhook-server-python-v2
As an example, you can run our receive_all_with_counter.py script on the server. It will output information on the received webhooks to the console:
wget https://github.com/green-api/whatsapp-api-webhook-server-python-v2/blob/master/examples/receive_all_with_counter.py
python3 receive_all_with_counter.py