My Basic Working G5/GV Dialplan

Catalog of dial plans
Post Reply
mel2000
Posts: 184
Joined: Fri Jun 05, 2009 11:27 pm

My Basic Working G5/GV Dialplan

Post by mel2000 » Tue Aug 18, 2009 4:42 am

My dialplan was inspired by various contributors from this board and some online regexp tutorials. It is a basic Inbound/Outbound combo that ensures that only valid USA 11, 10, and 7 digit telephone numbers and no pay-per-call numbers get outbound to G5/GV. It does not accommodate entering SIP call numbers.

It can be modified to append the area code of your choice to the 7 digit number. It can also be modified to make the x11 dialing substitutions of your choice. Appropriate modifications must also be made to the GoogleVoiceCall() parameters to suit your account. I allowed a free gateway to make toll-free calls when possible to avoid the GV callback delay.

**Edited to incorporate the "fromUserToMatch" parameter within the sys.GoogleVoiceCall() to add flexibility to use it with various providers.

**Edited to incorporate the "phone type parameter for sys.GoogleVoiceCall().

Code: Select all

#Ruby - Default (works)
# Dial Plan Generated by Rubyzard v0.1 
# If you need help, please post in our forum
# http://www.mysipswitch.com 

begin
# SIP tracing : true or false 
sys.Trace = false 
sys.Log("call from #{req.Header.From.FromURI.ToString()} to #{req.URI.User}.")

if sys.In then
 # Do your INCOMING call processing customisations here.
   if sys.IsAvailable() 
     sys.Dial("#{sys.Username}@local",30)
   else
     sys.Respond(480, "#{sys.Username} Not available")
   end

else
 # Do your OUTGOING call processing customisations here.
  GV_email = "xxxxxx@domain.com"
  GV_pwd = "******"
  SIPnum = "1747xxxxxxx"
  ac = "773"       # area code
  pt = 7   # phone type (1=Home, 2=Mobile (default), 3=Work, 7=Gizmo)

  case req.URI.User
    when /^1?(50001|9000)$/ then sys.Dial("#{GV_nbr}@Future-Nine")   # GV Voicemail
    when /^1?(976|900|809)\d{7}$/
      sys.Log("Calls to #{req.URI.User} not allowed")
      sys.Respond(488, "Call not allowed")
    when /^1?((888|877|866|800)\d{7})$/ then sys.Dial("1#{$1}@sip.tollfreegateway.com")   # use free gateway
    when /^411$/ then sys.Dial("18004664411@sip.tollfreegateway.com")   # use free gateway
    when /^1?([2-9]\d{2}[2-9]\d{6})$/ then sys.GoogleVoiceCall(GV_email,GV_pwd,SIPnum,"1#{$1}",".*",pt)   # 10 or 11 digits
    when /^([2-9]\d{6})$/ then sys.GoogleVoiceCall(GV_email,GV_pwd,SIPnum,"1#{ac}#{$1}",".*",pt)   # 7 digits
    when /^311$/ then sys.GoogleVoiceCall(GV_email,GV_pwd,SIPnum,"13127445000",".*",pt)      
  else
    sys.Log("#{req.URI.User} is an invalid number")
    sys.Respond(603,'Wrong number, check & dial again')
  end

end
rescue 
   sys.Log("** Error: " + $!) unless $!.to_s =~ /Thread was being aborted./ 
end
Last edited by mel2000 on Sun Nov 22, 2009 12:22 pm, edited 12 times in total.

sirmikey1
Posts: 157
Joined: Mon May 25, 2009 11:19 pm

Post by sirmikey1 » Wed Aug 19, 2009 11:02 am

Mel,

Hello and thanks for posting this.

The Google Voice call strings are new to me, will be very useful.

With your toll free gizmo calling, I had been using

Code: Select all

sys.Dial("${dst}@gizmo5") 
Is this below authenticating and/or securing the call?

Code: Select all

sys.Dial("1#{req.URI.User.to_str[0,10]}@Gizmo5")
Thanks in Advance,
Mikey

mel2000
Posts: 184
Joined: Fri Jun 05, 2009 11:27 pm

Post by mel2000 » Wed Aug 19, 2009 1:43 pm

sirmikey1 wrote:With your toll free gizmo calling, I had been using

Code: Select all

sys.Dial("${dst}@gizmo5") 
Is this below authenticating and/or securing the call?

Code: Select all

sys.Dial("1#{req.URI.User.to_str[0,10]}@Gizmo5")
No authenticating. My code truncates any garbage characters beyond the first 11, 10, or 7 digits (since my WiFi phone occasionally appends garbage characters at the end of a stored number). In the case above, the tested Toll-free number was not preceded by a 1 so I prepended a 1 to it and grabbed the next 10 digits of the number to ensure that it had exactly 11 digits, so no garbage characters, if any, would make their way into the dialed call.

sirmikey1
Posts: 157
Joined: Mon May 25, 2009 11:19 pm

Post by sirmikey1 » Wed Aug 19, 2009 2:01 pm

Mel,
I was curious about the

Code: Select all

req.URI.User.to_str

in the previous post. No authentication,
is this for caller ID or something?
Plz and Thks,
Mikey

mel2000
Posts: 184
Joined: Fri Jun 05, 2009 11:27 pm

Post by mel2000 » Wed Aug 19, 2009 3:51 pm

In order to extract a [0,10] substring of the array, req.URI.User, I had to convert it to a string first.

sirmikey1
Posts: 157
Joined: Mon May 25, 2009 11:19 pm

Post by sirmikey1 » Thu Aug 20, 2009 10:41 am

Mel,
Have you considered creating a speed-dial for GV? Just that it might become useful if you swap to another default VSP.
Mikey

mel2000
Posts: 184
Joined: Fri Jun 05, 2009 11:27 pm

Post by mel2000 » Thu Aug 20, 2009 11:59 am

No, I really don't use SpeedDials at all. I've already created alternative dialplans for switching to another provider.

sirmikey1
Posts: 157
Joined: Mon May 25, 2009 11:19 pm

Post by sirmikey1 » Fri Aug 21, 2009 3:53 pm

How-to Enable SIP Support with Google Voice [Tutorial]
http://truvoipbuzz.com/2009/08/how-to-e ... -tutorial/

Post Reply