GPQBot
13 строк · 410.0 Байт
1from pybotx import Bot, IncomingMessage, IncomingMessageHandlerFunc
2
3
4async def db_session_middleware(
5message: IncomingMessage, bot: Bot, call_next: IncomingMessageHandlerFunc
6) -> None:
7session_factory = bot.state.db_session_factory
8
9async with session_factory() as db_session:
10message.state.db_session = db_session
11
12await call_next(message, bot)
13await db_session.commit()