Simple and lightweight library based on aiogram for creating telegram mailings
Project description
Aiogram Broadcaster
A simple and straightforward broadcasting implementation for aiogram
Installaiton
$ pip install aiogram-broadcaster
Examples
Few steps before getting started...
- First, you should obtain token for your bot from BotFather and make sure you started a conversation with the bot.
- Obtain your user id from JSON Dump Bot in order to test out broadcaster.
Note: These and even more examples can found in examples/
directory
Base usage
from aiogram_broadcaster import TextBroadcaster
import asyncio
async def main():
# Initialize a text broadcaster (you can directly pass a token)
broadcaster = TextBroadcaster('USERS IDS HERE', 'hello!', bot_token='BOT TOKEN HERE')
# Run the broadcaster and close it afterwards
try:
await broadcaster.run()
finally:
await broadcaster.close_bot()
if __name__ == '__main__':
asyncio.run(main())
Embed a broadcaster in a message handler
from aiogram import Bot, Dispatcher, types
from aiogram_broadcaster import MessageBroadcaster
import asyncio
async def message_handler(msg: types.Message):
"""
The broadcaster will flood to a user whenever it receives a message
"""
users = [msg.from_user.id] * 5 # Your users list
await MessageBroadcaster(users, msg).run() # Run the broadcaster
async def main():
# Initialize a bot and a dispatcher
bot = Bot(token='BOT TOKEN HERE')
dp = Dispatcher(bot=bot)
# Register a message handler
dp.register_message_handler(message_handler, content_types=types.ContentTypes.ANY)
# Run the bot and close it afterwards
try:
await dp.start_polling()
finally:
await bot.session.close()
if __name__ == '__main__':
asyncio.run(main())
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
Close
Hashes for aiogram_broadcaster-0.0.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 476585e4a6fafb2fbb490929aa8d9e90815d1e1b11bcbf2cb34e580a3e559aa9 |
|
MD5 | 46121ffb3b8e4d0ba1065d58e0e8aa86 |
|
BLAKE2b-256 | dc0ec83c76d5d86a27bf117ba8b851518680291438919ea0ab3a5f9cd80e1bca |
Close
Hashes for aiogram_broadcaster-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ff33f281b6c3b24bd30fd9adc08de7fee3c5d9e5ee4c36e81ed1a5a36c7bf62 |
|
MD5 | 23a50fe20f024f1ec68604a17bfee1ed |
|
BLAKE2b-256 | 1e0086870ccd4b0c2b9e7bdde5fee0770bf5873ebb0b62997dac2493b84dc599 |