Posts Tagged ‘inum’

How-To: Distinguish PSTN, Skype, iNum, and SIP in your Tropo applications

Tuesday, February 23rd, 2010

Here at the secret layers of Tropo Support we often see similar questions raised by our developer base. We pay attention to these trends, since they often indicate that something may be lacking in our documentation.   If we do find something is lacking we of course want to address by expanding on concepts or adding additional examples to help shore up our doc sets and help out our developers.

Recently I have started to notice a trend of developers asking how to determine the source of callers dialing into their applications (Skype, PSTN, SIP, or iNum).  We’ll since we are often asked this question I figured I would provide a nice Ruby example for the ‘class’ =), I do hope this help!

Regards,
John Dyer
Customer Engineer
Voxeo Support

# -----------
# route based on DNIS
# John Dyer
# Voxeo Support
# -----------
log "@"*10 + $currentCall.inspect   # List some headers
log "@"*10  + $currentCall.getHeader("x-voxeo-to")  # log to header

module SipRegex
  def evaluate_sip_header(header)
    case header
      when /^<sip:990/            # SKYPE
        "SKYPE"
      when /<sip:999/              # SIP
        "SIP"
      when /^<sip:883/            # iNUM
        "INUM"
      when /<sip:|[1-9]\d\d/      # PSTN
        "PSTN"
      else
        "OTHER"
    end
  end
end
include SipRegex

toHeader = evaluate_sip_header($currentCall.getHeader("x-voxeo-to"))

if toHeader == 'PSTN'
    answer
    log "@"*10 + toHeader
    hangup
  elsif toHeader == 'SKYPE'
    answer
    log "@"*10 + toHeader
    hangup
  elsif  toHeader == 'SIP'
    answer
    log "@"*10 + toHeader
    hangup
  elsif  toHeader == 'INUM'
    answer
    log "@"*10 + toHeader
    hangup
  elsif toHeader == 'OTHER'
    answer
    log "@"*10 + toHeader
    hangup
  else
    log "@"*10 + "SOMETHING BAD HAPPENED" 
end