misc: removed routers example

This commit is contained in:
sdmway 2024-05-11 11:41:45 -06:00
parent fd95745fef
commit 86c9ba3107

View file

@ -3,7 +3,7 @@ import logging
import sys
from os import getenv
from aiogram import Bot, Dispatcher, Router, html
from aiogram import Bot, Dispatcher, html
from aiogram.client.default import DefaultBotProperties
from aiogram.enums import ParseMode
from aiogram.filters import CommandStart
@ -14,10 +14,10 @@ TOKEN = getenv("BOT_TOKEN")
# All handlers should be attached to the Router (or Dispatcher)
echo_router = Router()
dp = Dispatcher()
@echo_router.message(CommandStart())
@dp.message(CommandStart())
async def command_start_handler(message: Message) -> None:
"""
This handler receives messages with `/start` command
@ -30,7 +30,7 @@ async def command_start_handler(message: Message) -> None:
await message.answer(f"Hello, {html.bold(message.from_user.full_name)}!")
@echo_router.message()
@dp.message()
async def echo_handler(message: Message) -> None:
"""
Handler will forward receive a message back to the sender
@ -49,10 +49,6 @@ async def main() -> None:
# Initialize Bot instance with default bot properties which will be passed to all API calls
bot = Bot(token=TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML))
dp = Dispatcher()
dp.include_router(echo_router)
# And the run events dispatching
await dp.start_polling(bot)