Skip to main content

Broadcast/newsletter library for aiogram 3.x

Project description

aiogram-broadcast

PyPI CI

Broadcast/newsletter library for Telegram bots built with aiogram 3.x.

Features

  • Automatic subscriber registration via middleware
  • Rate-limited broadcasting to avoid Telegram API limits
  • Scheduled broadcasts with APScheduler
  • Pluggable subscriber storage: Redis or PostgreSQL
  • Progress callbacks for monitoring
  • Interactive UI menu with multi-language support (EN/RU)

Installation

Pick a storage backend (the core package no longer pulls in a driver by default):

pip install aiogram-broadcast[redis]      # Redis storage
pip install aiogram-broadcast[postgres]   # PostgreSQL storage (asyncpg)

Everything (both backends, scheduler and UI):

pip install aiogram-broadcast[all]

Quick Start

from aiogram_broadcast import BroadcastMiddleware, BroadcastService, RedisBroadcastStorage

redis = Redis(host="localhost")
storage = RedisBroadcastStorage(redis)
service = BroadcastService(bot, storage)

# Auto-register subscribers
dp.update.outer_middleware.register(BroadcastMiddleware(storage))

# Broadcast to all
result = await service.broadcast_text("Hello everyone!", parse_mode="HTML")
print(f"{result.successful}/{result.total} sent, {result.success_rate:.0f}%")

See examples/basic.py for a complete runnable bot.

Storage

Both backends implement the same BaseBroadcastStorage interface, so the service, middleware, scheduler and UI work identically regardless of which one you pick.

Redis

from redis.asyncio import Redis
from aiogram_broadcast import RedisBroadcastStorage

redis = Redis(host="localhost")
storage = RedisBroadcastStorage(redis)

PostgreSQL

import asyncpg
from aiogram_broadcast import PostgresBroadcastStorage

pool = await asyncpg.create_pool("postgresql://user:pass@localhost:5432/db")
storage = PostgresBroadcastStorage(pool)
await storage.create_schema()  # create the table and index once on startup

# or build the pool for you from a DSN:
storage = await PostgresBroadcastStorage.from_dsn("postgresql://user:pass@localhost/db")
await storage.create_schema()

See examples/postgres.py for a complete runnable bot.

Usage

Broadcasting

# Text, photo, video, document, or copy any message
await service.broadcast_text("Hello!", parse_mode="HTML")
await service.broadcast_photo(photo_file_id, caption="Check this out")
await service.broadcast_copy(from_chat_id=admin_id, message_id=msg_id)

# Custom sender for any message type
await service.broadcast_custom(my_sender_func)

Scheduled Broadcasts

from aiogram_broadcast import BroadcastScheduler

scheduler = BroadcastScheduler(service, AsyncIOScheduler())
task_id = await scheduler.schedule_text("Reminder!", run_date=some_datetime)
await scheduler.cancel(task_id)

See examples/scheduled.py for full setup.

Progress Tracking

async def on_progress(current, total, result):
    print(f"{current}/{total}{result.successful} sent, {result.failed} failed")

await service.broadcast_text("msg", progress_callback=on_progress)

See examples/progress.py.

Interactive UI Menu

A complete FSM-based wizard for composing and scheduling broadcasts from Telegram — supports text/photo/video/document messages, inline URL buttons, and scheduled delivery.

See examples/ui_menu.py.

License

MIT

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

aiogram_broadcast-0.2.0.tar.gz (37.1 kB view details)

Uploaded Source

Built Distribution

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

aiogram_broadcast-0.2.0-py3-none-any.whl (35.9 kB view details)

Uploaded Python 3

File details

Details for the file aiogram_broadcast-0.2.0.tar.gz.

File metadata

  • Download URL: aiogram_broadcast-0.2.0.tar.gz
  • Upload date:
  • Size: 37.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aiogram_broadcast-0.2.0.tar.gz
Algorithm Hash digest
SHA256 afe65b18ff3361a1b55342e4832adbe8af40570b307f9dbaeefabcbaa188c6e0
MD5 66da7572126d5313fbd2afc8e1f1149f
BLAKE2b-256 aa5e7c59b95c43c01d384754b74711e3084e39f0a1f506e2014baecd5a28b727

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiogram_broadcast-0.2.0.tar.gz:

Publisher: publish.yml on DefaultPerson/aiogram-broadcast

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aiogram_broadcast-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aiogram_broadcast-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e6c6577fa3113e252d4dbd7aa7edf708c8d593d1b5cc6f7664ef626d80027e8
MD5 163ef96f6e191d9a8fcfd0844bf91a8a
BLAKE2b-256 17e887cc5b7aeb535d2079db079b66a23e937c2f62c9dfd2687d19cdecdcea2e

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiogram_broadcast-0.2.0-py3-none-any.whl:

Publisher: publish.yml on DefaultPerson/aiogram-broadcast

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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