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 ...