Telegram Notification Service
To listen for update announcements, join the following channels:
A telegram bot to monitor the status of THORNodes.
- Docker (if you want to run with docker or docker-compose)
- Docker Compose (if you want to run with docker-compose)
- Python3 (if you want to run without docker)
variables.envfile and set
TELEGRAM_BOT_TOKENto your Telegram Bot Token obtained from BotFather.
THORCHAIN_NODE_IPto any THORNode IP you want to monitor (or
localhost). Leave it empty or remove it to use testnet seed Node IPs.
BINANCE_NODE_IPto any Binance Node IP you want to monitor (or
localhost). Leave it empty or remove it to not monitor a Binance Node.
ADMIN_USER_IDSto a list of Telegram User IDs that are permissioned to access the Admin Area.
docker-compose up -d
Install all required dependencies via:
pip install -r requirements.txt
/newbotin the chat, and follow the given steps to create a new telegram token. Save this token, you will need it in a second.
Set the telegram bot token you just created as an environment variable:
Next you can specify the IP of the Thornode that you want to watch in the
Set it to
localhostto listen a node on your own machine.
If you have a Binance Node IP that you want to monitor, you can set
BINANCE_NODE_IPto this IP. Set it to
localhostif the Binance Node runs on the same machine as the Telegram Bot.
Leave this environment variable empty or don't even set it to not do any Binance Node monitoring.
Next set Telegram User IDs that are permissioned to access the Admin Area in the
ADMIN_USER_IDSenvironment variable. Leave the default dummy values if you do not intend to use the Admin Area.
To find out your Telegram, open your Telegram Client, and search for the Telegram Bot
@userinfobot. Ensure that this is a Bot and not a Channel and has exactly the handle
@userinfobot, as there are a lot of channels and bots with similar names. Start this Bot and it returns you your User ID that you need to export in
If you enter multiple User IDs, make sure to separate the IDs with
,i.e. a comma.
Finally, if you want test the Thornode Telegram Bot with data from your local machine, you need to set the debug environment variable:
The DEBUG flag set to True will run a local web server as a separate process. This way the telegram bot can access the local files
To test whether the bot actually notifies you about changes, the data the bot is querying needs to change. You can simulate that by manually editing
Furthermore in DEBUG mode a separate process runs
increase_block_height.pywhich artificially increases the block height so that there are no notifications that the block height got stuck.
If you are using a Jetbrains IDE (e.g. Pycharm), you can set these environment variables for your run configuration which is very convenient for development (see: https://stackoverflow.com/questions/42708389/how-to-set-environment-variables-in-pycharm).
Start the bot via:
Make sure that you see a message in the console which indicates that the bot is running.
When you created the telegram bot token via BotFather, you gave your bot a certain name (e.g.
thornode_bot). Now search for this name in Telegram, open the chat and hit start!
At this point, you can play with the bot, see what it does and check that everything works fine!
The bot persistents all data, which means it stores its chat data in the file
storage/session.data. Once you stop and restart the bot, everything should continue as if the bot was never stopped.
If you want to reset your bot's data, simply delete the file
storagedirectory before startup.
In production you do not want to use mock data from the local endpoint but real network data. To get real data just set
DEBUG=Falseand all other environment variables as described in the 'Set environment variables' section. If you're using docker-compose to run this Bot, modify the existing variables in
variables.envfile (No need to set DEBUG as there's no DEBUG mode in the docker version).
Navigate to the root directory of this repository and execute the following commands:
Build the docker image as described in the
docker build -t thornode-bot .
To make the bot's data persistent, you need to create a docker volume. If the bot crashes or restarts the volume won't be affected and keeps all the session data:
docker volume create thornode-bot-volume
Finally run the docker container:
docker run --env TELEGRAM_BOT_TOKEN=XXX --env THORCHAIN_NODE_IP=XXX --env BINANCE_NODE_IP=XXX -v /var/run/docker.sock:/var/run/docker.sock --mount source=thornode-bot-volume,target=/storage thornode-bot
--env TELEGRAM_BOT_TOKENflag to your telegram bot token.
--env THORCHAIN_NODE_IPflag to an IP of a running THORNode, or to
localhostif the THORNode runs on the same machine as the Telegram Bot. If you don't know any IP leave this empty i.e.
--env THORCHAIN_NODE_IP=or remove it completely - then the Telegram Bot works with testnet seed node IPs from https://testnet-seed.thorchain.info.
--env BINANCE_NODE_IPflag to an IP of a running Binance Node, or to
localhostif Telegram Bot and Binance Node run on the same machine. Leave this empty i.e.
--env BINANCE_NODE_IP=or remove it to not do any Binance monitoring.
-vargument passes the dockersocket to the container so that we can restart docker containers from inside the Telegram Bot.
--mountflag tells docker to mount our previously created volume in the directory
storage. This is the directory where your bot saves and retrieves the
There is a health check in the Dockerfile that runs the
healthcheck.pyfile. The script assures that
thornode_bot.pyis periodically updating the
If the docker health check fails, the docker container is marked as "unhealthy". However, when using docker standalone (without docker compose or docker swarm) this doesn't do anything. To restart unhealthy containers, we have to use the autoheal image https://hub.docker.com/r/willfarrell/autoheal/ .
To make sure a potentially unhealthy thorbot_node container is restarted, run the autoheal container alongside the thornode_bot container:
docker run -d --name autoheal --restart=always -v /var/run/docker.sock:/var/run/docker.sock willfarrell/autoheal
The explained steps in the Docker Standalone section are conveniently bundled into a
First, as before, you need to set the right values in the
If you don't want to spin up the official docker image from our dockerhub, open
docker-compose.yamland comment out the line
image: "block42blockchaincompany/thornode_bot:latest"and comment in the line
Finally, start the Thornode Telegram Bot with:
docker-compose up -d
If you have problems running 'docker-compose up' while using a VPN, try to this:
- First run in your console
docker network create vpnworkaround --subnet 10.0.1.0/24
- Then comment in the networks configuration in
- Run again in your terminal
docker-compose up -d
To test the Thornode Bot, you need to impersonate your own Telegram Client programmatically.
To do that, you need to obtain your API ID and API hash by creating a telegram application that uses your user identity on https://my.telegram.org . Simply login in with your phone number that is registered on telegram, then choose any application (we chose Android) and follow the steps.
Once you get access to api_id and api_hash, save them in the Environment variables
TELEGRAM_API_HASHrespectively. Also save the name of your Telegram Bot without the preceding
TELEGRAM_BOT_IDenvironment variable (e.g. if your bot is named
You also need to have set the
TELEGRAM_BOT_TOKENenvironment variable with your telegram bot token, set
ADMIN_USER_IDSwith permissioned IDs and set
DEBUG=Trueas explained in previous sections. If you want to test the restarting of docker containers, do not forget to start at least one container on your system.
Keep in mind that the test always deletes the
storage/in order to have fresh starts for every integration test. If you wish to keep your persistent data, don't run the integration test or comment out the line
To run the test open the
test/folder in your terminal and run
The test should endure several minutes. Every command succeded if you see
-----ALL TESTS PASSED-----at the end.