Skip to content

Telegram BOT based on Node.JS and TypeScript for managing Wireguard VPN.

Notifications You must be signed in to change notification settings

PKSpeleo/telegram-bot

Repository files navigation

Telegram BOT based on Node.JS and TypeScript for managing Wireguard VPN.

This is Telegram BOT based on Node.JS and TypeScript for managing Wireguard VPN accounts, with automatic deployment based on GitHub Actions.

It must have a lot of nice features, soon ;)

Work in progress...

ATTENTION!

Telegram Chat ID can be changed if

  • Changed type of the Group from Private to Public
  • Switched on History visibility for new users

Looks like Chat id can be changed only once - from short to long, and then it will stay long without changes.

By the way! Here you can find my Wireguard Config File Parser and Serializer on TypeScrip with tests;)

What I want to do:

  • Support different bots (server_1, server_2, dev) in one repo.
  • Automatic deploy to different servers
  • Bot must know who is Boss, what chats are supported and who is known user from supported chat
  • Update Documentation to collect all necessary information about how to start this bot (with auto deploy) on fresh VPS.
  • Implement logging to Bosses private chat that someone using the Bot.
  • Implement same logging to local file on server (with write queue).
  • Lunch console commands and parse the result by Bot command form Boss
  • Implement Wireguard Config File Parser and Serializer
  • Explore commands to update Wireguard
  • Implement adding new user and rebooting Wireguard
  • Generate new user data (config for server and for user)
  • Implement whole flow of the user creation with Bot

Known problems

  • Figure out with wired behaviour when admin post and call /commands in Channels comments (works fine for users)
  • Need to refactor monster Wireguard Config File Parser and Serializer
  • Get rid of tests based on real commands and filesystem

Preparation.

This BOT supposed to bi started on VPS servers with Ubuntu 20. Below you will find short instruction how to prepare VPS, what and how need to be installed and how organise your BOT developing process with automatic deploy by GitHub Actions.

Prepare your machine

Right now these documentations looks like collection of necessary commands for run everything and do not search them aging in documentations. Maybe later it will be better ;)

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Then install Node:

nvm install 16.14.2
nano ~/.ssh/config
Host *
ForwardAgent yes

Host vps_server
    HostName 1.1.1.1
    User root
    IdentityFile ~/.ssh/vps_rsa

Now you can access server by ssh vps_server

  • Add Wireguard tools to macOS for debugging=)
brew install wireguard-tools
  • Add GitHub tools to manage secrets ;)
brew install gh

Prepare VPS

  • Copy PUB Rsa key to the Server
 scp ~/.ssh/vps_rsa.pub vps_server:~/.ssh/
  • Add key to the config
cat ~/.ssh/rsa.pub >> ~/.ssh/authorized_keys
  • Update apt-get
apt-get update
  • Install speedtest
curl -s https://install.speedtest.net/app/cli/install.deb.sh | bash &&
apt-get install speedtest
  • Install resources monitor htop
apt install htop
  • Install network monitor nload
apt install nload
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
  • Install Node:
nvm install 16.14.2
  • Install PROCESS MANAGER FOR NODE.JS pm2
npm install pm2 -g
  • Install zip fo backups
apt install zip

Using PM2 for lunching pre-build and bundled node app

  • Copy PM2 config file to the server
scp ecosystem.config.js vps_server:/root/telegram-bot
  • Copy telegram_bot.js and go to the server, lunch the app by PM2 and add to startup:
pm2 start ecosystem.config.js && \
pm2 startup
  • Stopping and removing from startup
pm2 stop ecosystem.config.js && \
pm2 unstartup && \
pm2 delete ecosystem.config.js
  • Useful commands
pm2 restart all
pm2 stop all
pm2 start all
pm2 list
pm2 monit

About

Telegram BOT based on Node.JS and TypeScript for managing Wireguard VPN.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages