Dialplan to dial SIP URI?

Catalog of dial plans
lhui
Posts: 2
Joined: Wed Sep 30, 2009 1:26 am

Dialplan to dial SIP URI?

Post by lhui » Wed Sep 30, 2009 8:41 am

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?

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

Post by MikeTelis » Wed Sep 30, 2009 8:57 am

You can distinguish between URI and PSTN dialing by Host. If Host is one of Sipsorcery (MySIPswitch) domain names, it's PSTN.

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
Please refer to complete dialplan.

lhui
Posts: 2
Joined: Wed Sep 30, 2009 1:26 am

thanks!

Post by lhui » Wed Sep 30, 2009 9:14 am

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

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

Post by MikeTelis » Thu Oct 01, 2009 6:14 am

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'.

mnipp
Posts: 192
Joined: Sat Oct 03, 2009 9:48 am
Location: NSW Australia

Post by mnipp » Mon Feb 15, 2010 8:35 am

Code: Select all

if req.URI.host[-14,14] == "sipsorcery.com" then   # skip to full sip dial if non sipsorcery host
I now use this in the first line so I test only the last 14 characters for a match to test true on all these forms.
sipsorcery.com
sip.sipsorcery.com
sip1.sipsorcery.com
sip2.sipsorcery.com
billion 7404VGP
dialplan (<9*:*>[0-9*][0-9*].T<:@sipbroker>|[0-9*].T)

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

Post by MikeTelis » Tue Feb 16, 2010 3:48 am

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

mnipp
Posts: 192
Joined: Sat Oct 03, 2009 9:48 am
Location: NSW Australia

Post by mnipp » Tue Mar 09, 2010 8:15 am

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.

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)

Aaron
Site Admin
Posts: 4652
Joined: Thu Jul 12, 2007 12:13 am

Post by Aaron » Tue Mar 09, 2010 8:52 am

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.

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
Regards,

Aaron

mnipp
Posts: 192
Joined: Sat Oct 03, 2009 9:48 am
Location: NSW Australia

Post by mnipp » Tue Mar 09, 2010 10:33 am

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)

beaver
Posts: 241
Joined: Tue Feb 09, 2010 5:32 am
Location: Beaverton USA (PST, GMT - 8)

Post by beaver » Sun Mar 14, 2010 12:32 am

mnipp wrote: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.
A question from a learner. What's the benefit of this method? dialing faster? or better audio quality? shorter latency?

Thanks,

Post Reply