aiogram/docs/source/quick_start.rst

53 lines
1.1 KiB
ReStructuredText
Raw Normal View History

2017-06-03 11:58:26 +03:00
Quick start
===========
Simple template
---------------
2017-11-16 19:37:52 +02:00
By first step you need import all modules
2017-11-16 19:37:52 +02:00
.. code-block:: python3
2017-11-16 19:37:52 +02:00
from aiogram import Bot
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor
2017-11-16 19:37:52 +02:00
In next step you you can initialize bot and dispatcher instances.
Bot token you can get from `@BotFather <https://t.me/BotFather>`_
.. code-block:: python3
2017-11-16 19:37:52 +02:00
bot = Bot(token='BOT TOKEN HERE')
dp = Dispatcher(bot)
2017-11-16 19:37:52 +02:00
And next: all bots is needed command for starting interaction with bot. Register first command handler:
.. code-block:: python3
2017-11-16 19:37:52 +02:00
@dp.message_handler(commands=['start', 'help'])
async def send_welcome(message: types.Message):
await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")
2017-11-21 00:53:53 +02:00
And last step - run long polling.
.. code-block:: python3
2017-11-16 19:37:52 +02:00
if __name__ == '__main__':
2017-11-29 13:50:50 +02:00
executor.start_polling(dp)
2017-11-16 19:37:52 +02:00
Summary
-------
2017-11-16 19:37:52 +02:00
.. code-block:: python3
2017-11-16 19:37:52 +02:00
from aiogram import Bot
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor
2017-11-16 19:37:52 +02:00
bot = Bot(token='BOT TOKEN HERE')
dp = Dispatcher(bot)
2017-11-16 19:37:52 +02:00
if __name__ == '__main__':
2017-11-21 00:53:53 +02:00
executor.start_polling(dp)