mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-14 02:52:12 +00:00
add default bot properties and clean imports (#1447)
This commit is contained in:
parent
acf52f468c
commit
b49939aaff
1 changed files with 6 additions and 6 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue