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.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b4bd1d354e4c8fd079b78eb2941eb2f92fc0237f030149f3de52296d88c829c |
|
MD5 | 48e15f1661b5ca8eed40dd2308a4144d |
|
BLAKE2b-256 | 08672cf05879c1aae70b42ea452b0fcf25dfaf03864c2b1c2b21150c1aa79a0e |
Close
Hashes for aiogram_broadcaster-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74f6470e0d37e08e740084b46d07e135d38c05f12700afddf35195e6e5667e5f |
|
MD5 | 2ab557890a710f3a48bc52fa8fcf8d42 |
|
BLAKE2b-256 | 36ae98cdc172133b4178551f1c369b21eaaa2061aadac67ba7e2fda00e469776 |