eric-brechemier / how-i-replaced-skype-with-twilio

How I replaced Skype with Twilio to make phone calls from my computer
Creative Commons Attribution 4.0 International
43 stars 9 forks source link

e164 Mustache filter transforms UK phone number into US phone number #11

Open eric-brechemier opened 2 years ago

eric-brechemier commented 2 years ago

I configured a new UK mobile phone number today, which failed to make calls due to an invalid caller id.

I am using the generic TwiML Bin from the guide, which extracts the phone number from the SIP Domain:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Dial callerId="{{#e164}}{{SipDomain}}{{/e164}}">{{#e164}}{{To}}{{/e164}}</Dial>
</Response>

The e164 Mustache filter used to extract my own phone number from the SIP Domain no longer works with that UK phone number. The caller id is reported as invalid.

I reproduced the issue using a fake UK phone number, which I included in the example below:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Dial callerId="{{#e164}}44-7355-547122.sip.twilio.com{{/e164}}">{{#e164}}{{To}}{{/e164}}</Dial>
</Response>

The error log shows the resulting value, which is quite unexpectedly a US Phone number:

invalidCallerId: "+17355547122"

I have also tried prefixing the value with a +

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Dial callerId="{{#e164}}+44-7355-547122.sip.twilio.com{{/e164}}">{{#e164}}{{To}}{{/e164}}</Dial>
</Response>

which makes no difference:

invalidCallerId: "+17355547122"
eric-brechemier commented 2 years ago

Calling the same UK phone number results in a correct conversion, however, in the {{To}} number.

The number is received by Twilio as:

To: "sip:+447355547122@44-7360-271984.sip.us1.twilio.com"

and correctly transformed to:

+447355547122
eric-brechemier commented 2 years ago

Let's try different values:

{{#e164}}+447355547122{{/e164}} -> +447355547122
{{#e164}}+44-7355547122{{/e164}} -> +447355547122
{{#e164}}447355547122{{/e164}} -> +447355547122

{{#e164}}44-7355-547122{{/e164}} -> +17355547122
{{#e164}}+44-7355-547122{{/e164}} -> +17355547122
{{#e164}}+44-7-355547122{{/e164}} -> +17355547122

{{#e164}}0044-7355-547122{{/e164}} -> 0044-7355-547122
eric-brechemier commented 2 years ago

The {{#e164}} filter results in different phone numbers depending on the presence and the position of the dashes which separate groups of digits in the phone number.

eric-brechemier commented 2 years ago

I have reported this issue to Twilio for their consideration.

As a workaround, I now recommend, for the configuration of any new phone number, to remove all dashes from the phone number value used as unique SIP domain.

There is no point in changing the configuration of existing phone numbers. If your number works correctly and you can make calls from your SIP phone to regular phone numbers, it means that your SIP domain name is not affected by the unexpected conversion to a different international country code when getting through the e164 Mustache filter.