mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Added docs for chat action util
This commit is contained in:
parent
b511044650
commit
9873ad84f5
3 changed files with 99 additions and 11 deletions
53
docs/utils/chat_action.rst
Normal file
53
docs/utils/chat_action.rst
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
==================
|
||||
Chat action sender
|
||||
==================
|
||||
|
||||
.. autoclass:: aiogram.utils.chat_action.ChatActionSender
|
||||
:members: __init__,running,typing,upload_photo,record_video,upload_video,record_voice,upload_voice,upload_document,choose_sticker,find_location,record_video_note,upload_video_note
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
async with ChatActionSender.typing(bot=bot, chat_id=message.chat.id):
|
||||
# Do something...
|
||||
# Perform some long calculations
|
||||
await message.answer(result)
|
||||
|
||||
|
||||
Middleware
|
||||
==========
|
||||
|
||||
.. autoclass:: aiogram.utils.chat_action.ChatActionMiddleware
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Before usa should be registered for the `message` event
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
<router or dispatcher>.message.middleware(ChatActionMiddleware())
|
||||
|
||||
After this action all handlers which works longer than `initial_sleep` will produce the '`typing`' chat action.
|
||||
|
||||
Also sender can be customized via flags feature for particular handler.
|
||||
|
||||
Change only action type:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@router.message(...)
|
||||
@flags.chat_action("sticker")
|
||||
async def my_handler(message: Message): ...
|
||||
|
||||
|
||||
Change sender configuration:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@router.message(...)
|
||||
@flags.chat_action(initial_sleep=2, action="upload_document", interval=3)
|
||||
async def my_handler(message: Message): ...
|
||||
|
|
@ -6,3 +6,4 @@ Utils
|
|||
|
||||
i18n
|
||||
keyboard
|
||||
chat_action
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue