A Python library for handling webhooks with ease.
Project description
Dispatchy: Simplified Webhooks for Discord and Telegram
Description
Dispatchy is a Python library designed to simplify sending messages via Discord and Telegram webhooks. It provides an intuitive and consistent interface for interacting with these services, handling tasks such as:
- Constructing message payloads
- Sending requests to the webhook URLs
- Handling errors and retries
The library aims to make it easy to send simple text messages, as well as more complex messages with embeds, files, and other features.
Features
General
- Simplified API: Easy-to-use classes and methods for sending webhook messages.
- Error Handling: Includes custom exception classes for Discord and Telegram API errors, along with logging.
- Retries with Backoff: Automatic retries with exponential backoff for handling temporary network issues.
Discord
- Sending text messages
- Setting username and avatar
- Sending text-to-speech messages
- Sending embeds (with full property support)
- File uploading
- Thread management
- Setting message flags
- Controlling allowed mentions
- Sending message components (buttons, select menus)
Telegram
- Sending text messages
- Setting parse mode (HTML, Markdown, MarkdownV2)
- Sending various media types (photos, audio, documents)
- Using reply keyboards and inline keyboards
Installation
pip install requests # Dispatchy depends on the requests library
pip install dispatchy
UsageDiscordfrom dispatchy import DiscordWebhook
import logging
logging.basicConfig(level=logging.INFO)
webhook_url = "your_discord_webhook_url" # Replace with your Discord webhook URL
try:
webhook = DiscordWebhook(url=webhook_url)
webhook.set_content("Hello from Dispatchy!")
# Example Embed
embed = {
"title": "My Embed Title",
"description": "This is the embed description.",
"color": 3447003, # Blue
"author": {"name": "Author Name", "url": "[https://example.com](https://example.com)"},
"fields": [
{"name": "Field 1 Name", "value": "Field 1 Value", "inline": True},
{"name": "Field 2 Name", "value": "Field 2 Value", "inline": True},
],
"footer": {"text": "Embed Footer Text"},
}
webhook.add_embed(embed)
# Example of adding a file
# webhook.add_file("path/to/your/file.txt")
response = webhook.send()
print(f"Message sent! Status code: {response.status_code}")
except Exception as e:
logging.error(f"An error occurred: {e}")
Telegramfrom dispatchy import TelegramWebhook
import logging
logging.basicConfig(level=logging.INFO)
bot_token = "your_telegram_bot_token" # Replace with your Telegram bot token
chat_id = "your_telegram_chat_id" # Replace with the chat ID
try:
webhook = TelegramWebhook(token=bot_token)
webhook.set_chat_id(chat_id)
webhook.set_text("Hello from Dispatchy!")
webhook.set_parse_mode("MarkdownV2") # Optional: "HTML", "Markdown", "MarkdownV2"
response = webhook.send()
print(f"Message sent! Status code: {response.status_code}")
except Exception as e:
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 dispatchy-0.0.1.tar.gz.
File metadata
- Download URL: dispatchy-0.0.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad080220c383d580006a9b64efb18ace1db8ac15c03884cedcbb201018a69534
|
|
| MD5 |
c216b39745af82cf973b9922fff0e7e6
|
|
| BLAKE2b-256 |
08c8381d7abfb8fdb198b5499df7d9bb78c16390daf6643f0408ab575f9d9a11
|
File details
Details for the file dispatchy-0.0.1-py3-none-any.whl.
File metadata
- Download URL: dispatchy-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa3d7c81ce599c17993df1ee8afcb15be8657fc448f14e340cf15a55e3a0ea94
|
|
| MD5 |
b01ef6b55e6158bd4a936fdd039fcc90
|
|
| BLAKE2b-256 |
a09272d086e3ec1c934173900e6b78d08d251d27ded22eb3f72e6ee1350ce1ce
|