Just installed the local version & cant get GV to work.

Discussions about using SIP Sorcery on your own computer/server
MikeTelis
Posts: 1581
Joined: Wed Jul 30, 2008 6:48 am

Post by MikeTelis » Wed Jan 06, 2010 9:22 pm

Hmm, I would understand why Int worked with Home/Work/Mobile but Gizmo is certainly different. One of my callback numbers is Gizmo and passing type 7 (Integer) with this number certainly works (checked a few minutes ago). So, either actual code running on Sipsorcery is different from codeplex or Google ignores phone type overall.

jaminmc
Posts: 22
Joined: Tue Oct 13, 2009 8:24 pm

Post by jaminmc » Wed Jan 06, 2010 10:30 pm

Woohoo!!!! It is all working!!!!! Sipgate was working, but not gizmo. Turns out the gizmo number needs a + in front of it. Then gizmo worked too. I have a alabrate diaplan. one that routes through voipstunt when I make a international call... So here is the meat of the plan... @num is the number that is called after all the processing.... I just threw in the @num = req.URI.User.to_s to make this functional for someone else without using my whole dialplan :)

Code: Select all

GV_USER = "xxxx@gmail.com"            # my GV e-mail address (user@gmail.com)
GV_PASS = "xxxxxx"                           # my GV password
SIPGATE_NUMBER = "1704xxxxxxx"     # my 10-digit Sipgate number
GIZMO5_NUMBER = "+1747xxxxxxx"   # my Gizmo Number
GV_NUMBER= "818xxxxxxx"                # my Google Voice number
@num = req.URI.User.to_s

def googleVoiceG5
  sys.Log("Trying Google Voice Gizmo5 \t")
  sys.GoogleVoiceCall(GV_USER,GV_PASS, GIZMO5_NUMBER,@num, GV_NUMBER,"7")
end

def googleVoiceSip
  sys.Log("Trying Google Voice sipgate \t")
  sys.GoogleVoiceCall(GV_USER,GV_PASS, SIPGATE_NUMBER,@num, GV_NUMBER,"3")
end

  case @num
    when /^1([2-9]\d\d)/                 # North America
      case $1                                  # check area code

# sipgate-to-US toll-free are no cost
# the following line will cause such calls to be made directly via sipgate, bypassing Google Voice 

         when /(800|866|877|888)/    # US toll-free and sipgate-to-sipgate calls
          sys.Dial("${@num}@sipgate") 

        else
          googleVoiceG5
          googleVoiceSip
        end

jainpj
Posts: 173
Joined: Tue Dec 30, 2008 10:13 am

Post by jainpj » Thu Jan 07, 2010 8:41 am

MikeTelis wrote:Hmm, I would understand why Int worked with Home/Work/Mobile but Gizmo is certainly different. One of my callback numbers is Gizmo and passing type 7 (Integer) with this number certainly works (checked a few minutes ago). So, either actual code running on Sipsorcery is different from codeplex or Google ignores phone type overall.
The source at codeplex defines phone type as integer and hence I would assume that you need to pass in an integer at sipsorcery.com. But the patch is defining the phone type as string and hence you will need to pass phone type as a string on the local version with the patch.

When you say, you checked few minutes ago, did you mean on the local version with the patch or on sipsorcery.com
jaminmc wrote:Woohoo!!!! It is all working!!!!! Sipgate was working, but not gizmo. Turns out the gizmo number needs a + in front of it. Then gizmo worked too.
I am glad its working now and thanks for the tip of placing + for gizmo. However I think Gizmo callback is not working at the moment for me. May be they are changing some thing again.

jaminmc
Posts: 22
Joined: Tue Oct 13, 2009 8:24 pm

Post by jaminmc » Thu Jan 07, 2010 9:13 pm

I got it to work on the local version. and my dialplan is similar to the one posted before....

Here is my actual Dialplan.

Code: Select all

#============================= BEGIN CODE ======================================#

#Ruby
# Note: This is the Gizmo and Sipgate script. 
# I have it set to use the Gizmo first, if that one fails, it will use sipgate.

# --------BEGIN MANDATORY ENTRIES SECTION---------------------------------------#                     

Area = '803'          # my area code, this will be added to 7-digit dialouts 
Tz   = -5             # my time zone (GMT format, e.g. Central = -6)

# ---- Enter your Google Voice ("GV") and Sipgate account credentials----#

GV_USER = "xxxx@gmail.com"            # my GV e-mail address (user@gmail.com)
GV_PASS = "xxxx"                  # my GV password
SIPGATE_NUMBER = "1704xxxxxxx"          # my 10-digit Sipgate number
GIZMO5_NUMBER = "+1747xxxxxxx"
GV_NUMBER= "818xxxxxxx"

# --------END MANDATORY ENTRIES SECTION-----------------------------------------#                     


# --------BEGIN OPTIONAL SECTION FOR SPEED DIAL---------------------------------#                     
# Speed dial entries. Format: "short code" => "destination (POTS or SIP)"


