Google Call Back Clarification
azrobert:
I copied the code I supplied and put it at the beginning of the inbound portion of my dialplan.
It works.
Below is code closer to my real dialplan. It includes code for a table lookup. The OpenCnam code is a sub-routine. The dialplan has a Begin statement which requires an additional End statement. I remove a lot of code, so I hope I didn't make any mistakes.
If you can't get it working, post your code and I'll see if I can spot the problem.
Code:
#Ruby # DialPlan1
TNAME = {
'4808370001' => 'Home',
'4808370002' => 'Work',
'4808370003' => 'Wife',
'4808370004' => 'Mother',
'4808370005' => 'Father',
'4808370006' => 'Girl Friend' }
def getcname cid
@OpenCName ||= sys.WebGet("https://api.opencnam.com/v2/phone/#{cid}?format=text",4)
sys.log("CallerName: #{@OpenCName}")
prs = @OpenCName.split(' ')
State = prs[-1]
if City = prs[-2]
@cname = "#{City} #{State}"
else
@cname = "#{@OpenCName}"
end
@cname = @cname.tr(',',' ')
sys.log("CName: #{@cname}")
return @cname
end
begin
if sys.In
CID = req.Header.From.FromURI.User
CID = "#{$1}" if CID =~ /^1(\d{10})$/ # Remove leading "1"
sys.log("CallerID: #{CID}")
if !(@cname = TNAME[CID]) && CID =~ /^([2-9]\d\d[2-9]\d{6})$/
@cname = getcname CID
end
sys.log("CallerName: #{@cname}")
sys.Dial("user1@local[fu=#{CID},fd=#{@cname}]",30)
else # OUT DIALPLAN STARTS
end
end
Edit:
I re-read your last post and you are always getting number 206.682.0185. 206 is a Washington state number, so you are using IPKall for your callback number. I know in the past IPKall had problems delivering CID on some of their numbers. Maybe this is your problem and not your dialplan. You can get another IPKall number or an IPComms number. If you get another IPKall number choose a different exchange.
To test OpenCnam put the following statement after I strip the country code to set a dummy CID:
CID = "4808370001"
or
cid = "4808370001"
I used lower case cid in my first example and upper case CID in the second. It makes a difference.
azrobert:
I see a fair number of people are reading this thread.
I thought some might want an explanation of the following code:
if !(@cname = TNAME[CID]) && CID =~ /^([2-9]\d\d[2-9]\d{6})$/
@cname = getcname CID
end
TNAME[CID] Does a table lookup on CID
@cname = TNAME[CID]
The result is placed in @cname
If no match the result is null
!(@cname = TNAME[CID])
! is NOT, so this is checking for a null result
&& is AND
CID =~ /^([2-9]\d\d[2-9]\d{6})$/
Checking CID for proper format
If if no result from table lookup and
CID is proper format
The next command is executed
getcname CID
Sub-routine getcname is called
CID is passed to the sub-routine
@cname = getcname CID
The result from the sub-routine is place in @cname
tyeske:
I have tried to put your code into my dial plan, but I must not be putting it in the correct place. Here is my working dial plan. I can dial out and I can receive calls. I'd really like to get the TNAME and OpenCnam working.
Currently with this dial plan, I get the correct incoming phone number sometimes, but other times I get the 206.682.0185 Washington number. I checked and Ipkall doesn't currently have any numbers available. Do you think I should switch to the Ipcomms number?
Thanks for all your help!
# Copyright(c) 2010 Mike Telis
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
# Click "View raw file" in the lower right for the best copy/paste view
AREA_CODE = '763' # my area code
GV_USER = 'XXXXX@gmail.com' # my GV e-mail address (user@gmail.com)
GV_PASS = 'XXXXXXX' # my GV password
CB_NUMBER = '14250000000' # my 11-digit SIP number (only one) Ipkall
SPEED_DIAL = { # my speed dial numbers
'411' => '8003733411', # Free411
'266' => '4153767253@podlinez.com', # CNN Headlines
}
begin
sys.Log "** Call from #{req.Header.From} to #{req.URI.User} **"
if sys.Out # if outbound call
num = req.URI.User.to_s # Get a string copy of the number to dial
num = SPEED_DIAL[num] || num # Substitute with speed dial entry, if any
case num
when /@/ then sys.Dial num # URI dialing
when /^[2-9]\d{6}$/ # Local call, 7-digit number
num = '1'+ AREA_CODE + num # prefix it with country and area code
when /^[01]?([2-9]\d{9})/ # US number with or without country code
num = '1' + $1 # add country code and truncate number to 10-digit
when /^(011|00|\+)(\d{9,})/ # international number
num = '+' + $2 # GoogleVoiceCall works with '+' prefix only
else sys.Respond 603, 'Wrong number, check & dial again'
end
sys.Log "Calling #{num} via Google Voice"
sys.GoogleVoiceCall GV_USER, GV_PASS, CB_NUMBER, num, '.*', CB_NUMBER =~ /^1747/ ? 7 : 1, 30
else # sys.Out
sys.Dial "#{sys.Username}@local"
end
rescue
sys.Log("** Error: " + $!) unless $!.to_s =~ /Thread was being aborted./
end
azrobert:
I have an IPkall and an IPComms DID. I'm happy with both. If you are having CID problems with IPKall and IPComms is the only free DID available, then go for it.
Try this
Code:
AREA_CODE = '763' # my area code
GV_USER = 'XXXXX@gmail.com' # my GV e-mail address (user@gmail.com)
GV_PASS = 'XXXXXXX' # my GV password
CB_NUMBER = '14250000000' # my 11-digit SIP number (only one) Ipkall
SPEED_DIAL = { # my speed dial numbers
'411' => '8003733411', # Free411
'266' => '4153767253@podlinez.com', # CNN Headlines
}
TNAME = {
'2066820185' => 'IPKall',
'4808370002' => 'Work',
'4808370003' => 'Wife',
'4808370004' => 'Mother',
'4808370005' => 'Father',
'4808370006' => 'Girl Friend' }
def getcname cid
@OpenCName ||= sys.WebGet("https://api.opencnam.com/v2/phone/#{cid}?format=text",4)
@OpenCName = "#{req.Header.From.FromName}" if !@OpenCName
if !@OpenCName
@OpenCName = "#{CID}"
@OpenCName.insert(6,"-")
@OpenCName.insert(3,"-")
end
sys.log("CallerName: #{@OpenCName}")
prs = @OpenCName.split(' ')
State = prs[-1]
if City = prs[-2]
@cname = "#{City} #{State}"
else
@cname = "#{@OpenCName}"
end
@cname = @cname.tr(',',' ')
sys.log("CName: #{@cname}")
return @cname
end
begin
sys.Log "** Call from #{req.Header.From} to #{req.URI.User} **"
if sys.Out # if outbound call
num = req.URI.User.to_s # Get a string copy of the number to dial
num = SPEED_DIAL[num] || num # Substitute with speed dial entry, if any
case num
when /@/ then sys.Dial num # URI dialing
when /^[2-9]\d{6}$/ # Local call, 7-digit number
num = '1'+ AREA_CODE + num # prefix it with country and area code
when /^[01]?([2-9]\d{9})/ # US number with or without country code
num = '1' + $1 # add country code and truncate number to 10-digit
when /^(011|00|\+)(\d{9,})/ # international number
num = '+' + $2 # GoogleVoiceCall works with '+' prefix only
else sys.Respond 603, 'Wrong number, check & dial again'
end
sys.Log "Calling #{num} via Google Voice"
sys.GoogleVoiceCall GV_USER, GV_PASS, CB_NUMBER, num, '.*', CB_NUMBER =~ /^1747/ ? 7 : 1, 30
else # sys.Out
CID = req.Header.From.FromURI.User
CID = "#{$1}" if CID =~ /^1(\d{10})$/ # Remove leading "1"
# CID = "xxxxxxxxxx"
sys.log("CallerID: #{CID}")
if !(@cname = TNAME[CID]) && CID =~ /^([2-9]\d\d[2-9]\d{6})$/
@cname = getcname CID
end
sys.log("CallerName: #{@cname}")
sys.Dial("#{sys.Username}@local[fu=#{CID},fd=#{@cname}]",60)
end
rescue
sys.Log("** Error: " + $!) unless $!.to_s =~ /Thread was being aborted./
end
tyeske:
I tried your script and edited my info. I can make outgoing calls, but can't receive and incoming calls. I call from my cell phone and it rings 5 times and goes to VM. Here is the output from the SS console. Can you fix the script?
Monitor 00:58:23:655: basetype=console, ipaddress=*, user=XXXXX, event=*, request=*, serveripaddress=*, server=*, regex=.*.
DialPlan 00:58:40:029 sip1(3216): Using dialplan Working Simple Dial Plan 3-1-14 for In call to sip:XXXXX@sipsorcery.com.
NewCall 00:58:40:045 sip1(3216): Executing script dial plan for call to XXXXX.
DialPlan 00:58:40:092 sip1(3216): ** Call from "unknown" <sip:2066820185@66.54.140.46>;tag=as0a23d929 to XXXXX **
DialPlan 00:58:40:108 sip1(3216): CallerID: 2066820185
DialPlan 00:58:40:108 sip1(3216): WebGet attempting to read from https://api.opencnam.com/v2/phone/2066820185?format=text.
DialPlan 00:58:41:623 sip1(3216): Error in WebGet for https://api.opencnam.com/v2/phone/2066820185?format=text.
DialPlan 00:58:41:639 sip1(3216): CallerName:
DialPlan 00:58:41:639 sip1(3216): ** Error: undefined method `split' for nil:NilClass
DialPlan 00:58:41:639 sip1(3216): Dialplan cleanup for XXXXX.
DialPlan 00:58:41:904 sip1(3216): Dial plan execution completed without answering and with no last failure status.
DialPlan 00:58:41:904 sip1(3216): UAS call failed with a response status of 480.
Registrar 00:59:17:295 sip1(5520): Binding update request for XXXXX@sipsorcery.com from udp:97.116.165.126:5061, expiry requested 120s granted 120s.
RegisterSuccess 00:59:17:310 sip1(5520): Registration successful for XXXXX@sipsorcery.com from udp:97.116.165.126:5061, binding sip:XXXXX@97.116.165.126:5061;expiry=120.
Navigation
[0] Message Index
[#] Next page
[*] Previous page