Skip to main content

An asynchronous Telegram bot designed for sending alerts and notifications with a message queuing system.

Project description

Telegram Alert Bot

PyPI version Python versions License Downloads Code style: black

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

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
  1. __init__(token: str, user_id: str)

    • token: Your Telegram bot token
    • user_id: The Telegram user ID to send messages to
  2. async send_telegram_message(message: str)

    • Sends a message directly to the specified user
    • Handles Telegram API errors and logs the outcome
  3. async background_bot_polling()

    • Runs continuously in the background
    • Processes messages from the queue
    • Should be run in a separate task
  4. 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

telegram_alert_bot-0.1.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

telegram_alert_bot-0.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file telegram_alert_bot-0.1.1.tar.gz.

File metadata

  • Download URL: telegram_alert_bot-0.1.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for telegram_alert_bot-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0223f57fa6ff8fb967961103ca142b489dccf24488432eca42fa9ec47c4b27f9
MD5 32b1f5f76b12b607a5950e5aaba8eb6f
BLAKE2b-256 bbef94b84a7d25f39fdc98733f761c821a2ae61a0a84df121b9e8410f2733d91

See more details on using hashes here.

File details

Details for the file telegram_alert_bot-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for telegram_alert_bot-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5d1fe7caa04018b78943ff6d24d5d4663d265ec4ad40a704cca8cad08ab0bb96
MD5 cc6ca82da98dcbb187f2b4f50da68e30
BLAKE2b-256 63b966a544d9fd5c7f4b8c960402f5b6d3db8419a1e5ba1a3fbac6f10e65684c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page