More docs

This commit is contained in:
Alex Root Junior 2023-07-29 03:42:04 +03:00
parent 48c4884877
commit 7fa3ebf8ba
No known key found for this signature in database
GPG key ID: 074C1D455EBEA4AC
17 changed files with 266 additions and 380 deletions

View file

@ -1,3 +1,5 @@
.. _enums:
#####
Enums
#####

View file

@ -1,14 +1,14 @@
Use Custom API server
=====================
.. autoclass:: aiogram.client.telegram.TelegramAPIServer
:members:
For example, if you want to use self-hosted API server:
.. code-block:: python3
.. code-block:: python
session = AiohttpSession(
api=TelegramAPIServer.from_base('http://localhost:8082')
)
bot = Bot(..., session=session)
.. autoclass:: aiogram.client.telegram.TelegramAPIServer
:members:

View file

@ -8,3 +8,4 @@ Client sessions is used for interacting with API server.
custom_server
base
aiohttp
middleware

View file

@ -0,0 +1,75 @@
##########################
Client session middlewares
##########################
In some cases you may want to add some middlewares to the client session to customize the behavior of the client.
Some useful cases that is:
- Log the outgoing requests
- Customize the request parameters
- Handle rate limiting errors and retry the request
- others ...
So, you can do it using client session middlewares.
A client session middleware is a function (or callable class) that receives the request and the next middleware to call.
The middleware can modify the request and then call the next middleware to continue the request processing.
How to register client session middleware?
==========================================
Register using register method
------------------------------
.. code-block:: python
bot.session.middleware(RequestLogging(ignore_methods=[GetUpdates]))
Register using decorator
------------------------
.. code-block:: python
@bot.session.middleware()
async def my_middleware(
make_request: NextRequestMiddlewareType[TelegramType],
bot: "Bot",
method: TelegramMethod[TelegramType],
) -> Response[TelegramType]:
# do something with request
return await make_request(bot, method)
Example
=======
Class based session middleware
------------------------------
.. literalinclude:: ../../../aiogram/client/session/middlewares/request_logging.py
:lines: 16-
:language: python
:linenos:
.. note::
this middlewware is already implemented inside aiogram, so, if you want to use it you can
just import it :code:`from aiogram.client.session.middlewares.request_logging import RequestLogging`
Function based session middleware
---------------------------------
.. code-block:: python
async def __call__(
self,
make_request: NextRequestMiddlewareType[TelegramType],
bot: "Bot",
method: TelegramMethod[TelegramType],
) -> Response[TelegramType]:
try:
# do something with request
return await make_request(bot, method)
finally:
# do something after request

View file

@ -1,10 +0,0 @@
##########
ErrorEvent
##########
.. automodule:: aiogram.types.error_event
:members:
:member-order: bysource
:undoc-members: True
:exclude-members: model_config,model_fields