add default bot properties and clean imports (#1447)

This commit is contained in:
Yana Malenko 2024-04-09 01:27:29 +03:00 committed by GitHub
parent acf52f468c
commit b49939aaff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,11 +3,11 @@ import logging
import sys
from os import getenv
from aiogram import Bot, Dispatcher, Router, types
from aiogram import Bot, Dispatcher, html
from aiogram.client.default import DefaultBotProperties
from aiogram.enums import ParseMode
from aiogram.filters import CommandStart
from aiogram.types import Message
from aiogram.utils.markdown import hbold
# Bot token can be obtained via https://t.me/BotFather
TOKEN = getenv("BOT_TOKEN")
@ -26,11 +26,11 @@ async def command_start_handler(message: Message) -> None:
# and the target chat will be passed to :ref:`aiogram.methods.send_message.SendMessage`
# method automatically or call API method directly via
# Bot instance: `bot.send_message(chat_id=message.chat.id, ...)`
await message.answer(f"Hello, {hbold(message.from_user.full_name)}!")
await message.answer(f"Hello, {html.bold(message.from_user.full_name)}!")
@dp.message()
async def echo_handler(message: types.Message) -> None:
async def echo_handler(message: Message) -> None:
"""
Handler will forward receive a message back to the sender
@ -45,8 +45,8 @@ async def echo_handler(message: types.Message) -> None:
async def main() -> None:
# Initialize Bot instance with a default parse mode which will be passed to all API calls
bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
# 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))
# And the run events dispatching
await dp.start_polling(bot)