Speeddial = {
  '411' => '8004664411',               # Google's Directory Assistance, GOOG-411
  '303' => '303@sip.blueface.ie',      # Blueface speaking clock (Ireland time)
  '266' => '4153767253@podlinez.net',  # CNN Headlines (266 = "CNN")
  '677' => '8186882773@podlinez.net',  # NPR's most e-mailed stories (677 ="NPR")                     
  '742' => '6506441934@podlinez.net',  # Prairie Home Companion's, or PHC's 
                                       # News from Lake Wobegon (742 = "PHC")
  '932' => '8009328437',               # 800-WEATHERCALL (9328437 = "WEA[ther]")                    
  '369' => '2129040080@podlinez.net',  # "FOX" Radio News
  '2455' => '6414539074@podlinez.net', # "BILL" Johnson podcast
}
# --------END OPTIONAL SPEED DIAL ENTRY SECTION---------------------------------#                     

  
# Serviced domains, must be in lowercase!

Domains  = ['My Local.homeip.net',"192.168.1.103",'xx.10.179.xx','sipgate.com','sip.sipgate.com'] #put sipgate in there so if I redial from my softphone, it will go through...

# Excluded Prefixes. Provides a safeguard against accidentally calling premium
# numbers. Accepts both strings and patterns, spaces ignored

ExcludedPrefixes = [
   ' 1 (900 | 976 | 809)',            # USA Premium
   '44 (9 | 55 | 87 (0|1))',          # UK Premium
   '44 84 (4|5)',                     # UK Local Premium
   '44 70',                           # UK Personal Premium
   '43 (8|9)',                        # Austria Premium
   '32 (7|90)',                       # Belgium Premium
   '45 (1 | 50 (1|2|3) | 70 (1|2))',  # Denmark Premium
   '45 (8|9) 0',                      # Denmark Premium (...)
   '33 (7|9)',                        # France Premium
   '49 (1 | 900)',                    # Germany Premium
   '39 [^3]',                         # Italy Premium (...)
   '31 (14 | 6 (3|8|9) | 8 | 9)',     # Netherlands Premium (...)
   '48 (39 | (2|7|8) 0)',             # Poland Premium
   '46 9 (00 | 39 | 44)',             # Sweden Premium
   '41 90 (0|1|6)',                   # Switzerland Premium
]

# Providers: "key" => "template". Template format: prefix@Provider

VSPtab = {
  '0' => '@ voipstunt',                # Future-nine default route
  '2' => '@ voipstunt',                # Future-nine grey route
  '3' => '@ voipstunt',                # Future-nine white route
  '4' => '@ voipstunt',                # Future-nine premium route
  '5' => '@ sipgate',              # sipgate
}

# ********************  G o o g l e V o i c e  *****************************
# !!!!!!!!!!!!    Make sure to enter your credentials below    !!!!!!!!!!!!!
# Note: enter the middle line on one line. My comments wrapped it to the second line
# Note 2: The "@num" in the parameter list is the only parameter that is not surrounded by
# single quotes

def googleVoiceSip
  sys.Log("Trying Google Voice sipgate \t")
  sys.GoogleVoiceCall(GV_USER,GV_PASS, SIPGATE_NUMBER,@num, GV_NUMBER,"3")
end

def googleVoiceG5
  sys.Log("Trying Google Voice Gizmo5 \t")
  sys.GoogleVoiceCall(GV_USER,GV_PASS, GIZMO5_NUMBER,@num, GV_NUMBER,"7")
end

# ********************  s e l e c t   V S P  *******************************

def selectVSP    # VoIP provider selection

  # Reject calls to premium numbers unless VSP was forced

  ExcludedPrefixes.each {|p| p.gsub!(/\s*/,''); sys.Respond(503,"Calls to #{$1}* not allowed") if @num =~ Regexp.new("^(#{p})")}

  case @num
    when /^1([2-9]\d\d)/                 # North America
      case $1                                  # check area code
#        when "808", "907", "867"        # AK, HI, Canada Yukon calls are now free with GV
#          route(4,"Destination - Alaska, Hawaii, Yukon")

# sipgate-to-sipgate and sipgate-to-US toll-free are no cost
# the following line will cause such calls to be made directly via sipgate, bypassing Google Voice 

         when /(800|866|877|888)/    # US toll-free and sipgate-to-sipgate calls
          route(5,"Destination - US toll-free or sipgate")
sys.Log("Destination - US toll-free or sipgate\t")

        else
          googleVoiceG5
          googleVoiceSip
          sys.Log("GoogleVoiceCall failed, routing thru F9") 
        #  route(0,"Destination - North America")
        end
    when /^972(5|6)/                    # Israel mobile
      route(0,"Destination - Israel mobile")
    else
      route(0,"Default route applied")
  end
end

# **************************  C A L L    S W I T C H  **********************

