mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-09 17:33:44 +00:00
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
import asyncio
|
|
import logging
|
|
|
|
from aiogram import Bot, types
|
|
from aiogram.dispatcher import Dispatcher
|
|
|
|
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)
|
|
|
|
|
|
@dp.message_handler()
|
|
async def echo(message: types.Message):
|
|
await bot.send_message(message.chat.id, message.text)
|
|
|
|
|
|
async def main():
|
|
count = await dp.skip_updates()
|
|
print(f"Skipped {count} updates.")
|
|
await dp.start_pooling()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
loop.run_until_complete(main())
|
|
except KeyboardInterrupt:
|
|
loop.stop()
|