Alternating GoogleVoice accounts

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

Alternating GoogleVoice accounts

Post by MikeTelis » Sun Sep 13, 2009 4:32 am

Like many others, I'm experiencing problems with sys.GoogleVoiceCall failing to receive callback (to Gizmo5, to Sipgate, to IPKall). The code below is handling these situations by:

1. Randomizing of GV account selection
2. Repeating the call using "next" GV account if current call failed

Here is the code:

Code: Select all

# Google Voice accounts: login, password, callback number, match, phone type, callback tmo

GVaccounts = [
   ['me1@gmail.com','pass1','1747xxxxxxx','.*',7,15],
   ['me2@gmail.com','pass2','1206xxxxxxx','.*',1,10],
]  

def gvcall(num,acnt)
  a = GVaccounts[acnt % GVaccounts.length]           # fetch params
  sys.GoogleVoiceCall(*((a[0,3] << num) + a[3,10]))  # insert number as 4th param
end
Usage example:

Code: Select all

num = req.URI.User.to_s
r = Time.now.to_i
gvcall num,r
gvcall num,r+1
In this example, sys.GoogleVoiceCall will be attempted twice, starting from randomly selected GV account and then proceeding to the next one.

If you have just one Google Voice login/password but several callback numbers (Gizmo5, Sipgate, IPKall), you can do like this:

Code: Select all

GV_email = 'me@gmail.com'
GV_pwd = 'gmailpassword'
GV_num = '408xxxxxxx'

GVaccounts = [
   [GV_email,GV_pwd,'1747xxxxxxx','.*',7],  #callback to Gizmo5
   [GV_email,GV_pwd,'1206xxxxxxx','.*'],    #callback to IPKall
   [GV_email,GV_pwd,'1415xxxxxxx','.*'],    #callback to Sipgate
]
And finally, you can use it like this:

Code: Select all

num = req.URI.User.to_s
r = Time.now.to_i
2.times { |x| gvcall num,r+x }
Ruby really is a powerful language! :)

Update 2009/11/19: Minor changes to accomodate pattern match and new "phone type" parameter.

Update 2009/11/23: Yet another approach to the problem, using Ruby hash to store parameters.

It's been quite a number of changes to sys.GoogleVoiceCall syntax (new parameters, removing old parameters etc) and every change required my attention to the matters. So, I decided to rewrite the code to make it easier to maintain:

Code: Select all

class Hash; alias :+ :merge; end 

MyGV = { :usr   => 'me@gmail.com', 
         :pwd   => 'pass', 
       } 

GVaccounts = [ 
   MyGV + { :cb => '1747xxxxxxx', :type => 'Gizmo', :tmo => 15 }, 
   MyGV + { :cb => '1206yyyyyyy' }, 
]

def gvcall(num,acnt)
  a = {:num => num, :type => 'Home', :tmo => 8, :match => '.*'} # init with num & default values
  a.update(GVaccounts[acnt % GVaccounts.length])                # add other params
  a[:type] = {'Home' => 1, 'Mobile' => 2, 'Work' => 3, 'Gizmo' => 7}[a[:type]] # Encode type
  sys.GoogleVoiceCall *a.values_at(:usr, :pwd, :cb, :num, :match, :type, :tmo)
end
If you need to add a parameter, just insert its name in the GoogleVoiceCall. Removing is done in the same manner, delete corresponding key. If you need to assign default value, just add it to the right side of first statement in gvcall. Note the way I handle :type parameter, this approach can be used for assigning symbolic names to numeric params.

Yet another version of this code is published on page 4 of this thread.
Last edited by MikeTelis on Mon Nov 23, 2009 9:59 am, edited 12 times in total.

davidnewton
Posts: 179
Joined: Thu Aug 27, 2009 3:00 am

Post by davidnewton » Sun Sep 13, 2009 11:59 pm

Thanks for sharing. The problem for me with GoogleVoiceCall is the one-way audio problem, while it shows GoogleVoiceCall executed successfully. In this case, the multi GV do not solve this problem.

ossiemaracay
Posts: 12
Joined: Fri Aug 14, 2009 1:48 pm
Location: Miami, FL USA

Post by ossiemaracay » Mon Sep 14, 2009 6:46 pm

Mike:

I've been using the GV/G5 setup for about a month now but as we all know G5 has become very unstable.

I already signed up for SP and IPKALL and I'm trying to follow your example.

I understand the logic behind your example but I don't have any experience with Ruby.

Could you please post a full outbound dial plan showing where the lines for this command should be inserted?

I'm guessing that I will have to make SS register to all callback services.

What about google voice itself? Do I change the settings to forward all calls to the 3 different callback services at the same time?

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

Post by MikeTelis » Mon Sep 14, 2009 7:27 pm

Full dialplan lives next door: Flexible table-controlled dialplan, optimized for US, GV.

Constant declarations can be placed anywhere in the beginning. The gvcall method - anywhere before "main" (say, right after the "dial" method). Finally, delete googleVoice method completely and replace call to googleVoice in selectVSP method with the following 2 lines:

Code: Select all

r = Time.now.to_i 
2.times { |x| gvcall @num,r+x }

