upd update handling
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
from typing import Annotated
|
from fastapi import APIRouter, Request, Response, BackgroundTasks
|
||||||
from fastapi import APIRouter, Depends, Request, Response, BackgroundTasks
|
from fastapi.datastructures import State
|
||||||
from sqlmodel.ext.asyncio.session import AsyncSession
|
|
||||||
from ..main import QBotApp
|
from ..main import QBotApp
|
||||||
|
|
||||||
|
|
||||||
from ..db import get_db
|
from ..db import async_session
|
||||||
from aiogram.types import Update
|
from aiogram.types import Update
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
@@ -15,7 +14,7 @@ router = APIRouter()
|
|||||||
|
|
||||||
@router.post("/webhook")
|
@router.post("/webhook")
|
||||||
async def telegram_webhook(
|
async def telegram_webhook(
|
||||||
db_session: Annotated[AsyncSession, Depends(get_db)],
|
# db_session: Annotated[AsyncSession, Depends(get_db)],
|
||||||
request: Request,
|
request: Request,
|
||||||
background_tasks: BackgroundTasks,
|
background_tasks: BackgroundTasks,
|
||||||
):
|
):
|
||||||
@@ -32,11 +31,24 @@ async def telegram_webhook(
|
|||||||
logger.error("Invalid request", exc_info=True)
|
logger.error("Invalid request", exc_info=True)
|
||||||
return Response(status_code=400)
|
return Response(status_code=400)
|
||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
app.dp.feed_webhook_update,
|
feed_bot_update,
|
||||||
bot=app.bot,
|
|
||||||
update=update,
|
|
||||||
db_session=db_session,
|
|
||||||
app=app,
|
app=app,
|
||||||
|
update=update,
|
||||||
app_state=request.state,
|
app_state=request.state,
|
||||||
)
|
)
|
||||||
return Response(status_code=200)
|
return Response(status_code=200)
|
||||||
|
|
||||||
|
|
||||||
|
async def feed_bot_update(
|
||||||
|
app: QBotApp,
|
||||||
|
update: Update,
|
||||||
|
app_state: State,
|
||||||
|
):
|
||||||
|
async with async_session() as db_session:
|
||||||
|
await app.dp.feed_webhook_update(
|
||||||
|
bot=app.bot,
|
||||||
|
update=update,
|
||||||
|
db_session=db_session,
|
||||||
|
app=app,
|
||||||
|
app_state=app_state,
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user