CTRL Telegram WebApp backend
You'll need to have the following environment to run this project
- Node.js 20+
- pnpm
- git
You can find more detailed version-constrains for Node.js and pnpm in package.json.
Follow these steps to start developing.
- Clone this repository
git clone https://github.com/ctrlsa/ctrl-app-backend.git
- Install app dependencies
pnpm i
- To start development server run
pnpm run dev
We are not using Docker containers or any virtualization yet. The following describes the steps that will allow you to deploy the app on the VPS or a cloud instance.
ℹ️ NOTE: Tested only on Debian
git clone https://github.com/ctrlsa/ctrl-app-backend.git
pnpm i
You need a domain name to deploy a Telegram WebApp.
Create a subdomain on one of your existing domain names (e.g. botapi.example.com) or register a new one. Delegate the domain name to your server (VPS or cloud).
Create a new Telegram bot using BotFather and obtain an API token.
The app will only work over the HTTPS protocol. You have to use an SSL certificate for Telegram Web Apps.
You can use free Let's Encrypt certificate (recommended) or buy a certificate from one of many authorities/sellers.
Follow the steps below to issue a free SSL certificate via Certbot
⚠️ There is NO need to follow official instructions from Certbot website
- Install Certbot:
sudo apt install certbot
- Make sure that port 80 is available
sudo netstat -tnlp | grep :80
If you see that some service is using port 80, stop it for a while to obtain a certificate
- Issue a new SSL certificate for your domain name:
sudo certbot certonly --standalone -d botapi.example.com
- Make sure auto update of your certificate is enabled and working properly
CTRL app uses Nginx as a reverse proxy.
Install Nginx on your server if it is not installed:
sudo apt install nginx
Once Nginx has been installed, you need to configure it. We will also use the SSL certificate we generated earlier.
The repository already has a ready-made config that you just need to copy and make the necessary changes:
Copy config
file from nginx
foder to /etc/nginx/sites-available
on your server.
Rename the config file from /etc/nginx/sites-available/config
to, for example /etc/nginx/sites-available/botapi.example.com
Edit config and set proper values:
sudo nano /etc/nginx/sites-available/botapi.example.com
Edit this config
file and set proper values:
server_name
(e.g.botapi.example.com
)ssl_certificate
andssl_certificate_key
paths (e.g./etc/letsencrypt/live/botapi.example.com/fullchain.pem
)root
path underlocation /
(e.g./home/botapi.example.com/public
)
Create a symbolic link to enable our coinfig:
sudo ln -s /etc/nginx/sites-available/botapi.example.com /etc/nginx/sites-enabled/botapi.example.com
Restart Nginx:
sudo service nginx restart
Edit config.js
and set proper values:
BOT_TOKEN
(obtained form BotFather)WEBHOOK_HOST
- a valid URL (host + optional port, e.g.https://botapi.example.com:8080
)
pnpm run start &
CTRL backend is licensed under the MIT License