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

February 23rd, 2010 by John Dyer

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

Related posts:

  1. Join the Tropo developer community – via Forums, IRC or Skype
  2. How to Build a VoIP-Based Baby Monitor
  3. Tutorial: Click-to-Call applications (w/ conferencing)
  4. Get the Tropo sample applications – via git and Github
  5. The People’s Skype for the #Occupy Movement

Tags: , , , , ,

3 Tweets

5 Responses to “How-To: Distinguish PSTN, Skype, iNum, and SIP in your Tropo applications”

  1. Mike Telis says:

    I noticed that SIP calls come with the following x-voxeo-to header:

    Call[mtelis->999144xxxx] : @@@@@@@@@@

    and wrongly identified as “PSTN”. You need to remove leading “1″ in the pattern. Here is my version:

    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

    BTW, you don't have a branch for 'SIP' in the if toHeader.. elseif statement and in result the code produces "SOMETHING BAD HAPPENED" error message while in fact everything is working just as expected.

  2. Mike Telis says:

    Something is wrong with formatting, comment is looking good when I type it but not line breaks when submitted. Here is yet another attempt. For some reason Mike =========

    I noticed that SIP calls come with the following x-voxeo-to header:

    Call[mtelis->999144xxxx] : @@@@@@@@@@

    and wrongly identified as “PSTN”. You need to remove leading “1″ in the pattern. Here is my version:

    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

    BTW, you don't have a branch for 'SIP' in the if toHeader.. elseif statement and in result the code produces "SOMETHING BAD HAPPENED" error message while in fact everything is working just as expected.

  3. John Dyer says:

    Thanks Mike,

    It seems changes made on our network while making Tropo production ready effected some of the SBC data used to determine these routes, and as such it invalidated my test module. Appreciate the heads up, and I have corrected the code.

    Regards,

    John Dyer Customer Engineer Voxeo Support

Leave a Reply

Please note: By submitting a comment you agree to comply with our Comment Policy. We welcome all comments, positive or negative, but do reserve the right to remove all or part of blog comments that do not comply with our policy.

Additionally, the first time you leave a comment on this blog, it will be held for moderation. After that first comment has been approved, future comments will be posted without delay.

Additional comments powered by BackType