Dialplan to dial SIP URI?
Dialplan to dial SIP URI?
What's the best (RUBY) way to support outgoing SIP URI directly?
So far I have this to dial SIP directly
sys.Dial("#{req.URI.User}@#{req.URI.Host}")
but how to determine PSTN format also?
So far I have this to dial SIP directly
sys.Dial("#{req.URI.User}@#{req.URI.Host}")
but how to determine PSTN format also?
You can distinguish between URI and PSTN dialing by Host. If Host is one of Sipsorcery (MySIPswitch) domain names, it's PSTN.
Related code:
Please refer to complete dialplan.
Related code:
Code: Select all
# 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
thanks!
Thanks, that explains the behavior!
Code: Select all
# Do your OUTGOING call processing customisations here.
if "#{req.URI.host}" == "sipsorcery.com" then
sys.Dial("voipuser")
else
sys.Dial("#{req.URI.User}@" << "#{req.URI.Host}".downcase.slice(/[^:]+/))
end
Note that if you need to place a SIP call to other SS user, you still can do it in this way:
sys.Dial('mybuddy@local')
it will call 'mybuddy@sipsorcery.com'.
sys.Dial('mybuddy@local')
it will call 'mybuddy@sipsorcery.com'.
Code: Select all
if req.URI.host[-14,14] == "sipsorcery.com" then # skip to full sip dial if non sipsorcery host
sipsorcery.com
sip.sipsorcery.com
sip1.sipsorcery.com
sip2.sipsorcery.com
billion 7404VGP
dialplan (<9*:*>[0-9*][0-9*].T<:@sipbroker>|[0-9*].T)
dialplan (<9*:*>[0-9*][0-9*].T<:@sipbroker>|[0-9*].T)
Domains.find {...} was a workaround. The thing is that MSS wouldn't allow some reserved words like include even if they were used in some innocent context. SS doesn't have this limitation, so I replaced it with Domains.include?(host) where Domains defined as follows:
Code: Select all
Domains = ['sipsorcery.com','sip1.sipsorcery.com','sip2.sipsorcery.com','174.129.234.254','174.129.236.7']
I just updated my outplans with a self contained sip dial block that can be added or deleted from the outplan's more simplied structure.
Can be added to ruby wizard dial plans.
Can be added to ruby wizard dial plans.
Code: Select all
# ****************************************
# if a full sip dial, dial here and quit.
# skip to number dial if sipsorcery host
# ****************************************
siphost = req.URI.Host.downcase.slice(/[^:]+/)
if !( siphost[-14,14] == "sipsorcery.com" or siphost == "174.129.236.7" or siphost == "174.129.234.254" )
sys.Log("Sip Number in #{req.URI.User}@#{req.URI.Host}")
sys.Dial("#{req.URI.User}@" << "#{req.URI.Host}".downcase) # dial full sip address entered
sys.Respond(480, "failed sip dial.") # A failed sip dial, quit dial plan
end
# end of sip dial.
billion 7404VGP
dialplan (<9*:*>[0-9*][0-9*].T<:@sipbroker>|[0-9*].T)
dialplan (<9*:*>[0-9*][0-9*].T<:@sipbroker>|[0-9*].T)
You can use sys.GetCanonicalDomain(string host) to check whether a hostname is serviced by sipsorcery. If the host is serviced the canonical domain will be returned, which at this point is always sipsorcery.com.
Regards,
Aaron
Code: Select all
domain = sys.GetCanonicalDomain("174.129.236.7:8060")
=> sipsorcery.com
sys.GetCanonicalDomain("sip1.sipsorcery.com")
=> sipsorcery.com
sys.GetCanonicalDomain("somedomain.somewhere.com")
=> nil
Aaron
Good to know, I tried it in my code so far so good.
Code: Select all
# ****************************************
# if a full sip dial, dial here and quit.
# skip to number dial if sipsorcery host
# ****************************************
if sys.GetCanonicalDomain(req.URI.Host.to_s) == "sipsorcery.com"
sys.Dial("local") if req.URI.User =~ /[a-zA-Z]/ # if dialled sipsorcery name not number
sys.Respond(480, "failed sip dial.") if req.URI.User =~ /[a-zA-Z]/ # A failed sip dial, quit dial plan
else
sys.Log("Sip Number in #{req.URI.User}@#{req.URI.Host}")
sys.Dial("#{req.URI.User}@" << "#{req.URI.Host}".downcase) # dial full sip address entered
sys.Respond(480, "failed sip dial.") # A failed sip dial, quit dial plan
end
# end of sip dial.
Last edited by mnipp on Sat May 01, 2010 4:21 am, edited 1 time in total.
billion 7404VGP
dialplan (<9*:*>[0-9*][0-9*].T<:@sipbroker>|[0-9*].T)
dialplan (<9*:*>[0-9*][0-9*].T<:@sipbroker>|[0-9*].T)