trav
Posts: 120
Joined: Tue Sep 08, 2009 8:34 pm

Post by trav » Mon Sep 21, 2009 8:00 am

is there a way to give out only one CID regardless of the GV account dialed? otherwise your contacts will have to store another number for you...

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

Post by MikeTelis » Mon Sep 21, 2009 8:10 am

For outbound calls, Google Voice always sends your GV number as caller ID. Thus, if you are using the same GV account and just alternating callback methods (thru Gizmo, thru IPKall, thru SIPGate), your callee will always see your GV number. However, if you have more than one GV account, your callee(s) will be getting different GV numbers.

If I had to alternate two or more different GV accounts, I'd use a more sophisticated algorithm than just alternating accounts at random. For example, I'd select an account with GV number in area code (or close to area code) as the number I'm calling and then just alternate different callback routes.

ossiemaracay
Posts: 12
Joined: Fri Aug 14, 2009 1:48 pm
Location: Miami, FL USA

Post by ossiemaracay » Tue Sep 22, 2009 5:48 pm

Mike:

I've tried to "digest" the Flexible Table Plan but is just way beyond my expertise. Even after hours and hours of reading the forums I could not get a lot of progress.

I'm not a programmer or a techie. I'm just trying to implement the "alternating callback providers" feature.

I'm using GVTRICKS' plan which is very plain and simple but nonetheless it works like a charm:

Code: Select all

####################################################
######## OUTBOUND CALL FROM GOOGLE VOICE  ##########
####################################################

#Logic for routing outgoing calls.
sys.Trace = false
case req.URI.User
when /^/
   sys.Log(" Dialing USA #{req.URI.User} through Google Voice service\t")
   sys.Log("*****************************************************\n")
   sys.GoogleVoiceCall("caller@gmail.com","GV_Password","415XXXXX19","#{req.URI.User}","786XXXXX86")
end

I only have 3 callback providers: G5,SP and IPKALL. I don't need this dial plan to make international calls or switch calls or forward calls to any other phone.

I know that my request might sound dumb to all of the experts here but I'm just looking for a little help to make this thing work.

Kind of like a "how to .....for dummies"....

Thanks a lot in advance for all your help.

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

Post by MikeTelis » Tue Sep 22, 2009 8:49 pm

ossiemaracay,

here is your dialplan:

Code: Select all

Area = '408'

# Google Voice accounts: login, password, callback number, match, phone type, callback tmo

GVaccounts = [ 
   ['you@gmail.com','pass','1747xxxxxxx','.*',7,15], 
   ['you@gmail.com','pass','1415XXXXX19','.*',10], 
]

def gvcall(num,acnt)
  a = GVaccounts[acnt % GVaccounts.length]           # fetch params
  sys.GoogleVoiceCall(*((a[0,3] << num) + a[3,10]))  # insert number as 4th param
end

begin
    sys.Log("** Call from #{req.Header.From.to_s} 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

    case num
      when /^[2-9]\d{6}$/         # Local call, 7-digit number
        num = '1'+ Area + num     # prefix it with country and area code
      when /^[01]?([2-9]\d{9})/   # US number with or without "1" country code
        num = '1' + $1            # add country code and truncate number to 10-digit
      else sys.Respond(603,'Wrong number, check & dial again')
    end

    sys.Log("Calling #{num} via Google Voice")
    r = Time.now.to_i
    2.times { |x| gvcall num,r+x }

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

rescue
  sys.Log("** Error: " + $!) unless $!.to_s =~ /Thread was being aborted./
end
Instructions:

1. Enter your home area code on the first line (Area = ...)
2. Enter your GV credentials, callback number and callback matching filter in GVAccounts table
3. Enjoy! :)

Dialing rules:

a) 7-digit numbers are your local numbers. The dialplan will prepend them with "1" country code and "Area" area code.

b) 10-digit numbers will be prepended with "1" country code

c) 11-digit numbers will be dialed "as is". You can use leading "0" (as in collect call) instead of "1"; the dialplan will replace it with "1"

d) "long numbers" (longer than 11 digits, such as 1-800-CITIBANK) will be truncated
Last edited by MikeTelis on Sun Nov 22, 2009 6:12 am, edited 10 times in total.

ossiemaracay
Posts: 12
Joined: Fri Aug 14, 2009 1:48 pm
Location: Miami, FL USA

Post by ossiemaracay » Thu Sep 24, 2009 5:23 pm

Mike:

Thanks so much for your help!!!! I owe you big time......

I will not be able to try out the plan until this coming weekend.

I will definitely let you know if it works out as expected.

I have a 2 part question regarding the alternating callback plan:

- Do I need to forward GV to all 3 callback services: SP, G5 and IPKALL?

-If so, what would happen when there is an incoming call, which one will take the incoming call?

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

Post by MikeTelis » Thu Sep 24, 2009 6:25 pm

You must have all three callback numbers "listed" in your GV account Settings / Phones. However, only one (out of three) should be used as forwarding number for your incoming calls. There is a checkbox next to each number in Settings / Phones, you should check only one out of these three.

Incoming calls will be forwarded to this "checked" number and finally, to your SIP phone(s) registered into Sipsorcery SIP account.

Post Reply