diff --git a/VERSION b/VERSION index 3fe43a6..0f434c9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.88 +2.2.89 diff --git a/app/modules/telefoni/backend/router.py b/app/modules/telefoni/backend/router.py index df2aeab..8b4802e 100644 --- a/app/modules/telefoni/backend/router.py +++ b/app/modules/telefoni/backend/router.py @@ -210,7 +210,7 @@ async def yealink_established( def _is_external_number(value: Optional[str]) -> bool: 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: d = digits_only(value) @@ -221,6 +221,21 @@ async def yealink_established( return True 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) caller_value = _sanitize(caller) or _sanitize(remote) callee_value = _sanitize(callee) @@ -228,6 +243,12 @@ async def yealink_established( 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 if called_number_value and _is_external_number(called_number_value): is_outbound = True