A Telegram bot wrapper to run HA bots
Project description
habot
A Python package to run highly available Telegram bots
Usage
Install habot with pip:
pip install -i https://test.pypi.org/simple/ habot
(Habot will move to proper pypi at some later date)
Then import and you have two interesting functions available for you code:
import habot
habot.bot.run_primary_backup_model(updater, instances)
habot.bot.run_bot_only(updater)
Of these the latter will only start_polling() and idle() for an Updater of a Telegram bot made using python-telegram-bot package.
run_primary_backup_model will in addition to the bot run a primary-backup system between the instances. The instance is a list of IPs or host/domain names. The workings of the primary-backup model are described in the section below.
How the primary-backup model works
In the primary-backup model, bot code can be started for multiple instances. Primary is the instance that has become primary with the lowest timestamp.
First every instance starts looking for a primary. In case ans instance can find no primary:
- The instance becomes primary with its current timestamp
- The instance starts broadcasting that timestamp for other instances by spawning a HTTP server thread
- Another thread of the instance keeps looking for potential alternative primary with a lower timestamp
- A watcher thread checks that the other two threads remain alive.
- Bot code is started in the main thread.
In case the instance does find a primary, it just keeps periodically looking for a primary in the main thread.
If the primary instance A finds another instance B that has become primary with lower timestamp:
- A stops all its threads.
- And restarts the cycle by looking for a primary instance.
Security
The instances communicate between themselves over HTTP
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file habot-0.0.3.tar.gz.
File metadata
- Download URL: habot-0.0.3.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0f14824eb2b20a627ad4abe467deaa27f0b0b0dd1ab98472321827889ee62b3
|
|
| MD5 |
9e4a866d23128194efa4389873620848
|
|
| BLAKE2b-256 |
d873856ba330ba9bf3a044db468a19d5f9d409dbce6d9f45d6abb306a359a5f2
|
File details
Details for the file habot-0.0.3-py3-none-any.whl.
File metadata
- Download URL: habot-0.0.3-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bcb6296f08256825b91943a05a914d6c98c915e967a747d01b92af12b2c801a
|
|
| MD5 |
107593c276040550635a8f258d13736e
|
|
| BLAKE2b-256 |
6fcebb9babf0bbfc0b6b32e3f181d1a4230f243b2aa0eae514376dc199249d6b
|