mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Update index.rst
This commit is contained in:
parent
a76fb42ba0
commit
73ab7c3c46
1 changed files with 24 additions and 26 deletions
|
|
@ -1,29 +1,27 @@
|
|||
.. include:: ../README.rst
|
||||
import logging
|
||||
from aiogram import Bot, Dispatcher, types
|
||||
from aiogram.utils import executor
|
||||
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton
|
||||
TOKEN = 7537770028:AAEBMd-n9Nce8EjHy6c6sFKSucpYKXrBU08
|
||||
bot = Bot(token=TOKEN)
|
||||
dp = Dispatcher(bot)
|
||||
tap_button = KeyboardButton('Тап!')
|
||||
keyboard = ReplyKeyboardMarkup(resize_keyboard=True).add(tap_button)
|
||||
/start
|
||||
@dp.message_handler(commands=['start'])
|
||||
async def send_welcome(message: types.Message):
|
||||
await message.answer("Привет! Нажимай на кнопку 'Тап!' чтобы тапать.", reply_markup=keyboard)
|
||||
|
||||
Simple usage
|
||||
------------
|
||||
# Обработчик нажатия на кнопку 'Тап!'
|
||||
@dp.message_handler(lambda message: message.text == 'Тап!')
|
||||
async def handle_tap(message: types.Message):
|
||||
await message.answer("Ты тапнул!")
|
||||
|
||||
.. literalinclude:: ../examples/echo_bot.py
|
||||
# Обработчик любых текстовых сообщений
|
||||
@dp.message_handler(content_types=types.ContentTypes.TEXT)
|
||||
async def handle_text(message: types.Message):
|
||||
await message.answer("Просто тапай!")
|
||||
|
||||
|
||||
Usage without dispatcher
|
||||
------------------------
|
||||
|
||||
Just only interact with Bot API, without handling events
|
||||
|
||||
.. literalinclude:: ../examples/without_dispatcher.py
|
||||
|
||||
|
||||
Contents
|
||||
========
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 3
|
||||
|
||||
install
|
||||
migration_2_to_3
|
||||
api/index
|
||||
dispatcher/index
|
||||
utils/index
|
||||
changelog
|
||||
contributing
|
||||
# Запуск бота
|
||||
if __name__ == '__main__':
|
||||
executor.start_polling(dp, skip_updates=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue