HiveBot
HiveBot simplifies the process of hosting multiple PTB Telegram bots by leveraging request multiplexing to the appropriate bot handlers based on the selected bot in each chat session.
Hosting multiple Telegram bots typically requires each bot to have its own dedicated bot account and server configuration, which can be a chore. With HiveBot, developers can consolidate multiple bots within a single account. Simply add the tenant bot code to the dedicated folder within HiveBot's directory structure and HiveBot then handles the routing of incoming messages to the respective bot handlers based on the selected bot in each chat session.
Quickstart
-
You will need to get your own Telegram API token from @BotFather. Click here for the instructions.
-
Setup the necessary environment variables by copying
.env.templateto.envand editing.env. -
Start HiveBot. Some example bots have already been added to the
botsfolder.python main.pyYou may need to use Poetry to install the necessary Python dependencies first. If you are using Nix, just
nix runwill suffice! -
In Telegram, navigate to your bot chat.
- Send a
/startfirst if necessary (Telegram requires users to send a/startbefore bots can receive subsequent messages). - Send
/switchto toggle between tenant bots.
- Send a
Adding tenant bots
Additional tenant bots can be added to HiveBot using the dedicated bots folder.
The code for each tenant bot can be a single file or multiple files consolidated within a folder.
There are minimal restrictions on the structure of the code of the tenant bots:
- For bots with single Python file: Ensure that the file has a
main()function.