Files
pepperplus-cb/src/control_backend/api/v1/endpoints/message.py
Kasper 129d3c4420 docs: add docs to CB
Pretty much every class and method should have documentation now.

ref: N25B-295
2025-11-24 21:58:22 +01:00

31 lines
808 B
Python

import logging
from fastapi import APIRouter, Request
from control_backend.schemas.message import Message
logger = logging.getLogger(__name__)
router = APIRouter()
@router.post("/message", status_code=202)
async def receive_message(message: Message, request: Request):
"""
Generic endpoint to receive text messages.
Publishes the message to the internal 'message' topic via ZMQ.
:param message: The message payload.
:param request: The FastAPI request object (used to access app state).
"""
logger.info("Received message: %s", message.message)
topic = b"message"
body = message.model_dump_json().encode("utf-8")
pub_socket = request.app.state.endpoints_pub_socket
await pub_socket.send_multipart([topic, body])
return {"status": "Message received"}