mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 01:54:53 +00:00
Write docs and small fixes.
This commit is contained in:
parent
23fba99d93
commit
7a55c040ee
31 changed files with 306 additions and 458 deletions
|
|
@ -8,9 +8,7 @@ At first you have to import all necessary modules
|
|||
|
||||
.. code-block:: python3
|
||||
|
||||
from aiogram import Bot, types
|
||||
from aiogram.dispatcher import Dispatcher
|
||||
from aiogram.utils import executor
|
||||
from aiogram import Bot, Dispatcher, executor, types
|
||||
|
||||
Then you have to initialize bot and dispatcher instances.
|
||||
Bot token you can get from `@BotFather <https://t.me/BotFather>`_
|
||||
|
|
@ -29,6 +27,14 @@ Next step: interaction with bots starts with one command. Register your first co
|
|||
async def send_welcome(message: types.Message):
|
||||
await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")
|
||||
|
||||
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)
|
||||
|
||||
Last step: run long polling.
|
||||
|
||||
.. code-block:: python3
|
||||
|
|
@ -41,16 +47,21 @@ Summary
|
|||
|
||||
.. code-block:: python3
|
||||
|
||||
from aiogram import Bot, types
|
||||
from aiogram.dispatcher import Dispatcher
|
||||
from aiogram.utils import executor
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue