A plan to handle international (+) notation properly

Catalog of dial plans
Post Reply
SpookyET
Posts: 14
Joined: Mon Oct 06, 2008 3:45 pm
Contact:

A plan to handle international (+) notation properly

Post by SpookyET » Tue Mar 31, 2009 12:33 am

Hello,

I have two VoIP services, one to call in United States and Canada for as much as I want, and one to call internationally. The international service can also be used to call locally, but it charges per minute. On my iPhone, I like to store numbers in international format: +<country> <city> <number>. As in +44 (1632) 960008 for a UK number, where 44 is the country code, 1632 the city code, and 960008 the local number.

I also store my US numbers in that format because I want it to just work when I travel abroad: +1 (646) 555-1234.

In traditional calling, not VoiP, "+" is supposed to be converted to 00. And 00 is supposed to be converted to whatever prefix you asked your operator to associate with 00. This way, you don't have to know the dialling out code specific to the country you are in. In United States, 011 is the dialling out code. Another country may have a single dial out code like United States, or it may have many dial out codes such as 012, 014, 015, 018 with different tariffs for each prefix operator. You have to call customer support and associate one of them with 00 for the + notation to work.

I have discovered that VoIP apps on the iPhone behave differently. Some translate the + to 00. Others just send the + to MySipSwitch. So, I created this simple and ugly dial out plan. It seems to be working. However, I feel that it is not robust enough, and it may fail. I wonder how it can be cleaned up.

If the number starts with *, +, 00, or 011, use the international VoIP. If it starts with +1, 001, or anything else, dial the USA VoIP.

Thank you,

SpookyET

Code: Select all

sys.Log("call from #{req.Header.From.FromURI.ToString()} to #{req.URI.User}.")

if sys.In then
  # Do your incoming call processing customisations here.
  sys.Dial("#{sys.Username}@local")                  # Forwards all incoming calls to your registered contacts.
else
  # Do your outgoing call processing customisations here.
  case req.URI.User
    when /^303$/ then sys.Dial("303@sip.blueface.ie")  # Blueface speaking clock.
    when /^612$/ then sys.Dial("612@fwd.pulver.com")   # FWD speaking clock.
    when /^\*/ then sys.Dial("International")
    when /^\+1/ then sys.Dial("${dst:1}@USA")
    when /^\+/ then sys.Dial("011${dst:1}@International")
    when /^001/ then sys.Dial("${dst:2}@USA")
    when /^011/ then sys.Dial("${dst}@International")
    when /^00/ then sys.Dial("011${dst:2}@International")
    else sys.Dial("USA")
  end
end

User avatar
TheFug
Posts: 914
Joined: Sat Oct 06, 2007 8:23 am
Location: The Netherlands, North-Holland

Post by TheFug » Tue Mar 31, 2009 12:19 pm

It's possible to make a complete database like solution for that, i guess,
but something like this, is also possible:

Code: Select all


when /^(00|0011|001)/ then sys.Dial("${dst}@US-PROVIDER") 
Thanks, The Fug.

gear: my ISP's Zyxel Modem/Router in bridge, Sitecom WL309 Router, Siemens Gigaset 301D

SpookyET
Posts: 14
Joined: Mon Oct 06, 2008 3:45 pm
Contact:

Post by SpookyET » Thu Apr 02, 2009 7:40 pm

That's not going to work because the prefixes need to be stripped.

MikeTelis
Posts: 1582
Joined: Wed Jul 30, 2008 6:48 am

Post by MikeTelis » Thu Apr 16, 2009 5:56 am

You may want to try my flexible dial plan. The code dealing with international prefixes is here:

Code: Select all

    # sub! below removes prefixes:
    #  '+' - international format
    #   00 - European style international prefix (00)
    #  011 - US style international prefix (011)
    #  810 - Russian style international prefix (810)

    unless @num.sub!(/^(\+|00|011|810)/,'')  # If no international prefix, process special cases below
      case @num
         when /^82(\d{7,7})$/     # Calling to Moscow region, old format (before 496 area code)
           @num = '7496' + $1
         when /^8/
           @num[0] = '7'          # Russian style long distance prefix (8), replace 8 with country code (7)
         when /^[1-9]\d{6,6}$/
           @num = '7495' + @num   # Local call (Moscow 495 area)
      end
    end

Post Reply