An asynchronous Telegram bot designed for sending alerts and notifications with a message queuing system.
Project description
Telegram Alert Bot
A simple asynchronous Telegram bot for sending alerts and notifications with message queuing capabilities.
Features
- Asynchronous message handling
- Message queuing system
- Error handling for Telegram API communications
- Support for mentioning other bots in messages
- Logging functionality
- Optional message merging based on a specified pattern
Installation
pip install telegram-alert-bot
Prerequisites
- Python 3.7+
- python-telegram-bot library
- A Telegram Bot Token (obtained from @BotFather)
- Your Telegram User ID
Usage
Basic Setup
from telegram_alert_bot import TelegramAlertBot
import asyncio
# Initialize the bot
bot = TelegramAlertBot(
token="YOUR_BOT_TOKEN",
user_id="YOUR_TELEGRAM_USER_ID"
)
# Create an async function to run your bot
async def main():
# Start the background polling
polling_task = asyncio.create_task(bot.background_bot_polling())
# Trigger an event (send a message)
await bot.event_trigger("Hello, World!", "mybot")
# Wait for the message to be processed
await bot.message_queue.join()
# Run the bot
asyncio.run(main())
API Reference
TelegramAlertBot Class
The main class for handling Telegram alerts. Implementation can be found in:
startLine: 6
endLine: 31
Methods
-
__init__(token: str, user_id: str)token: Your Telegram bot tokenuser_id: The Telegram user ID to send messages to
-
async send_telegram_message(message: str)- Sends a message directly to the specified user
- Handles Telegram API errors and logs the outcome
-
async background_bot_polling()- Runs continuously in the background
- Processes messages from the queue
- Should be run in a separate task
-
async event_trigger(message: str, bot: str)- Queues a new message for sending
- Automatically adds bot mention in format
@bot - Messages are processed in FIFO order
Error Handling
The bot includes built-in error handling for Telegram API communications. All errors are logged using Python's logging module. Error handling implementation can be found in:
startLine: 14
endLine: 18
Logging
The bot uses Python's built-in logging module to track:
- Message sending attempts
- Successful message delivery
- Error states
- Event triggers
- Bot polling status
Version
Current version: 0.1.0
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Support
For support, please open an issue in the GitHub repository.
Authors
pudjo_jotaro https://github.com/pudjojotaro
Project details
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 telegram_alert_bot-0.2.0.tar.gz.
File metadata
- Download URL: telegram_alert_bot-0.2.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4d17a1a46522588f1c8d44e6b56c6072b718f009255fc533fe94c686b0c3b7c
|
|
| MD5 |
f17d009987859bb19eeba1154a84c6c4
|
|
| BLAKE2b-256 |
01a9a4e4d215fd60b6e6503ec205e22009972874ca07b928c70f35251e70e8ee
|
File details
Details for the file telegram_alert_bot-0.2.0-py3-none-any.whl.
File metadata
- Download URL: telegram_alert_bot-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9b13406adddeb798115921e94a8111cd0c2eda8189f9dff7a4a4e213181b490
|
|
| MD5 |
b986efb59c75e5ddf46b883f2e354ea4
|
|
| BLAKE2b-256 |
caf632d83d03297850744d4d4250ac70c24448045aa0cdfb995e39fee631f77d
|