Incoming calls from PSTN via SIPbroker

Catalog of dial plans
Post Reply
MikeTelis
Posts: 1582
Joined: Wed Jul 30, 2008 6:48 am

Incoming calls from PSTN via SIPbroker

Post by MikeTelis » Tue Aug 12, 2008 7:19 pm

The following is not my complete dialplan, it's a part handling incoming calls from Voxalot / SIPbroker. The problem is that approximately a half of their PSTN access numbers send Caller IDs in a wrong format, something like this:

Calgary,AB <sip:403xxxxxxx@202.202.202.202>

It is a comma in FromName that is giving us a problem, it's not recognized by most of softphones (like X-Lite, Bria, SJ Phone) and the softphone won't ring at all.

The purpose of this code is to transform these caller IDs into proper format:

1403xxxxxxx <sip:403xxxxxxx@202.202.202.202>

We need to extract caller's phone number from URI and, if it's a 10-digit US/Canada number, add country code (1) in front of the number.

Here is the code:

Code: Select all

if sys.In then          # If incoming call...

  name = req.Header.From.FromName.to_s     # create a copy of FromName

  if name =~ /^$|\D/ then            # if FromName isn't empty and isn't all digits (caller's phone #)
    req.Header.From.FromURI.ToString.to_s =~ /^(sip:)*(\d*)@/  # replace it w/phone # from FromURI
    name = $2                        # All digits between optional "sip:" and '@' are in $2
  end

#Next line will prefix 10-digit numbers with "1" (US country code). Some SIPbroker PSTN send CID without country code
  name = ("1" + name) if name =~ /^[2-9]\d{9,9}$/

  sys.Log("FromName: '#{name}'")
  req.Header.From.FromName = name    # Set FromName for sys.Dial  

  if sys.IsAvailable() then                           # If my ATA is registered  
    sys.Dial("#{sys.Username}@local")                 # forward all incoming calls to it
  else                                                # else forward calls to my home phone
    sys.Log("#{sys.Username} is not online.")
    sys.Log("Forwarding call to home number")
    sys.Dial("xxxxxxxxxxx@Provider",35)
    sys.Log("Call timed out!")
    sys.Respond(480, "#{sys.Username} Not online")
  end

else                    # Outbound call ...

gbonnet
Site Admin
Posts: 680
Joined: Wed Jul 11, 2007 2:58 pm
Location: Bologna
Contact:

Post by gbonnet » Tue Aug 12, 2008 7:56 pm

