aiogram/docs/utils/chat_action.rst
Alex Root Junior 7776cf9cf6
Bot API 5.7 and some new features (#834)
* Update API, added some new features

* Fixed unknown chat_action value

* Separate events from dispatcher messages

* Disabled cache for I18n LazyProxy

* Rework events isolation

* Added chat member status changed filter, update Bot API 5.7, other small changes

* Improve exceptions in chat member status filter

* Fixed tests, covered flags and events isolation modules

* Try to fix flake8 unused type ignore

* Fixed linter error

* Cover chat member updated filter

* Cover chat action sender

* Added docs for chat action util

* Try to fix tests for python <= 3.9

* Fixed headers

* Added docs for flags functionality

* Added docs for chat_member_updated filter

* Added change notes

* Update dependencies and fix mypy checks

* Bump version
2022-02-19 01:45:59 +02:00

56 lines
1.3 KiB
ReStructuredText

==================
Chat action sender
==================
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): ...