Use webhook without domain
This topic explains how to deploy your Telegram bot (use webhook) on a VPS using a self-signed certificate and IP address instead of a domain, with the help of nginx
, openssl
, docker compose
, and of course, dehuckakpyt.telegram-bot
.
Install requirements
sudo apt install nginx
– installs the NGINX web server.sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
– installs Docker Engine and Docker Compose plugins.
Set configs
We'll use /work-directory
as the working directory.
cd /work-directory
– navigate to the working directory.copy your bot project to
/work-directory/webhook-example-telegram-bot
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 36500 -nodes
– generates a self-signed SSL certificate and private key. Important: Be sure to specify your IP address in theCommon Name
field when prompted.copy
cert.pem
to your project under/resources/cert.pem
nano /work-directory/docker-compose.yaml
– create the Docker Compose configuration file:
telegram-bot.spring.update-receiver.webhook.url.host
– the URL where Telegram will send webhook updates.
telegram-bot.spring.update-receiver.webhook.certificate.path
– the path to your certificate inside the application resources.
telegram-bot.spring.update-receiver.webhook.secret-token.random-generation.print-on-startup
– prints the auto-generated value for the X-Telegram-Bot-Api-Secret-Token
header to the console at startup.
nano /work-directory/webhook-example-telegram-bot/Dockerfile
– create the Dockerfile for building and running your bot:
nano /etc/nginx/conf.d/default.conf
– configure NGINX to serve your bot over HTTPS:
Start services
systemctl start nginx
– starts nginx service.systemctl enable nginx
– starts automatically on system reboot.systemctl restart nginx
– reload service after changing config.systemctl status nginx
– check that service starts.docker compose build --no-cache && docker compose up -d
– build and start application.
Testing
You can check if the bot is working by simply sending it a message in Telegram. Alternatively, you can manually send a test request using the following curl command:
You should receive a 200 OK response if everything is configured correctly.