@TheTagBot is a Telegram bot that lets you save and retrieve media using your own tags.
If you want to host your own copy of this bot, here's how:
-
Get Nix running on your system (preferably use NixOS)
-
Install Elasticsearch
-
Copy secrets-example.py to
secrets.py
and edit theHTTP_PASS
variable to a secure password (for examplehunter2
), this is the password for the Elasticsearch user that the bot will use -
Setup security in Elasticsearch by putting the following into
$ES_PATH_CONF/elasticsearch.yml
:xpack.security.enabled: true discovery.type: single-node
Then run (as the same user that Elasticsearch runs as):
elasticsearch-setup-passwords auto
Put the generated password for the
elastic
user insecrets.py
:HTTP_PASS = '<super secret password that you generated earlier>' ADMIN_HTTP_PASS = 'elastic user password here'
-
Now you can run the bot using
nix-shell
in the repo root:nix-shell shell.nix --run 'python bot.py'
The bot will take care of setting up the Elasticsearch indicies that it needs.
-
Telethon will prompt for your bot token when you first run the bot, when you move it to a server simply copy the
bot.session
file to the server.
You can change the limits in constants.py to suit your needs.
When you want to make changes to the index mapping, you have to delete and re-create it with the new settings. The scripts
directory has two scripts that can help with this:
- backup.py makes the index read-only and copies all the documents into a backup index
- recreate.py deletes and re-creates the index with the settings in
settings.json
, then copies the documents from the backup (you can run this multiple times after having run backup.py once)