mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
misc: consistency of comments and dispatcher instance creation
This commit is contained in:
parent
1cb0f38d2e
commit
fd95745fef
9 changed files with 31 additions and 16 deletions
|
|
@ -3,7 +3,7 @@ import logging
|
|||
import sys
|
||||
from os import getenv
|
||||
|
||||
from aiogram import Bot, Dispatcher, html
|
||||
from aiogram import Bot, Dispatcher, Router, html
|
||||
from aiogram.client.default import DefaultBotProperties
|
||||
from aiogram.enums import ParseMode
|
||||
from aiogram.filters import CommandStart
|
||||
|
|
@ -13,10 +13,11 @@ from aiogram.types import Message
|
|||
TOKEN = getenv("BOT_TOKEN")
|
||||
|
||||
# All handlers should be attached to the Router (or Dispatcher)
|
||||
dp = Dispatcher()
|
||||
|
||||
echo_router = Router()
|
||||
|
||||
|
||||
@dp.message(CommandStart())
|
||||
@echo_router.message(CommandStart())
|
||||
async def command_start_handler(message: Message) -> None:
|
||||
"""
|
||||
This handler receives messages with `/start` command
|
||||
|
|
@ -29,7 +30,7 @@ async def command_start_handler(message: Message) -> None:
|
|||
await message.answer(f"Hello, {html.bold(message.from_user.full_name)}!")
|
||||
|
||||
|
||||
@dp.message()
|
||||
@echo_router.message()
|
||||
async def echo_handler(message: Message) -> None:
|
||||
"""
|
||||
Handler will forward receive a message back to the sender
|
||||
|
|
@ -47,6 +48,11 @@ async def echo_handler(message: Message) -> None:
|
|||
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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue