24 lines
740 B
Python

from fastapi import APIRouter, Request, Depends
from botbuilder.schema import Activity
from botbuilder.core import TurnContext
from backend.app.factories.bot_factory import BotFactory
router = APIRouter()
@router.post("/api/messages", response_model=None)
async def messages(
req: Request,
bot = Depends(lambda: BotFactory().get_bot("dayta")),
adapter = Depends(lambda: BotFactory().get_adapter() )
):
body = await req.json()
activity = Activity().deserialize(body)
async def call_bot_logic(turn_context: TurnContext):
await bot.on_turn(turn_context)
auth_header = req.headers.get("Authorization", "")
await adapter.process_activity(activity, auth_header, call_bot_logic)
return {}