diff --git a/examples/data/cats.jpg b/examples/data/cats.jpg new file mode 100644 index 00000000..d3b8caf8 Binary files /dev/null and b/examples/data/cats.jpg differ diff --git a/examples/echo_bot.py b/examples/echo_bot.py new file mode 100644 index 00000000..df1b5150 --- /dev/null +++ b/examples/echo_bot.py @@ -0,0 +1,43 @@ +import asyncio +import logging + +from aiogram.bot import AIOGramBot +from aiogram.dispatcher import Dispatcher + +API_TOKEN = 'BOT TOKEN HERE' + +logging.basicConfig(level=logging.INFO) + +loop = asyncio.get_event_loop() +bot = AIOGramBot(token=API_TOKEN, loop=loop) +dp = Dispatcher(bot) + + +@dp.message_handler(commands=['start', 'help']) +async def send_welcome(message): + await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.") + + +@dp.message_handler(regexp='(^cat[s]?$|puss)') +async def cats(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): + 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()