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