Echo bot

echo_bot.py
 1"""
 2This is a echo bot.
 3It echoes any incoming text messages.
 4"""
 5
 6import logging
 7
 8from aiogram import Bot, Dispatcher, executor, types
 9
10API_TOKEN = 'BOT TOKEN HERE'
11
12# Configure logging
13logging.basicConfig(level=logging.INFO)
14
15# Initialize bot and dispatcher
16bot = Bot(token=API_TOKEN)
17dp = Dispatcher(bot)
18
19
20@dp.message_handler(commands=['start', 'help'])
21async def send_welcome(message: types.Message):
22    """
23    This handler will be called when user sends `/start` or `/help` command
24    """
25    await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")
26
27
28@dp.message_handler(regexp='(^cat[s]?$|puss)')
29async def cats(message: types.Message):
30    with open('data/cats.jpg', 'rb') as photo:
31        '''
32        # Old fashioned way:
33        await bot.send_photo(
34            message.chat.id,
35            photo,
36            caption='Cats are here 😺',
37            reply_to_message_id=message.message_id,
38        )
39        '''
40
41        await message.reply_photo(photo, caption='Cats are here 😺')
42
43
44@dp.message_handler()
45async def echo(message: types.Message):
46    # old style:
47    # await bot.send_message(message.chat.id, message.text)
48
49    await message.answer(message.text)
50
51
52if __name__ == '__main__':
53    executor.start_polling(dp, skip_updates=True)