fix: Rich-Markup-Fehler bei leeren Styles + Telefonnummer-Normalisierung

- _render_message: leeren style-Tag vermieden (MarkupError bei inbound-Msgs)
- Nachrichtentext: eckige Klammern werden escaped (kein Markup-Injection)
- get_by_phone: sucht +49xxx und 49xxx gleichzeitig (Green API liefert ohne +)
This commit is contained in:
2026-03-13 14:58:04 +01:00
parent 0f73341c8b
commit b0c6ba44de
2 changed files with 13 additions and 10 deletions

View File

@@ -19,11 +19,14 @@ def get_by_telegram_id(db: Session, telegram_id: str) -> Contact | None:
def get_by_phone(db: Session, phone: str) -> Contact | None: def get_by_phone(db: Session, phone: str) -> Contact | None:
return ( # Normalisierung: mit und ohne führendes + suchen
db.query(Contact) variants = {phone, "+" + phone.lstrip("+"), phone.lstrip("+")}
.filter((Contact.phone == phone) | (Contact.whatsapp_phone == phone)) from sqlalchemy import or_
.first() conditions = or_(*(
) (Contact.phone == v) | (Contact.whatsapp_phone == v)
for v in variants
))
return db.query(Contact).filter(conditions).first()
def create(db: Session, data: ContactCreate) -> Contact: def create(db: Session, data: ContactCreate) -> Contact:

View File

@@ -143,11 +143,11 @@ class MainScreen(Screen):
direction = msg.get("direction", "outbound") direction = msg.get("direction", "outbound")
direction_prefix = "" if direction == "outbound" else "" direction_prefix = "" if direction == "outbound" else ""
status_suffix = "" if msg.get("status") == "failed" else "" status_suffix = "" if msg.get("status") == "failed" else ""
style = "dim" if direction == "outbound" else "" text = msg.get("text", "").replace("[", "\\[")
text = msg.get("text", "") if direction == "outbound":
log.write( log.write(f"[dim]{ts}[/dim] [dim]{direction_prefix}{text}{status_suffix}[/dim]")
f"[dim]{ts}[/dim] [{style}]{direction_prefix}{text}{status_suffix}[/{style}]" else:
) log.write(f"[dim]{ts}[/dim] {direction_prefix}{text}{status_suffix}")
# ── Background-Polling ───────────────────────────────────────────────────── # ── Background-Polling ─────────────────────────────────────────────────────