| 123456789101112131415161718192021222324252627282930313233343536 |
- from datetime import datetime, timezone
- from .phone import normalize
- def normalize_call(participant: dict, queue_dn: str) -> dict:
- raw = participant.get("party_caller_id")
- normalized = normalize(raw, "DE") if raw else {
- "e164": None,
- "valid": False,
- }
- return {
- "callId": participant.get("callid"),
- "legId": participant.get("legid"),
- "queue": queue_dn,
- "direction": (
- "inbound"
- if participant.get("party_dn_type") == "Wexternalline"
- else "internal"
- ),
- "status": (participant.get("status") or "unknown").lower(),
- "caller": {
- "raw": raw,
- "e164": normalized.get("e164"),
- },
- "agent": None,
- "observedAt": datetime.now(timezone.utc).isoformat(),
- "source": {
- "partyDn": participant.get("party_dn"),
- "partyDnType": participant.get("party_dn_type"),
- "deviceId": participant.get("device_id"),
- "directControl": participant.get("direct_control"),
- },
- }
|