Sunr1ses / google-voice-sipsorcery-dialplans

Automatically exported from code.google.com/p/google-voice-sipsorcery-dialplans
1 stars 0 forks source link

Syntax error in dial plan #43

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.open account on Sip socery and provide 
2.Bind the SIP gate for service provider 
3. copy paste the provided code for dial out plan

What is the expected output? What do you see instead?
expected output to make calls without any error
I see "syntax error" when I call throught x-lite

What version of the product are you using? On what operating system?
Windows XP

Please provide any additional information below:
Area = '205' 
Tz = -6 

GV_USER = "jivaXXXX@gmail.com" 
GV_PASS = "pass"
SG_NUMBER = "415XXXXXXX" 

def googleVoice_SG

sys.GoogleVoiceCall(GV_USER,GV_PASS,SG_NUMBER,@num,'.*',1,30) 

end

VSPtab = {
'0' => '00 @ Sipgate', # SIPGate default route
'2' => '02 @ Sipgate', # SIPGate grey route
'3' => '03 @ Sipgate', # SIPGate white route
'4' => '04 @ Sipgate', # SIPGate premium route
'5' => '@ Sipgate', # sipgate
'6' => '@ Gizmo', # gizmo

}

# Speed dial entries. Format: "short code" => "destination (POTS or SIP)"

Speeddial = {
'0' => '123456789', # my 0 (zero) key's speeddial number
'1' => 'wwwxxxyyyy', # home speed dial
'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' => '7755333366', # Columbus OH-based national weather (932 = "WEA
[ther]") 

}
# --------END OPTIONAL SPEED DIAL ENTRY SECTION---------------# 

# Serviced domains, must be in lowercase!

Domains = ['sipsorcery.com','174.129.236.7']

# 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
]

# ******************** 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 /^4(1?747\d{7})$/ then # Gizmo5 to Gizmo5 calls when Gizmo5 enabled
if G5_NUMBER != "747xxxyyyy"
route(6,"Gizmo5 to Gizmo5 call")
end

else

if SG_NUMBER != "415xxxyyyy" # Place GV call via SIPGate (preferred) or 
Gizmo5
googleVoice_SG
else
googleVoice_G5
end

sys.Log("GoogleVoiceCall failed, routing thru SIPGate")
route(4,"Destination - North America non-GV")
end

when /^972(5|6)/ # Israel mobile
route(3,"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

#==========================================
# Note: this section is important to understand because it lets users 
choose a specific
# SIP Provider for each outbound call. Perfect for users both sipgate and 
G5
# accounts who want to be able to choose which provider to use. Let's 
develop
# this section to make the script portable to both G5 and sipgate users as 
well
# as user with other 3rd party SIP providers

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

Original issue reported on code.google.com by jiva...@gmail.com on 4 Apr 2010 at 5:30

GoogleCodeExporter commented 9 years ago
There are several lines that are split in the code you posted, and its 
difficult for
us to tell if they are wrapped in your SIP Sorcery account. When viewing the 
source
code for copying, always click "view raw file" in the lower right corner of the
source code viewer page. That is a much better page from which to copy the 
code. Look
at your speed dials 677 and 732 for instance.

Syntax error is almost always caused by this.

Original comment by easter...@gmail.com on 4 Apr 2010 at 5:54

GoogleCodeExporter commented 9 years ago

Original comment by easter...@gmail.com on 4 Apr 2010 at 5:57

GoogleCodeExporter commented 9 years ago
could you provide me the correct code ? 

Original comment by jiva...@gmail.com on 4 Apr 2010 at 9:05

GoogleCodeExporter commented 9 years ago
Actually, I can't. I thought you had copied the code from this site, but you 
didn't.
It looks very similar to, but isn't, the ComplexDialPlan found elsewhere on this
site. If you want to keep the code you posted above, just look for the lines 
that
were inadvertently split when you copied them from wherever you got them.

Original comment by easter...@gmail.com on 5 Apr 2010 at 1:20

GoogleCodeExporter commented 9 years ago
Don't forget that the "Syntax error" message contains line number, too. When 
you're 
looking for accidentally wrapped line of code, the line number helps a lot! ;-)

Original comment by mte...@gmail.com on 5 Apr 2010 at 8:53

GoogleCodeExporter commented 9 years ago
True, but also remember its the line of the *first* error. Once you find the 
type of
error at that line, look at the rest of the script for similar errors. It will 
save
you a ton of trouble vs troubleshooting one error at a time, assuming you are
experiencing line wrap errors.

Original comment by easter...@gmail.com on 5 Apr 2010 at 8:57

GoogleCodeExporter commented 9 years ago
I traced the call but didnt see any line number for syntex error. I have 
attached 
the code in file. Please have a look

Appreciate your help ! 

Original comment by jiva...@gmail.com on 12 Apr 2010 at 6:29

GoogleCodeExporter commented 9 years ago
SIP trace is absolutely useless. You need to go to Console, click on "Connect" 
in there 
and then try making a call. Select whatever output you get with your mouse and 
click 
Ctrl-C to copy. Then you can paste it into notepad, remove all sensitive 
information 
(like phone number, SIP account name etc) and post the result here.

Original comment by mte...@gmail.com on 12 Apr 2010 at 7:50

GoogleCodeExporter commented 9 years ago
I got the trace from the console and it says there is an error on line number 
131. 
could you help me in figuring out what is the error ? please see the attached 
trace.

Original comment by jiva...@gmail.com on 14 Apr 2010 at 4:34

Attachments:

GoogleCodeExporter commented 9 years ago
Line #131 is this:

# this section to make the script portable to both G5 and sipgate users as 
well

As you can see, it's a wrapping problem ("well" wrapped on a new line resulting 
in 
syntax error). I guess this is not the only place where wrapping occurred.

Original comment by mte...@gmail.com on 14 Apr 2010 at 7:29

GoogleCodeExporter commented 9 years ago
Closing due to inactivity. User was advised to make sure lines do not wrap when 
copying and pasting dialplans.

Original comment by easter...@gmail.com on 8 Feb 2011 at 2:30