diff --git a/common_lib/services/chat_internal.py b/common_lib/services/chat_internal.py new file mode 100644 index 0000000..75bd71e --- /dev/null +++ b/common_lib/services/chat_internal.py @@ -0,0 +1,27 @@ +import httpx +from uuid import UUID +from fastapi import HTTPException, status +from config import settings +from common_lib.utils.http_client import client + + +async def send_internal_message(sender: str, user_id: UUID, content: str) -> dict: + try: + response = await client.post( + f"{settings.CHAT_PRIVATE_SERVICE}/internal/send", + json={"sender": str(sender), + "user_id": str(user_id), + "content": str(content) + }) + + if response.status_code != 200: + raise HTTPException( + status_code=response.status_code, + detail=f"chat_private_service: {response.text}" + ) + + wrapped = response.json() + return wrapped["data"] + + except httpx.RequestError as e: + raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail=f"chat_private_service unreachable: {str(e)}") diff --git a/pyproject.toml b/pyproject.toml index 1f8f9a5..6d490a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "common-lib" -version = "0.0.23" +version = "0.0.24" description = "Библиотека общих компонентов для микросервисов yobble" authors = [{ name = "cheykrym", email = "you@example.com" }] license = "MIT"