Skip to content

Commit 687eef2

Browse files
committed
feat(portaswitch): enhance voicemail sender parsing to handle multiple formats
1 parent 2cca61f commit 687eef2

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

app/bss/adapters/portaswitch/serializer.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from datetime import datetime, timezone
23
from typing import Optional
34

@@ -305,7 +306,21 @@ def compose_display_name(first_name: Optional[str], last_name: Optional[str]) ->
305306

306307
@staticmethod
307308
def parse_voicemail_message_sender_user_ref(sender: str) -> str:
308-
return sender.split(" ")[1][1:]
309+
"""
310+
Parse sender field from a voicemail message and extract the caller number.
311+
312+
Expected formats (examples):
313+
1. "Caller #1001" -> "1001"
314+
2. "Caller #anonymous <anonymous@someserver-50.ops>" -> "anonymous"
315+
3. "123 (John Doe) <1001@pbx>" -> "1001"
316+
4. "123 <1001@pbx>" -> "1001"
317+
"""
318+
match = re.search(r"<([^@\s]+)@|#(\S+)", sender)
319+
320+
if match:
321+
return match.group(1) or match.group(2)
322+
323+
return sender
309324

310325
@staticmethod
311326
def parse_voicemail_message_receiver_user_ref(receiver: str) -> str:

0 commit comments

Comments
 (0)