From 7025542e3cc1d02797aada2cd1463fda3eb7b7bd Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Thu, 16 Nov 2017 19:37:52 +0200 Subject: [PATCH] Rewrite quick start guide. --- docs/source/bot/base.rst | 2 +- docs/source/quick_start.rst | 70 +++++++++++++++---------------------- 2 files changed, 30 insertions(+), 42 deletions(-) diff --git a/docs/source/bot/base.rst b/docs/source/bot/base.rst index b4e4b663..5fe71588 100644 --- a/docs/source/bot/base.rst +++ b/docs/source/bot/base.rst @@ -1,7 +1,7 @@ BaseBot ======= -This class is base of bot. In BaseBot implemented all available methods of Telegram Bot API. +This class is base of bot. In BaseBot implemented only methods for interactions with Telegram Bot API. .. autoclass:: aiogram.bot.base.BaseBot :members: diff --git a/docs/source/quick_start.rst b/docs/source/quick_start.rst index 1dd3dda8..ee241a38 100644 --- a/docs/source/quick_start.rst +++ b/docs/source/quick_start.rst @@ -4,62 +4,50 @@ Quick start Simple template --------------- -.. code-block:: python3 - - import asyncio - from aiogram import Bot - - - loop = asyncio.get_event_loop() - bot = Bot('TOKEN', loop) - - - async def main(): - bot_info = await bot.get_me() - - print(bot_info.username) - - - if __name__ == '__main__': - try: - loop.run_until_complete(main()) - except KeyboardInterrupt: - loop.stop() - - -Manual ------- - -First you need to get event loop from asyncio +By first step you need import all modules .. code-block:: python3 - import asyncio + from aiogram import Bot + from aiogram.dispatcher import Dispatcher + from aiogram.utils import executor - loop = asyncio.get_event_loop() +In next step you you can initialize bot and dispatcher instances. +Bot token you can get from `@BotFather `_ -Then create bot instance, if you have bot token. - -Token you can get from `@BotFather `_ .. code-block:: python3 - from aiogram import Bot + bot = Bot(token='BOT TOKEN HERE') + dp = Dispatcher(bot) - bot = Bot('TOKEN', loop) - - -And then you can use Dispather module: +And next: all bots is needed command for starting interaction with bot. Register first command handler: .. code-block:: python3 - from aiogram.dispather import Dispatcher + @dp.message_handler(commands=['start', 'help']) + async def send_welcome(message: types.Message): + await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.") - dp = Dispatcher(bot) +And last step - run long pooling. -Dispatcher cah handler updates from telegram bot API. +.. code-block:: python3 -It have **dp.start_pooling()** method. + if __name__ == '__main__': + executor.start_pooling(dp, on_startup=startup) +Summary +------- +.. code-block:: python3 + + from aiogram import Bot + from aiogram.dispatcher import Dispatcher + from aiogram.utils import executor + + bot = Bot(token='BOT TOKEN HERE') + dp = Dispatcher(bot) + + if __name__ == '__main__': + executor.start_pooling(dp)