|
1 | 1 | """Endpoints for communication with botx.""" |
2 | 2 |
|
3 | 3 | from http import HTTPStatus |
4 | | - |
5 | | -from fastapi import APIRouter, Request |
| 4 | +from dependency_injector.wiring import inject, Provide |
| 5 | +from fastapi import APIRouter, Request, Depends |
6 | 6 | from fastapi.responses import JSONResponse |
7 | 7 | from pybotx import ( |
8 | 8 | Bot, |
|
16 | 16 | ) |
17 | 17 | from pybotx.constants import BOT_API_VERSION |
18 | 18 |
|
| 19 | +from app.infrastructure.containers import ApplicationStartupContainer |
19 | 20 | from app.logger import logger |
20 | | -from app.presentation.api.bot import bot_dependency |
21 | 21 | from app.settings import settings |
22 | 22 |
|
23 | 23 | router = APIRouter() |
24 | 24 |
|
25 | 25 |
|
26 | 26 | @router.post("/command") |
27 | | -async def command_handler(request: Request, bot: Bot = bot_dependency) -> JSONResponse: |
| 27 | +@inject |
| 28 | +async def command_handler( |
| 29 | + request: Request, |
| 30 | + bot: Bot = Depends(Provide[ApplicationStartupContainer.bot]), |
| 31 | +) -> JSONResponse: |
28 | 32 | """Receive commands from users. Max timeout - 5 seconds.""" |
29 | 33 |
|
30 | 34 | try: |
@@ -78,7 +82,11 @@ async def command_handler(request: Request, bot: Bot = bot_dependency) -> JSONRe |
78 | 82 |
|
79 | 83 |
|
80 | 84 | @router.get("/status") |
81 | | -async def status_handler(request: Request, bot: Bot = bot_dependency) -> JSONResponse: |
| 85 | +@inject |
| 86 | +async def status_handler( |
| 87 | + request: Request, |
| 88 | + bot: Bot = Depends(Provide[ApplicationStartupContainer.bot]), |
| 89 | +) -> JSONResponse: |
82 | 90 | """Show bot status and commands list.""" |
83 | 91 |
|
84 | 92 | try: |
@@ -112,7 +120,11 @@ async def status_handler(request: Request, bot: Bot = bot_dependency) -> JSONRes |
112 | 120 |
|
113 | 121 |
|
114 | 122 | @router.post("/notification/callback") |
115 | | -async def callback_handler(request: Request, bot: Bot = bot_dependency) -> JSONResponse: |
| 123 | +@inject |
| 124 | +async def callback_handler( |
| 125 | + request: Request, |
| 126 | + bot: Bot = Depends(Provide[ApplicationStartupContainer.bot]), |
| 127 | +) -> JSONResponse: |
116 | 128 | """Process BotX methods callbacks.""" |
117 | 129 |
|
118 | 130 | try: |
|
0 commit comments