add internal msg
This commit is contained in:
parent
f46f3904e5
commit
bfc63823bd
27
common_lib/services/chat_internal.py
Normal file
27
common_lib/services/chat_internal.py
Normal file
@ -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)}")
|
||||
@ -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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user