Dial Plan to let us dial out from 2 different GV numbers

Catalog of dial plans
Post Reply
Maestro232
Posts: 2
Joined: Sat Jul 03, 2010 1:43 am

Dial Plan to let us dial out from 2 different GV numbers

Post by Maestro232 » Sat Jul 03, 2010 1:53 am

Hello,

I am happy to have a setup at home using an ATA and analogue phone receiving incoming and outgoing calls via GV + SipSorcery + Sipgate. I used the excellent dialplan below, but my wife and I each have our own GV accounts and when dialing out from our ATA would like to easily indicate which GV account to dial VIA our SipSorcery dialplan. I am thinking of just pre-pending the dialout number with a "*" for all my GV account and a "#" for hers...or something simple like that. But I confess that I'm not too savvy with code. Could someone explain how I could modify the dialplan below? Thank you...

Code: Select all

# 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 = '413'                  # my area code
GV_USER   = 'me@gmail.com'  # my GV e-mail address (user@gmail.com)
GV_PASS   = 'mepass'             # my GV password
CB_NUMBER = '1415707XXXX'          # my 11-digit SIP number (only one)

SPEED_DIAL = {                    # my speed dial numbers
 '1'   => '12345678910',          # Franky

}

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{10,})/ # 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

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

Re: Dial Plan to let us dial out from 2 different GV numbers

Post by MikeTelis » Sat Jul 03, 2010 8:50 am

The latest version of so-called "Complex Dial Plan" allows you to describe and use several GV accounts. However, I'd rather recommend to address this problem at ATA / VoIP phone level. There are many models with 2 FXS ports (Linksys PAP2T, Linksys SPA2102); many VoIP telephones allow to use several accounts and switch between them with either prefix or dedicated buttons.

You'll have to create a separate Sipsorcery account (or yet another SIP account under your SS username) for your wife and link it to a dialplan with her GV credentials.

Maestro232
Posts: 2
Joined: Sat Jul 03, 2010 1:43 am

Re: Dial Plan to let us dial out from 2 different GV numbers

Post by Maestro232 » Sat Jul 03, 2010 11:14 am

Thank you for your advice. I do have the PAP2T, but I wasn't interested in purchasing a second analog phone at this point. However, I do plan to get a nice PMP for myself soon, so maybe I'll do as you suggest and set up a second account, and just have our home phone use my wife's credentials and my PMP use mine.

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

Re: Dial Plan to let us dial out from 2 different GV numbers

Post by MikeTelis » Wed Jul 14, 2010 9:26 pm

Version 2 of my flexible dialplan can do exactly what you need: select Google Voice account by a prefix. I'd recommend that you select one of GV accounts (either your or your wife's) by default and use a prefix to select the other.

touta98
Posts: 4
Joined: Fri Jul 30, 2010 6:52 pm

Re: Dial Plan to let us dial out from 2 different GV numbers

Post by touta98 » Fri Jul 30, 2010 7:22 pm

MikeTelis wrote:The latest version of so-called "Complex Dial Plan" allows you to describe and use several GV accounts. However, I'd rather recommend to address this problem at ATA / VoIP phone level. There are many models with 2 FXS ports (Linksys PAP2T, Linksys SPA2102); many VoIP telephones allow to use several accounts and switch between them with either prefix or dedicated buttons.

You'll have to create a separate Sipsorcery account (or yet another SIP account under your SS username) for your wife and link it to a dialplan with her GV credentials.
Mike,
I have two GV accounts. I'm using one for my cell phone with fring.
I wanted to use the second one with ATA at home.

I used GV, SG, SS, simple dial plan and fring for my cell phone and worked without an issue.
Later I added subaccount on SS. I repeated the same steps with two dial plans, one attached to my cell phone account and the other to my ata. I also used two different SG numbers.

Outbound calls worked fine from my ata but Incoming calls for the second account goes to my cell phone insted of my ata.
Am I doing something wrong?

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

Re: Dial Plan to let us dial out from 2 different GV numbers

Post by MikeTelis » Fri Jul 30, 2010 7:36 pm

Yes! You need to use different "Register Contact" for your Sipgate account associated with the other GV. The "User" part of the contact (before '@') should be pointing to your "subaccount" (aka SIP account).

touta98
Posts: 4
Joined: Fri Jul 30, 2010 6:52 pm

Re: Dial Plan to let us dial out from 2 different GV numbers

Post by touta98 » Fri Jul 30, 2010 8:07 pm

MikeTelis wrote:Yes! You need to use different "Register Contact" for your Sipgate account associated with the other GV. The "User" part of the contact (before '@') should be pointing to your "subaccount" (aka SIP account).
I have done that already
sip:334xxxxxxx@sipsorcery.com
sip:717xxxxxxx@sipsorcery.com (primary)

Do I need to change anything in the dial plan other the GV info and SG number?

touta98
Posts: 4
Joined: Fri Jul 30, 2010 6:52 pm

Re: Dial Plan to let us dial out from 2 different GV numbers

Post by touta98 » Fri Jul 30, 2010 8:12 pm

touta98 wrote:
MikeTelis wrote:Yes! You need to use different "Register Contact" for your Sipgate account associated with the other GV. The "User" part of the contact (before '@') should be pointing to your "subaccount" (aka SIP account).
I have done that already
sip:334xxxxxxx@sipsorcery.com
sip:717xxxxxxx@sipsorcery.com (primary)

Do I need to change anything in the dial plan other the GV info and SG number?

Do I need to change this line?

else # sys.Out
sys.Dial "#{sys.Username}@local"

touta98
Posts: 4
Joined: Fri Jul 30, 2010 6:52 pm

Re: Dial Plan to let us dial out from 2 different GV numbers

Post by touta98 » Fri Jul 30, 2010 9:19 pm

I figured it out.
I changed sys.Dial "#{sys.Username}@local"
to sys.Dial "334xxxxxxx@local"

It worked.
Thanks.

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

Re: Dial Plan to let us dial out from 2 different GV numbers

Post by MikeTelis » Sat Jul 31, 2010 1:52 am

You're welcome! Yep, I forgot about the sys.Username thing... have been using the following code:

Code: Select all

    prs = req.URI.User.split('.')  # parse User into chunks
    @trunk = prs[-2]               # get trunk name
    @user  = prs[-1]               # called user name
for too long to remember about it. The code extracts SIP account name (suffix) into @user and prefix -> @trunk. Then I forward the call to the bindings (phone(s) registered to that SIP account) with:

sys.Dial("#{user}@local")

If you don't use prefixes, you can just replace sys.Username with req.URI.User.

Post Reply