Telegram Bot for MCL nodes status tracking
- Write in Telegram to @BotFather to register your bot. You’ll need to specify a bot name and username. In response, you’ll receive an HTTP API token — save it in a safe place. You’ll need it later.
2. Create a private Telegram channel (Go to Menu -> New Channel -> Input name -> Select Private)
3. Add your bot as an administrator of this channel.
4. You’ll need to get your channel ID so the script will know where to send messages.
To do this, perform a little trick: write any message to your channel, right-click on the message and select “Copy post link”, then paste the link somewhere.
You’ll get a link like this: https://t.me/c/1489973255/
Number after “c” is your channel ID. In my case, it is 1489973255. Add -100 to it and save it somewhere (-1001489973255 in this example).
5. Now, we are ready to set up our script. First, let’s install the required dependencies:
sudo apt-get install python3.7 python3-pip libgnutls28-dev
pip3 install setuptools wheel slick-bitcoinrpc python-telegram-bot
6. Create a Python script to check the daemon status and post updates to TG.
Code:
https://gist.github.com/tonymorony/6c87e50ad63eed6a9b72e86c3556b33a
Put your bot API key between quotation marks on this line.
https://gist.github.com/tonymorony/6c87e50ad63eed6a9b72e86c3556b33a#file-bot_example-py-L54
And your channel ID (with -100) on this line:
https://gist.github.com/tonymorony/6c87e50ad63eed6a9b72e86c3556b33a#file-bot_example-py-L55
7. We all done! Now you can try to update the status manually. Try executing:
python3 name_of_script_from_gist.py
Check if messages are posted into the channel. If they are, you are set up correctly and you are ready to automate the check.
8. I’m using cron for it
crontab -e# m h dom mon dow command
*/2 * * * * python3 /home/tony/marmara_count_balances.py
In this example of a cron setup script executing every 2 minutes (your path to the script and script name will be different), that’s it!
Note that it’s just an example of such a simple bot setup. It’s quite easy to modify the Python script to do more interesting things