Косметические правки по фронту, раскатка приложения в продакшн версии, исправление бага с созданием контакта
This commit is contained in:
@@ -114,6 +114,7 @@ class UserDto(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
id: uuid.UUID
|
||||
display_name: str = Field(min_length=1, max_length=255)
|
||||
phone: str | None = Field(default=None, min_length=1, max_length=32)
|
||||
|
||||
|
||||
class FileDto(BaseModel):
|
||||
@@ -697,7 +698,7 @@ def create_app(settings: Settings | None = None) -> FastAPI:
|
||||
"Idempotency-Key must equal message_id",
|
||||
),
|
||||
)
|
||||
body = dto.model_dump(mode="json")
|
||||
body = dto.model_dump(mode="json", exclude_none=True)
|
||||
fp = canonical_fingerprint(body)
|
||||
async with request.app.state.sessions() as session:
|
||||
row = await session.scalar(
|
||||
@@ -992,17 +993,11 @@ def extract_delivery(result: dict[str, Any]) -> tuple[int | None, str | None, st
|
||||
)
|
||||
|
||||
|
||||
async def deliver_outbound(app: FastAPI, row_id: uuid.UUID) -> dict[str, Any]:
|
||||
async with app.state.sessions() as session:
|
||||
row = await session.get(OutboundMessage, row_id)
|
||||
portal = await active_portal(session)
|
||||
if not row or not portal:
|
||||
raise RuntimeError("portal_not_installed")
|
||||
payload = row.payload_json
|
||||
def imconnector_send_fields(connector: str, line: str, payload: dict[str, Any]) -> dict[str, Any]:
|
||||
message = payload["message"]
|
||||
fields: dict[str, Any] = {
|
||||
"CONNECTOR": app.state.settings.bitrix_connector_id,
|
||||
"LINE": app.state.settings.bitrix_open_line_id,
|
||||
"CONNECTOR": connector,
|
||||
"LINE": line,
|
||||
"MESSAGES[0][user][id]": payload["user"]["id"],
|
||||
"MESSAGES[0][user][name]": payload["user"]["display_name"],
|
||||
"MESSAGES[0][message][id]": payload["message_id"],
|
||||
@@ -1010,10 +1005,28 @@ async def deliver_outbound(app: FastAPI, row_id: uuid.UUID) -> dict[str, Any]:
|
||||
"MESSAGES[0][message][text]": message["text"],
|
||||
"MESSAGES[0][chat][id]": payload["external_chat_id"],
|
||||
}
|
||||
if message["files"]:
|
||||
phone = payload["user"].get("phone")
|
||||
if phone:
|
||||
fields["MESSAGES[0][user][phone]"] = phone
|
||||
if message.get("files"):
|
||||
file = message["files"][0]
|
||||
fields["MESSAGES[0][message][files][0][url]"] = file["download_url"]
|
||||
fields["MESSAGES[0][message][files][0][name]"] = file["name"]
|
||||
return fields
|
||||
|
||||
|
||||
async def deliver_outbound(app: FastAPI, row_id: uuid.UUID) -> dict[str, Any]:
|
||||
async with app.state.sessions() as session:
|
||||
row = await session.get(OutboundMessage, row_id)
|
||||
portal = await active_portal(session)
|
||||
if not row or not portal:
|
||||
raise RuntimeError("portal_not_installed")
|
||||
payload = row.payload_json
|
||||
fields = imconnector_send_fields(
|
||||
app.state.settings.bitrix_connector_id,
|
||||
app.state.settings.bitrix_open_line_id,
|
||||
payload,
|
||||
)
|
||||
result = await app.state.bitrix.call(portal, "imconnector.send.messages", fields)
|
||||
chat_id, session_id, bitrix_message_id = extract_delivery(result)
|
||||
response = {
|
||||
|
||||
@@ -91,6 +91,7 @@ components:
|
||||
properties:
|
||||
id: {type: string, format: uuid}
|
||||
display_name: {type: string, maxLength: 255}
|
||||
phone: {type: string, minLength: 1, maxLength: 32}
|
||||
message:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
|
||||
@@ -23,6 +23,7 @@ from app.main import (
|
||||
BitrixClient,
|
||||
TokenCipher,
|
||||
canonical_fingerprint,
|
||||
imconnector_send_fields,
|
||||
normalize_event,
|
||||
resolve_inbound_file_urls,
|
||||
retry_delay,
|
||||
@@ -278,3 +279,23 @@ async def test_bitrix_call_refreshes_and_retries_once_after_401():
|
||||
assert result == {"ok": True}
|
||||
assert auth_values == ["old-access", "new-access"]
|
||||
assert refresh_calls == [False, True]
|
||||
|
||||
|
||||
def test_imconnector_send_fields_maps_name_and_phone():
|
||||
payload = {
|
||||
"message_id": "mid",
|
||||
"external_chat_id": "chat",
|
||||
"occurred_at": "2026-07-10T09:00:00Z",
|
||||
"user": {"id": "uid", "display_name": "Иван Иванов", "phone": "+79990000000"},
|
||||
"message": {"text": "hello", "files": []},
|
||||
}
|
||||
fields = imconnector_send_fields("han_mobile_app", "8", payload)
|
||||
assert fields["MESSAGES[0][user][name]"] == "Иван Иванов"
|
||||
assert fields["MESSAGES[0][user][phone]"] == "+79990000000"
|
||||
legacy = {
|
||||
**payload,
|
||||
"user": {"id": "uid", "display_name": "+79990000000"},
|
||||
}
|
||||
legacy_fields = imconnector_send_fields("han_mobile_app", "8", legacy)
|
||||
assert "MESSAGES[0][user][phone]" not in legacy_fields
|
||||
assert legacy_fields["MESSAGES[0][user][name]"] == "+79990000000"
|
||||
|
||||
Reference in New Issue
Block a user