From e044267b50e394bc8c3c1478d2136221be78fa5a Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Fri, 7 Sep 2018 23:17:20 +0300 Subject: [PATCH] Rewrite quick start // include code from file --- docs/source/examples/echo_bot.rst | 5 ++- docs/source/quick_start.rst | 62 ++++++++++--------------------- 2 files changed, 24 insertions(+), 43 deletions(-) diff --git a/docs/source/examples/echo_bot.rst b/docs/source/examples/echo_bot.rst index 4919f555..bacd2c36 100644 --- a/docs/source/examples/echo_bot.rst +++ b/docs/source/examples/echo_bot.rst @@ -1,4 +1,7 @@ Echo bot ======== -example \ No newline at end of file + +.. literalinclude:: ../../../examples/echo_bot.py + :language: python + :linenos: diff --git a/docs/source/quick_start.rst b/docs/source/quick_start.rst index 428f336f..a73640b4 100644 --- a/docs/source/quick_start.rst +++ b/docs/source/quick_start.rst @@ -1,3 +1,4 @@ +=========== Quick start =========== @@ -6,62 +7,39 @@ Simple template At first you have to import all necessary modules -.. code-block:: python3 - - from aiogram import Bot, Dispatcher, executor, types +.. literalinclude:: ../../examples/echo_bot.py + :language: python + :lines: 1-4 Then you have to initialize bot and dispatcher instances. Bot token you can get from `@BotFather `_ - -.. code-block:: python3 - - bot = Bot(token='BOT TOKEN HERE') - dp = Dispatcher(bot) +.. literalinclude:: ../../examples/echo_bot.py + :language: python + :lines: 10-12 Next step: interaction with bots starts with one command. Register your first command handler: -.. code-block:: python3 - - @dp.message_handler(commands=['start', 'help']) - async def send_welcome(message: types.Message): - await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.") +.. literalinclude:: ../../examples/echo_bot.py + :language: python + :lines: 15-17 If you want to handle all messages in the chat simply add handler without filters: -.. code-block:: python - - @dp.message_handler() - async def echo(message: types.Message): - await bot.send_message(message.chat.id, message.text) +.. literalinclude:: ../../examples/echo_bot.py + :language: python + :lines: 27-29 Last step: run long polling. -.. code-block:: python3 - - if __name__ == '__main__': - executor.start_polling(dp) +.. literalinclude:: ../../examples/echo_bot.py + :language: python + :lines: 32-33 Summary ------- -.. code-block:: python3 - - from aiogram import Bot, Dispatcher, executor, types - - bot = Bot(token='BOT TOKEN HERE') - 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() - async def echo(message: types.Message): - await bot.send_message(message.chat.id, message.text) - - - if __name__ == '__main__': - executor.start_polling(dp) +.. literalinclude:: ../../examples/echo_bot.py + :language: python + :linenos: + :lines: -19,27- \ No newline at end of file