Косметические правки по фронту, раскатка приложения в продакшн версии, исправление бага с созданием контакта
This commit is contained in:
@@ -117,6 +117,67 @@ async def ensure_delivery_outbox(
|
||||
return outbox
|
||||
|
||||
|
||||
OPENLINES_FALLBACK_DISPLAY_NAME = "Новый клиент HAN"
|
||||
|
||||
|
||||
def openlines_display_name(full_name: str | None) -> str:
|
||||
name = (full_name or "").strip()
|
||||
return name or OPENLINES_FALLBACK_DISPLAY_NAME
|
||||
|
||||
|
||||
def openlines_user_payload(user: UserIdentity, profile: ClientProfile | None) -> dict[str, str]:
|
||||
return {
|
||||
"id": str(user.id),
|
||||
"display_name": openlines_display_name(profile.full_name if profile else None),
|
||||
"phone": user.phone_number,
|
||||
}
|
||||
|
||||
|
||||
async def load_active_client_profile(
|
||||
session: AsyncSession, user_id: uuid.UUID
|
||||
) -> ClientProfile | None:
|
||||
return (
|
||||
await session.execute(
|
||||
select(ClientProfile).where(
|
||||
ClientProfile.user_id == user_id, ClientProfile.record_status == "A"
|
||||
)
|
||||
)
|
||||
).scalar_one_or_none()
|
||||
|
||||
|
||||
def openlines_delivery_payload(
|
||||
*,
|
||||
message: Message,
|
||||
dialog_id: uuid.UUID,
|
||||
user: UserIdentity,
|
||||
profile: ClientProfile | None,
|
||||
attachment: MessageAttachment | None,
|
||||
) -> dict[str, Any]:
|
||||
files: list[dict[str, Any]] = []
|
||||
if attachment:
|
||||
files.append(
|
||||
{
|
||||
"attachment_id": str(attachment.id),
|
||||
"name": attachment.safe_file_name,
|
||||
"mime_type": attachment.mime_type,
|
||||
"size_bytes": attachment.size_bytes,
|
||||
"_storage_bucket": attachment.storage_bucket,
|
||||
"_object_key": attachment.object_key,
|
||||
}
|
||||
)
|
||||
return {
|
||||
"message_id": str(message.id),
|
||||
"external_chat_id": str(dialog_id),
|
||||
"occurred_at": message.occurred_at.isoformat(),
|
||||
"user": openlines_user_payload(user, profile),
|
||||
"message": {
|
||||
"content_kind": message.content_kind,
|
||||
"text": message.text,
|
||||
"files": files,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class DomainError(Exception):
|
||||
def __init__(self, code: str, status: int, message: str, details: dict[str, Any] | None = None):
|
||||
self.code, self.status, self.message = code, status, message
|
||||
@@ -1032,34 +1093,18 @@ async def send_message(
|
||||
"bypassed" if verdict["processing_mode"] == "mock" else "clean"
|
||||
)
|
||||
message.safety_status = "allowed"
|
||||
profile = await load_active_client_profile(session, user.id)
|
||||
outbox = await ensure_delivery_outbox(
|
||||
session,
|
||||
message_id=message.id,
|
||||
external_chat_id=dialog_id,
|
||||
payload_json={
|
||||
"message_id": str(message.id),
|
||||
"external_chat_id": str(dialog_id),
|
||||
"occurred_at": message.occurred_at.isoformat(),
|
||||
"user": {"id": str(user.id), "display_name": user.phone_number},
|
||||
"message": {
|
||||
"content_kind": message.content_kind,
|
||||
"text": message.text,
|
||||
"files": (
|
||||
[
|
||||
{
|
||||
"attachment_id": str(attachment.id),
|
||||
"name": attachment.safe_file_name,
|
||||
"mime_type": attachment.mime_type,
|
||||
"size_bytes": attachment.size_bytes,
|
||||
"_storage_bucket": attachment.storage_bucket,
|
||||
"_object_key": attachment.object_key,
|
||||
}
|
||||
]
|
||||
if attachment
|
||||
else []
|
||||
),
|
||||
},
|
||||
},
|
||||
payload_json=openlines_delivery_payload(
|
||||
message=message,
|
||||
dialog_id=dialog_id,
|
||||
user=user,
|
||||
profile=profile,
|
||||
attachment=attachment,
|
||||
),
|
||||
# Keep the row recoverable after a process crash, but do not let the
|
||||
# delivery worker race the synchronous first attempt.
|
||||
next_attempt_at=datetime.now(UTC)
|
||||
|
||||
Reference in New Issue
Block a user