Asynchronous library for Telegram bot API
Project description
About
Asynchronous library for Telegram bot API.
Installation
aiotgbot requires Python 3.8 or greater and is available on PyPI. Use pip to install it:
pip install aiotgbot
Using aiotgbot
from typing import AsyncIterator
from aiotgbot import (Bot, BotUpdate, HandlerTable, PollBot,
PrivateChatFilter, Runner)
from aiotgbot.storage_memory import MemoryStorage
handlers = HandlerTable()
@handlers.message(filters=[PrivateChatFilter()])
async def reply_private_message(bot: Bot, update: BotUpdate) -> None:
assert update.message is not None
name = (f'{update.message.chat.first_name} '
f'{update.message.chat.last_name}')
await bot.send_message(update.message.chat.id, f'Hello, {name}!')
async def run_context(runner: Runner) -> AsyncIterator[None]:
storage = MemoryStorage()
await storage.connect()
handlers.freeze()
bot = PollBot(runner['token'], handlers, storage)
await bot.start()
yield
await bot.stop()
await storage.close()
def main() -> None:
runner = Runner(run_context)
runner['token'] = 'some:token'
runner.run()
if __name__ == '__main__':
main()
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
aiotgbot-0.7.0a1.tar.gz
(25.9 kB
view hashes)
Built Distribution
aiotgbot-0.7.0a1-py3-none-any.whl
(29.6 kB
view hashes)
Close
Hashes for aiotgbot-0.7.0a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2de130ba0d8e8e9d9e3a80bed47e040436c86af8fc6f0295d109c4573b82c977 |
|
MD5 | c7e662835f392ec41983a7e817410733 |
|
BLAKE2b-256 | 510f78261304f64fd0cea48d93da28c8ee085ad90116c0dc01f3cb2cd22ef3ed |