Thanks Mike for starting to post in this new section!
Blueface [url=http://www.blueface.ie/]Phone[/url] Service

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

Post by TheFug » Wed Aug 20, 2008 3:35 pm

emoci helped me with this one, he advised me to make a "dummy" account for SipBroker, username: anon server: sipbroker.com
password: can be left open, The From header can also be set, "TheFug" <sip:0031231234567@sip.mysipswitch.com>
And this works perfect for me, to peer through any peering network, to their users #ID phone number,
using: when /^\*8/ then sys.Dial("${dst:2}@SIPBROKER") as a Ruby dialplan rule.
Thanks, The Fug.

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

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

Post by TheFug » Wed Aug 20, 2008 3:55 pm

Hi, MikeTelis, what i see on my telephone, is an extra 080 at the start,
could i use your code to correct it, and will it also work, for me here in my "Netherlands " situation ? my country code is 0031 and have a 3 digit city code (calling nationaly) where the first zero will be removed from, when dialing internationaly.
Thanks, The Fug.

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

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

Post by MikeTelis » Wed Aug 20, 2008 7:49 pm

I'm not sure I can follow your idea. Please add the following lines to your dialplan's "incoming call" code:

sys.Log("FromHost: '#{req.Header.from.FromURI.Host}'")
sys.Log("FromUser: '#{req.Header.from.FromURI.User}'")
sys.Log("FromName: '#{req.Header.From.FromName}'")

Show me what you see in the log on incoming calls and explain what needs to be changed. I'll tell you how :-)

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

Post by TheFug » Wed Aug 20, 2008 9:40 pm

Okay, i added the lines you mentioned, and i see now, in the CDR at least, the correct CallerID, as an addition in the From: frame there, so i guess i leave it at this..
Thanks for your help, i'm a bit tweaking my dialplan:

Code: Select all

#Ruby

sys.Trace=true 
#rem"${fromname}" <sip:${fromuriuser}@sip.mysipswitch.com>
sys.Log("call received on #{req.URI.ToString()} from #{req.Header.From.FromURI.ToString()} at #{Time.now}.")

if sys.Out then
 sys.Log("Outgoing call from user domain=#{sys.FromDomain}.")



   
 case req.URI.User
  when /^(8|613|612|958|514|615)/ then sys.Dial("FWD")
  when /^00498/ then sys.Dial("275498${dst:5}@BRUJULA")
  when /^(001800|001866|001877|003180|0044800|0044500|0044808|0049800|0049130|0047800)/ then sys.Dial("*${dst:2}@FWD")
  when /^06/ then sys.Dial("00316${dst:2}@INTERVOIP")
  when /^08/ then sys.Dial("*318${dst:2}@FWD")
  when /^(0|00)/ then sys.Dial("${dst}@VOIPBUSTER") 
  when /^1777/ then sys.Dial("CALLCENTRIC")
  when /^\*75/ then sys.Dial("*75${dst:3}@CALLCENTRIC")
  when /^\*1/ then sys.Dial("${dst:2}@BRUJULA")
  when /^\*2/ then sys.Dial("${dst:2}@SIPGATE")
  when /^\*3/ then sys.Dial("${dst:2}@ORBTALK")
  when /^\*4/ then sys.Dial("${dst:2}@FWD")
  when /^\*5/ then sys.Dial("${dst:2}@IXCALL")
  when /^\*6/ then sys.Dial("${dst:2}@VOXALOT")
  when /^\*7/ then sys.Dial("${dst:2}@CALLCENTRIC")
  when /^\*8/ then sys.Dial("${dst:2}@SIPBROKER")
  when /^\*9/ then sys.Dial("${dst:2}@VOIPBUSTER")
  when /^\*0/ then sys.Dial("${dst:2}@INTERVOIP")
    
 end
else
 sys.Log("Incoming call to domain=#{sys.ToDomain} from host #{req.Header.From.FromURI.Host}.")
 if sys.IsAvailable() then

sys.Log("FromHost: '#{req.Header.from.FromURI.Host}'")
sys.Log("FromUser: '#{req.Header.from.FromURI.User}'")
sys.Log("FromName: '#{req.Header.From.FromName}'")

   sys.Log("#{sys.Username} is online.")
   sys.Dial("#{sys.Username}@local&00316234567@INTERVOIP")
 else
   sys.Log("#{sys.Username} is not online.")
   sys.Respond(480, "#{sys.Username} Not online")
 end
end

I guess, when I'm not online my cellphone also won't ring, (INTERVOIP)

sys.Dial("00316234567@INTERVOIP") will do in the "is not online" section at the end of my dialplan i guess...
Last edited by TheFug on Thu Aug 21, 2008 10:55 am, edited 2 times in total.
Thanks, The Fug.

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

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

Post by TheFug » Wed Aug 20, 2008 10:05 pm

With the lines now in the correct place i get:

DialPlan=> FromHost: 'ixcall.net'
DialPlan=> FromUser: '3180231234567'
DialPlan=> FromName: '0231234567'
DialPlan=> Fugcall is online.

and just discoverd, that it's a Philips DECT on my Siemens C450IP base station, that gives a wrong read out of the CallerID,
And is caused by Ixcall i guess, because this call is made via Ixcall DID (landline Netherlands) peering to Voxalot, calling my own user IDphone# there, the other handsets and cellphone, show correctly my city and subscriber number, without any in front of that.
And the Philips shows: 080231234567 (what's incorrect)

Thanks ! I guess it's solved now.
Thanks, The Fug.

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

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

Post by MikeTelis » Thu Aug 21, 2008 6:20 am

The calls to sys.Log do not fix anything, they just display debugging info. sys.Log lines from my previous post display various fields of the From header.

The following simple steps will speed up your work on Ruby dialplan and prevent from silly mistakes :-)

1. Put sys.Log debug lines in place to display call data (that's what I suggested in my previous post).

2. Create local variables for your req.*, assign them with values that appear in your log (see step 1) and use IronEditor for debugging.

For example:

host = 'ixcall.net'
user = '3180231234567'
name = '0231234567'

Now you can write your code playing with the local variables and display them onto IronEditor output window with Ruby's

puts "Name = #{name}"

3. Once your code is working as desired, port it to your MSS dialplan.

host = req.Header.from.FromURI.Host.to_s
user = req.Header.from.FromURI.User.to_s
name = req.Header.From.FromName.to_s

...
... the code you designed is here
...

Save local variables into the ones from req class, if necessary, like here:

req.Header.From.FromName = name # Set FromName for sys.Dial

Now, if you see a req variable used just once in your code, you may want to simplify it by avoiding copying into and from local variable.

Note that working with req string variables is pretty messy right now. If something works in IronEditor and doesn't work in real life (MSS) - most certainly you need to apply "ToString" or to_s methods (sometimes both!!) to them.

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

Post by TheFug » Thu Aug 21, 2008 11:03 am

Thank you, MikeTelis, if I can play around with variables, would help me indeed, I'll try it.
Thanks, The Fug.

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

Post Reply