def callswitch(num,*args)
  route                 # Initialize vars

  @num = num unless @num = Speeddial[num]     # If there is speed dial entry for it...

  @l = "URI dialing: #{@num}" # Assume URI dialing
  unless @num =~ /@/          # If we already have URI, skip all number processing
    @num.gsub!(/%(..)/) {$1.to_i(16).chr} # Convert %hh into ASCII

    if @num =~ /^#(.)(.*)/    # If number starts with '#'
      @p = $1; @num = $2      # next char is VSP code
    end

    @num.gsub!(/[^0-9*+]/,'') # Delete all fancy chars (only digits, '+' and '*' allowed)

    # sub! below removes prefixes:
    #  '+' - international format
    #   00 - European style international prefix (00)
    #  011 - US style international prefix (011)

    unless @num.sub!(/^(\+|00|011)/,'')  # If no international prefix, process special cases below
      case @num
        when /^[2-9]\d{6,6}$/       # Local call, 7-digit number
          @num = "1#{Area}#{@num}"  # prefix it with country and area code
        when /^[01]?([2-9]\d{9,9})/ # US number with or without "1" country code
          @num = '1' + $1           # add country code and truncate number to 10-digit
        when /^\*/                  # Voxalot voicemail, echotest & other special numbers
          else
            sys.Respond(603,'Wrong number, check & dial again')
      end
    end

    sys.Log("Number in ENUM format: #{@num}")

    @l = "Forced routing to provider #{@p}, template '#{VSPtab[@p]}'" # Assume user explicitly selected VSP

    if @p.empty?        # Automatic VSP selection?

      # Invoke selectVSP prior to ENUM lookup just in case we need to modify @num

      route                 # re-initialize variables
      selectVSP             # Pick appropriate provider for the call

      if enumuri = sys.ENUMLookup("+#{@num}.e164.org") # Check if NAPTR exists for the number
        sys.Log("ENUM entry found: '#{enumuri}'")      # If yes, call that URI
        sys.Dial(enumuri)                              # if call failed, call via regular VSP.
        status()                                       # If this is not what you want, add "return"
        sys.Log("Call to #{enumuri} failed (#{@reason}), will call again via regular VoIP provider")
      end

    end # @p.empty
  end   # URI

  dial(*args)   # dial selected number or URI
end

# *******************************  D I A L  ********************************

def dial(*args)
  sys.Log(@l) unless @l.empty?               # for the record :)
  if tpl=VSPtab[@p.to_s]                     # if provider is in our table
    tpl.gsub!(/\s*/,'')                      # Remove spaces
    @num = tpl.gsub(/@/,@num+'@')            # Insert number before '@'
  end
  sys.Dial(@num,*args) # Dial
  status()             # We shouldn't be here! Get error code...
  sys.Log("Call failed: code #{@code}, #{@reason}")
end

# ******************************  R O U T E  *******************************

def route(p='', l='')
  @p = p; @l = l
end

# *****************************  S T A T U S  ******************************

def status
  if (ptr = sys.LastDialled[0]).nil?
    @code = 487; @reason = 'Cancelled by Sipsorcery'
  else
    ptr = ptr.TransactionFinalResponse
    @code = ptr.StatusCode; @reason = ptr.ReasonPhrase
#   sys.Log("#{ptr.ToString()}")
  end
end

# *******************************  M A I N  *****************************
begin
  sys.Log("** Call from #{req.Header.From.ToString()} to #{req.URI.User} **")

  t = Time.now + ((Tz+8)*60*60)  # Get current time and adjust to local. SS Server is in GMT-8
  sys.Log(t.strftime('Local time: %c'))

if sys.In               # If incoming call...
    name = req.Header.from.FromURI.User.to_s     # get a copy of caller's number

    # Prefix 10-digit numbers with "1" (US country code).
    # Some DID send Caller ID without country code

    name = ('1' + name) if name =~ /^[2-9]\d\d[2-9]\d{6}$/

    name.sub!(/^011/,'') # Remove 011 prefix added by Google Voice

    sys.Log("FromName: '#{name}'")
    req.Header.From.FromName = name    # Set FromName for sys.Dial
    # Change FromURI.User, too - or else Bria won't find contact in its phonebook!
    req.Header.from.FromURI.User = name

#    if sys.IsAvailable()                  # If my ATA is registered
      callswitch("#{sys.Username}@local") # forward all incoming calls to it
#    elsif (8..23) === t.hour              # else forward calls to my home
#      sys.Log("#{sys.Username} is not online, forwarding call to home number...")
 #     callswitch("0",35)                  # Note that '0' is in my speed dial list
 #   end

    sys.Respond(480, "#{sys.Username} Not online") # switch to voice mail

  else                    # Outbound call ...

    # check if it's URI or phone number.
    # If destination's host is in our domain, it's a phone call

    num = req.URI.User.to_s; reqHost = req.URI.Host.to_s  # Get User and Host
    host = reqHost.downcase.slice(/[^:]+/)                # Convert to lowercase and delete optional ":port"

    num << '@' << reqHost unless Domains.find {|x| x == host} # URI dialing unless host is in our domain list

    callswitch(num)

  end
  sys.Respond(@code,@reason) # Forward error code to ATA
rescue
   # Gives a lot more details at what went wrong (borrowed from Myatus' dialplan)
   sys.Log("** Error: " + $!) unless $!.to_s =~ /Thread was being aborted./
end

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest