Skip to content

Flexible Telegram bot designed to manage Docker containers, monitor server status, and extend its functionality through a plugin system

License

Notifications You must be signed in to change notification settings

orenlab/pytmbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

pytmbot

pyTMbot

A simple Telegram bot to handle Docker containers and images, also providing basic information about the status of local servers. The bot operates synchronously. It does not use webhooks.

Security Rating Vulnerabilities Quality Gate Status Bugs Maintainability Rating Code Smells Duplicated Lines (%) Codacy Badge Production Docker CI

The bot was written using the pyTelegramBotAPI. Use psutil and docker-py libraries for gather information.

🐳 A large section on Docker

  • Information about containers (even those that have finished work)
  • The ability to view container logs
  • Information about images

πŸ’‘ Features

  • Load average information
  • Summary memory usage information (with swap)
  • Sensors information
  • Summary process information
  • Uptime information
  • File system base information
  • Basic information about the network connection

πŸ”– Additionally:

  • The "About Me" section, which allows users to check for updates regarding the bot: /check_bot_updates
  • The Jinja2 templating engine is used to generate the responses.
  • The bot logs are accessible in the Docker log aggregator.
  • And of course we use emoji πŸ˜…

Screenshots are available here: screenshots.md.

πŸ•Έ Requirements

Initially, I designed the bot to run only inside a Docker container. However, this method has some limitations, so from version 0.9.0 onward, it is possible to install the bot locally outside the container. At the same time, the bot will still be able to function and receive information about Docker containers.

Full list of Python dependencies see in requirements.txt. List of Python dependencies for self setup bot see in setup_req.txt

πŸ”Œ Installation, setup and run bot

πŸ›‘ Secure

An authorization mechanism has been built into the pyTMbot management system. To describe the principle of its operation in the most concise way, we can say the following:

  • At the initial stage of configuration, we set the unique identifiers of users who are allowed to access the bot (ALLOWED_USER_IDS), regardless of which official method is used.
  • With each new request for the bot, the middleware AccessControl is activated first. It checks whether the variable from_user.id matches the values specified in the settings. If a match is found, the request is sent to the appropriate handler.
  • In all other cases, a mechanism is triggered that informs the user that they do not have access to the bot and stops processing.

In the alpine-dev build (and the next release 0.1.2), this mechanism has been expanded:

  • The bot now reacts to incoming requests by reporting the lack of access twice, then completely stops processing messages.
  • All failed attempts to authorize are logged with an DENIED and BLOCKEDflag.

For stable version, failed attempts to authorize are logged with an ERRORflag.

πŸ’’ Supported commands

In addition to button navigation, the bot also supports commands. Below is a list of commands and their details:

# Command Keyboard button Note
1 /start None -
2 /help None -
3 /docker 🐳 Docker -
4 /containers 🧰 Containers Button available in the Docker section
5 /images πŸ–ΌοΈ Images Button available in the Docker section
6 /back πŸ”™ Back to main menu Button available in the Docker section
7 /check_bot_updates None -

🌲 Bot tree

πŸ“ˆ Roadmap

πŸ‹ pyTMbot on Docker Hub

GitHub Release Docker Pulls Docker Image Size Github last-commit

🧬 Authors

πŸš€ About Me

I am a novice Python developer. This is my first publicly available project in this great programming language.

πŸ“œ License

MIT License