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.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86c8a34523525f38105f0b2ebe647a5d4b21c3910bb7e76ce1bc2839e68f325e |
|
MD5 | 7d1cf96e074360844b241ddeea063bae |
|
BLAKE2b-256 | 9d052c034ee95555796c6f85d19940eb780561c1804894007d4a8fea7524b755 |
Close
Hashes for aiogram_broadcaster-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0862436b8235c4e4d8b4f446120936b583185627e916479a5a9895f1d3298537 |
|
MD5 | aa6296f4534bf84295b9200ee535d5a5 |
|
BLAKE2b-256 | e46618486294cd6688366ac22f2167c5adbc9b6c9bd134e73613dcfb823ba219 |