mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 18:01:04 +00:00
Upgrade architecture + 5.0 Bot API (#469)
Upgrade architecture + 5.0 Bot API (#469) * Moved `methods`, `types` and `client` to root package * Removed update handler from routers to dispatcher * Reworked events propagation mechanism to handlers * Reworked inner middlewares logic (very small change) * Updated to Bot API 5.0 * Initial migration from MkDocs to Sphinx + config for readthedocs
This commit is contained in:
parent
566b7ff282
commit
4008a3114d
608 changed files with 12537 additions and 6427 deletions
41
examples/echo_bot.py
Normal file
41
examples/echo_bot.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
from typing import Any
|
||||
|
||||
from aiogram import Bot, Dispatcher, types
|
||||
from aiogram.dispatcher.handler import MessageHandler
|
||||
|
||||
TOKEN = "42:TOKEN"
|
||||
dp = Dispatcher()
|
||||
|
||||
|
||||
@dp.message(commands=["start"])
|
||||
class MyHandler(MessageHandler):
|
||||
"""
|
||||
This handler receive messages with `/start` command
|
||||
|
||||
Usage of Class-based handlers
|
||||
"""
|
||||
|
||||
async def handle(self) -> Any:
|
||||
await self.event.answer(f"<b>Hello, {self.from_user.full_name}!</b>")
|
||||
|
||||
|
||||
@dp.message(content_types=[types.ContentType.ANY])
|
||||
async def echo_handler(message: types.Message, bot: Bot) -> Any:
|
||||
"""
|
||||
Handler will forward received message back to the sender
|
||||
|
||||
Usage of Function-based handlers
|
||||
"""
|
||||
|
||||
await bot.forward_message(
|
||||
from_chat_id=message.chat.id, chat_id=message.chat.id, message_id=message.message_id
|
||||
)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
bot = Bot(TOKEN, parse_mode="HTML")
|
||||
dp.run_polling(bot)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue