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