- All calls must be dialed in international format with e leading '+' or '00'. For example: 00883510000000091.
- There are provision up to ten Voice Service Providers (VSP), each one named from 'VSP_0' to 'VSP_9'.
- To dial through a specific VSP, the dialing sequence is: <VSP number> * <phone number in e164 format>. For example, to dial +552112345678 through VSP_3 the dialing sequence is as follows: 3*552112345678.
- To change the default VSP, the dialing sequence is: <VSP number> *. For example, to change the default VSP to VSP_3 the dialing sequence is: 3*.
- Authorized numbers from a specific provider can trigger a callback response from my sip phone.
The code is as follows:
Code: Select all
##########################################################
# Speed dial numbers in e164 or URL format #
##########################################################
SPEED_DIAL = { #
"3246" => "+883510000000091", # iNum echo test
"8378" => "music@iptel.org", # Fado de Anamar
} #
##########################################################
CNAM = { #
"+5521xxxxxxxx" => "<name>", #
"+351xxxxxxxxx" => "<name>", #
} #
##########################################################
AUTH = { #
"00351xxxxxxxxx" => "Callback", #
} #
##########################################################
SIPACC = "<in only sip account>" # Callback SIP account
UserID = "<user id number>" # User ID definition
MailTO = "<e-mail for notifications>" # E-mail definition
##########################################################
@time = System::DateTime.UtcNow.AddMinutes(sys.GetTimezoneOffsetMinutes()).to_s
sys.SetFromHeader("#{req.Header.From.FromName}", nil, nil)
def prefix
case @vsp
when "VSP_0" then @prefix = ""
when "VSP_1" then @prefix = "+"
when "VSP_2" then @prefix = "+"
when "VSP_3" then @prefix = "00"
when "VSP_4" then @prefix = "+"
when "VSP_5" then @prefix = "+"
when "VSP_6" then @prefix = "+"
when "VSP_7" then @prefix = "+"
when "VSP_8" then @prefix = "+"
when "VSP_9" then @prefix = "+"
end
end
def dialvsp
prefix
@num = @prefix + @num if @num =~ /^[1-9]/
@url = "#{@num}@#{@vsp}"
sys.Dial(@url)
end
def dialout
@url = SPEED_DIAL[@num]
if @url =~ /\@/
if not @url =~ /\@VSP_\d$/
@url = "#{@url}[fd=#{"+" + UserID},fu=#{"00" + UserID}]"
end
sys.Dial(@url)
else
@num = @url if @url =~ /^(\+|00)/
end
case @num
when /^\d\*/
@vsp = "VSP_#{@num[0]-48}"
if @num =~ /^\d\*$/
@text = "Default provider set to #{@vsp}"
sys.Email(MailTO,"SIPsorcery","#{@text}.")
sys.DBWrite("VSP",@vsp)
sys.Respond(487,@text)
else
@num.sub! (/^\d\*/,"")
dialvsp
end
when /^(\*9524|[1-9]|[a-z]|[A-Z])/
@num.sub! (/^\*9524/,"")
@url = "#{@num}@local[fd=#{"+" + UserID},fu=#{"00" + UserID}]"
sys.Dial(@url)
when /^(\*|\+|00)/
@num.sub! (/^(\+|00)/,"")
if @num =~ /^\*\d/
@url = "#{@num}@sipbroker.com[fd=#{"+" + UserID},fu=#{"00" + UserID}]"
sys.Dial(@url)
else
@url = sys.ENUMLookup("#{@num}.e164.org")
@url = sys.ENUMLookup("#{@num}.e164.arpa") if not @url =~ /\@/
if @url =~ /\@/
@url = "#{@url}[fd=#{"+" + UserID},fu=#{"00" + UserID}]"
sys.Dial(@url)
end
end
@vsp = sys.DBRead("VSP")
dialvsp
end
sys.Respond(404,"User not found")
end
if sys.In
@cid = req.Header.From.FromURI.User.to_s
@cnam = req.Header.From.FromName.to_s
@cid.sub! (/^55(000|00|0)/,"")
@cnam.sub! (/^00/,"+")
if @cid =~ /^0[1-9]/ or @cid =~ /^[1-9]\d([2-9]\d{7}|9\d{8})$/
@cid.sub! (/^0/,"")
@cnam = "+55" + @cid if @cnam =~ /^\d/ or @cnam == ""
@cid = "0055" + @cid
else
if @cid =~ /^[1-9]/
@cnam = "+" + @cid if @cnam =~ /^\d/ or @cnam == ""
@cid = "00" + @cid
else
@cnam = @cid if @cnam=~ /^\d/ or @cnam == ""
end
end
@cnam = CNAM[@cnam] if not CNAM[@cnam] == nil
if AUTH[@cid] == "Callback" and req.URI.User =~/^#{SIPACC}$/
@vsp = sys.DBRead("VSP")
prefix
@text = "Callback authorized to #{@cnam} <#{@cid}> at #{@time}"
@url1 = "1021@local[fd=#{@cnam},fu=#{"WebCallBack"}]"
@url2 = @prefix + "#{@cid[2..-1]}@#{@vsp}"
sys.Email(MailTO,"SIPSorcery","#{@text}.")
sys.Callback(@url1,@url2,5)
else
@url = "1021@local[fd=#{@cnam},fu=#{@cid}]&1022@local[fd=#{@cnam},fu=#{@cid}]"
if sys.Dial(@url,60).to_s == "Redirect"
@text = "Call redirected from #{@cnam} <#{@cid}> at #{@time}"
sys.Email(MailTO,"SIPSorcery","#{@text}.")
@num = sys.RedirectURI.User.to_s
dialout
else
@text = "Call not attended from #{@cnam} <#{@cid}> at #{@time}"
sys.Email(MailTO,"SIPSorcery","#{@text}.")
end
end
else
@num = req.URI.User.to_s
dialout
end