Upgrade architecture + 5.0 Bot API (#469)

Upgrade architecture + 5.0 Bot API (#469)
* Moved `methods`, `types` and `client` to root package
* Removed update handler from routers to dispatcher
* Reworked events propagation mechanism to handlers
* Reworked inner middlewares logic (very small change)
* Updated to Bot API 5.0
* Initial migration from MkDocs to Sphinx + config for readthedocs
This commit is contained in:
Alex Root Junior 2021-01-26 21:20:52 +02:00 committed by GitHub
parent 566b7ff282
commit 4008a3114d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
608 changed files with 12537 additions and 6427 deletions

View file

@ -0,0 +1,95 @@
#######
aiohttp
#######
AiohttpSession represents a wrapper-class around `ClientSession` from `aiohttp <https://pypi.org/project/aiohttp/>`_
Currently `AiohttpSession` is a default session used in `aiogram.Bot`
.. autoclass:: aiogram.client.session.aiohttp.AiohttpSession
Usage example
=============
.. code-block::
from aiogram import Bot
from aiogram.session.aiohttp import AiohttpSession
session = AiohttpSession()
Bot('42:token', session=session)
Proxy requests in AiohttpSession
================================
In order to use AiohttpSession with proxy connector you have to install `aiohttp-socks <https://pypi.org/project/aiohttp-socks>`_
Binding session to bot:
.. code-block::
from aiogram import Bot
from aiogram.client.session.aiohttp import AiohttpSession
session = AiohttpSession(proxy="protocol://host:port/")
Bot(token="bot token", session=session)
.. note::
Only following protocols are supported: http(tunneling), socks4(a), socks5
as aiohttp_socks `documentation <https://github.com/romis2012/aiohttp-socks/blob/master/README.md>`_ claims.
Authorization
-------------
Proxy authorization credentials can be specified in proxy URL or come as an instance of :obj:`aiohttp.BasicAuth` containing
login and password.
Consider examples:
.. code-block::
from aiohttp import BasicAuth
from aiogram.client.session.aiohttp import AiohttpSession
auth = BasicAuth(login="user", password="password")
session = AiohttpSession(proxy=("protocol://host:port", auth))
or simply include your basic auth credential in URL
.. code-block::
session = AiohttpSession(proxy="protocol://user:password@host:port")
.. note::
Aiogram prefers `BasicAuth` over username and password in URL, so
if proxy URL contains login and password and `BasicAuth` object is passed at the same time
aiogram will use login and password from `BasicAuth` instance.
Proxy chains
------------
Since `aiohttp-socks <https://pypi.org/project/aiohttp-socks/>`_ supports proxy chains, you're able to use them in aiogram
Example of chain proxies:
.. code-block::
from aiohttp import BasicAuth
from aiogram.client.session.aiohttp import AiohttpSession
auth = BasicAuth(login="user", password="password")
session = AiohttpSession(
proxy={
"protocol0://host0:port0",
"protocol1://user:password@host1:port1",
("protocol2://host2:port2", auth),
} # can be any iterable if not set
)

View file

@ -0,0 +1,8 @@
####
Base
####
Abstract session for all client sessions
.. autoclass:: aiogram.client.session.base.BaseSession
:members:

View file

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

View file

@ -0,0 +1,10 @@
##############
Client session
##############
Client sessions is used for interacting with API server.
.. toctree::
custom_server
base
aiohttp