Telegram Bot¶
You can add new torrents via Telegram bot.
Register bot¶
- Register your bot with BotFather as described in https://core.telegram.org/bots#6-botfather
Note
If you have already configured notifications with Telegram you don’t need create a new bot. Use an existing one.
Install
python-telegram-bot
library to your python environment with$ pip install python-telegram-bot
You may install torrt with required dependencies with:
$ pip install torrt[telegram]
Configure torrt to use the bot:
$ torrt configure_bot telegram token=YOUR_TOKEN
Restricts users (comma-separated) talking to the bot with option
allowed_users
:$ torrt configure_bot telegram token=YOUR_TOKEN allowed_users=user1,user2
Create a new Telegram group and add the bot.
Listen to commands¶
Start listening to user commands:
$ torrt run_bots
Now your bot is ready to accept messages and fully functional.
Note
It is recommended to start run_bots
process using a process management system (see supervisord
or systemd
configuration example below).
Talking to the bot¶
Bot supports a number of commands.
To start new conversation with bot use command:
/start
and follow further instructions. You can add new, list or remove already registered torrents.
Note
If you want to cancel current operation use /cancel command.
Add a torrent using
/add
command (torrent is downloaded to a default directory.):/add https://rutracker.org/forum/viewtopic.php?t=1234567
All registered torrents can be viewed with:
/list
To remove torrent use command:
/remove
To show all available commands use:
/help
Supervisor configuration¶
Here described how to configure and start torrt’s Telegram bot with supervisord
.
Install
supervisord
on your host as described at http://supervisord.org/installing.htmlCreate configuration file
torrt.conf
at/etc/supervisor/conf.d/
:[program:torrt] directory=/tmp command=PATH_TO_TORRT_SCRIPT run_bots user=USER_ON_HOST autostart=true autorestart=true
ReplacePATH_TO_TORRT_SCRIPT
with a location of torrt executable file andUSER_ON_HOST
with a user starting a process.
Start process with following commands:
# supervisorctl reread # supervisorctl reload # supervisorctl start torrt
Systemd user service¶
If you are running basically any modern Linux distribution you can run Telegram bot under your user with systemd
,
without having to deal with global system configuration.
Mark your user as the one allowed to ‘linger’
# loginctl enable-linger `whoami`
Create service definition in your home directory:
$ mkdir -p ~/.config/systemd/user/ $ echo << "EOF" > ~/.config/systemd/user/torrt.service [Unit] Description=torrt bot [Install] WantedBy=default.target [Service] ExecStart=PATH_TO_TORRT_SCRIPT run_bots EOF
Replace
PATH_TO_TORRT_SCRIPT
with a location of torrt executable fileStart Service
$ systemctl --user daemon-reload $ systemctl --user start torrt
(Optional) Enable service autostart
$ systemctl --user enable torrt