fix: strip local phone suffix from overly long caller numbers (Yealink URL misconfiguration)

This commit is contained in:
Christian 2026-05-05 00:29:13 +02:00
parent e4e35a1285
commit 31fa771626
2 changed files with 23 additions and 2 deletions

View File

@ -1 +1 @@
2.2.88 2.2.89

View File

@ -210,7 +210,7 @@ async def yealink_established(
def _is_external_number(value: Optional[str]) -> bool: def _is_external_number(value: Optional[str]) -> bool:
d = digits_only(value) d = digits_only(value)
return len(d) >= 8 return 8 <= len(d) <= 15
def _is_internal_number(value: Optional[str], local_ext: Optional[str]) -> bool: def _is_internal_number(value: Optional[str], local_ext: Optional[str]) -> bool:
d = digits_only(value) d = digits_only(value)
@ -221,6 +221,21 @@ async def yealink_established(
return True return True
return len(d) <= 6 return len(d) <= 6
def _strip_local_suffix(value: Optional[str], local_ext: Optional[str]) -> Optional[str]:
"""If a number is too long (> 15 E.164 digits), try stripping the local extension
from the end. This fixes Yealink Action URL misconfiguration where $caller$local
gets concatenated without a separator."""
if not value or not local_ext:
return value
d = digits_only(value)
local_d = digits_only(local_ext)
if len(d) > 15 and local_d and d.endswith(local_d):
stripped = d[: len(d) - len(local_d)]
if len(stripped) >= 4:
# Re-apply leading '+' if original had it
return ("+" + stripped) if value.lstrip().startswith("+") else stripped
return value
local_value = _sanitize(local) or _sanitize(active_user) local_value = _sanitize(local) or _sanitize(active_user)
caller_value = _sanitize(caller) or _sanitize(remote) caller_value = _sanitize(caller) or _sanitize(remote)
callee_value = _sanitize(callee) callee_value = _sanitize(callee)
@ -228,6 +243,12 @@ async def yealink_established(
local_extension = extract_extension(local_value) or local_value local_extension = extract_extension(local_value) or local_value
# Fix Yealink misconfiguration where caller number has the local phone number
# concatenated at the end (e.g. "$caller$local" without a separator in the URL template).
caller_value = _strip_local_suffix(caller_value, local_extension) or caller_value
if _sanitize(remote):
remote = _strip_local_suffix(_sanitize(remote), local_extension) or remote
is_outbound = False is_outbound = False
if called_number_value and _is_external_number(called_number_value): if called_number_value and _is_external_number(called_number_value):
is_outbound = True is_outbound = True