Реализованы задачи бэклога 1-5 (1я не до конца)
This commit is contained in:
@@ -41,6 +41,11 @@ from app.postgres import create_postgres_engine
|
||||
|
||||
logger = logging.getLogger("bitrix-local-app")
|
||||
|
||||
BITRIX_SENDER_PREFIX = re.compile(
|
||||
r"^\[b\][^\r\n\[]+:\[/b\]\s*(?:\[br\]\s*)?",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
CONNECTOR_ICON_DATA_URI = "data:image/svg+xml," + quote(
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">'
|
||||
'<path fill="#fff" d="M20 20h15v25h30V20h15v60H65V60H35v20H20z"/>'
|
||||
@@ -222,6 +227,10 @@ def first(value: Any, *paths: tuple[str, ...]) -> Any:
|
||||
return None
|
||||
|
||||
|
||||
def strip_bitrix_sender_prefix(text: str) -> str:
|
||||
return BITRIX_SENDER_PREFIX.sub("", text, count=1)
|
||||
|
||||
|
||||
def normalize_event(payload: dict[str, Any]) -> dict[str, Any] | None:
|
||||
event = str(payload.get("event", "")).upper()
|
||||
if event not in {
|
||||
@@ -257,6 +266,7 @@ def normalize_event(payload: dict[str, Any]) -> dict[str, Any] | None:
|
||||
text_value = str(
|
||||
first(data, ("MESSAGES", "0", "message", "text"), ("MESSAGE", "TEXT")) or ""
|
||||
)
|
||||
text_value = strip_bitrix_sender_prefix(text_value)
|
||||
files_raw = first(data, ("MESSAGES", "0", "message", "files"), ("MESSAGE", "FILES")) or []
|
||||
if isinstance(files_raw, dict):
|
||||
files_raw = list(files_raw.values())
|
||||
|
||||
Reference in New Issue
Block a user