mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-09 17:33:44 +00:00
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import asyncio
|
|
import logging
|
|
|
|
from aiogram import Bot, types
|
|
from aiogram.dispatcher import Dispatcher
|
|
from aiogram.utils.executor import start_polling
|
|
|
|
API_TOKEN = 'BOT TOKEN HERE'
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
loop = asyncio.get_event_loop()
|
|
bot = Bot(token=API_TOKEN, loop=loop)
|
|
dp = Dispatcher(bot)
|
|
|
|
|
|
@dp.message_handler(commands=['start', 'help'])
|
|
async def send_welcome(message: types.Message):
|
|
await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")
|
|
|
|
|
|
@dp.message_handler(regexp='(^cat[s]?$|puss)')
|
|
async def cats(message: types.Message):
|
|
with open('data/cats.jpg', 'rb') as photo:
|
|
await bot.send_photo(message.chat.id, photo, caption='Cats is here 😺',
|
|
reply_to_message_id=message.message_id)
|
|
|
|
|
|
@dp.message_handler()
|
|
async def echo(message: types.Message):
|
|
await bot.send_message(message.chat.id, message.text)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
start_polling(dp, loop=loop, skip_updates=True)
|
|
|
|
# Also you can use another execution method
|
|
# >>> try:
|
|
# >>> loop.run_until_complete(main())
|
|
# >>> except KeyboardInterrupt:
|
|
# >>> loop.stop()
|