Help with a Guyana Dial Plan

Catalog of dial plans
arampe
Posts: 70
Joined: Mon Nov 15, 2010 11:38 pm

Help with a Guyana Dial Plan

Post by arampe » Thu Oct 13, 2011 8:04 pm

Hello everyone,

Code: Select all

I am using Mike telis Dial Plan , and it works great .
I want to dial 592 641 4210 and have it go to my PSTN  VSP. 
but there is a problem in my dial plan , can any assist please ..

Console says..

[quote]
ip1(1940): 
NATKeepAlive 19:57:02:985 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.80.78.52:55555.
NATKeepAlive 19:57:03:016 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:212.150.129.2:30037.
NATKeepAlive 19:57:03:016 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.213.188.244:5060.
DialPlan 19:57:03:875 sip1(4880): New call from udp:212.150.129.2:30037 successfully authenticated by digest.
DialPlan 19:57:03:891 sip1(4880): Using dialplan 250809 for Out call to sip:5926412110@sipsorcery.com.
NewCall 19:57:03:891 sip1(4880): Executing script dial plan for call to 5926412110.
DialPlan 19:57:04:000 sip1(4880): ** Call from <sip:AdeshOffice@sipsorcery.com>;tag=7535a07e5b05191083f292e6e31cc4cc to 5926412110 **
DialPlan 19:57:04:000 sip1(4880): Local time: 10/13/2011 18:57
DialPlan 19:57:04:016 sip1(4880): Number in ENUM format: 15926412110
DialPlan 19:57:04:375 sip1(4880): Calling +1 (592) 641-2110 (USA/Can) with Google Voice
DialPlan 19:57:04:375 sip1(4880): SDP on GoogleVoiceCall call had public IP not mangled, RTP socket 212.150.129.2:58498.
DialPlan 19:57:04:375 sip1(4880): UAS call progressing with Ringing.
DialPlan 19:57:04:391 sip1(4880): Logging into google.com for arampe.
DialPlan 19:57:04:719 sip1(4880): Google Voice pre-login page loaded successfully.
DialPlan 19:57:04:719 sip1(4880): GALX key JciZzWIYHCo successfully retrieved.
DialPlan 19:57:07:719 sip1(4880): Google Voice home page loaded successfully.
DialPlan 19:57:08:266 sip1(4880): Call key LIm5F3pGRt/+BONBRMAQPlzvOUA= successfully retrieved for arampe, proceeding with callback.
DialPlan 19:57:08:266 sip1(1812): SIP Proxy setting application server for next call to user 250809 as udp:69.59.142.213:5070.
DialPlan 19:57:10:297 sip1(4880): Google Voice Call to +15926412110 initiated, callback #3057604525, phone type 1, timeout 10s.
DialPlan 19:57:11:751 sip1(4916): Using dialplan Andy_and_Melly for In call to sip:Andy_and_Melly@sipsorcery.com.
NewCall 19:57:11:766 sip1(4916): Executing script dial plan for call to Andy_and_Melly.
DialPlan 19:57:11:829 sip1(4916): ** Call from "7185028863" <sip:7185028863@64.154.41.150>;tag=as52910316 to Andy_and_Melly **
DialPlan 19:57:11:829 sip1(4916): Local time: 10/13/2011 15:57
DialPlan 19:57:11:844 sip1(4916): Caller's number: '17185028863'
DialPlan 19:57:11:844 sip1(4916): Caller's name:   'Andy and Melly'
DialPlan 19:57:11:860 sip1(4916): URI dialing: Andy_and_Melly@local[fu=17185028863]
DialPlan 19:57:11:860 sip1(4916): Commencing Dial with: Andy_and_Melly@local[fu=17185028863].
DialPlan 19:57:11:860 sip1(4916): Call leg is for local domain looking up bindings for Andy_and_Melly@sipsorcery.com for call leg Andy_and_Melly@local.
DialPlan 19:57:11:891 sip1(4916): 1 found for Andy_and_Melly@sipsorcery.com.
DialPlan 19:57:11:891 sip1(4916): ForkCall commencing call leg to sip:Andy_and_Melly@190.213.188.244:5060.
DialPlan 19:57:11:891 sip1(4916): SIPClientUserAgent Call using alternate outbound proxy of udp:69.59.142.213:5060.
DialPlan 19:57:11:891 sip1(4916): Switching to sip:Andy_and_Melly@190.213.188.244:5060 via udp:69.59.142.213:5060.
DialPlan 19:57:11:891 sip1(4916): SDP on UAC call had public IP not mangled, RTP socket 64.154.41.150:18764.
DialPlan 19:57:12:063 sip1(4916): Information response 100 Trying for sip:Andy_and_Melly@190.213.188.244:5060.
DialPlan 19:57:12:079 sip1(4916): Information response 180 Ringing for sip:Andy_and_Melly@190.213.188.244:5060.
DialPlan 19:57:12:079 sip1(4916): UAS call progressing with Ringing.
NATKeepAlive 19:57:13:063 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.139.2:1025.
NATKeepAlive 19:57:13:079 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.139.2:5061.
NATKeepAlive 19:57:13:094 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.191.19:5060.
NATKeepAlive 19:57:13:094 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.80.78.52:55555.
NATKeepAlive 19:57:13:126 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:212.150.129.2:30037.
NATKeepAlive 19:57:13:126 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.213.188.244:5060.
DialPlan 19:57:13:298 sip1(4916): Information response 180 Ringing for sip:Andy_and_Melly@190.213.188.244:5060.
DialPlan 19:57:13:298 sip1(4916): UAS call ignoring progress response with status of 180 as already in Proceeding.
DialPlan 19:57:18:610 sip1(4916): Response 200 OK for sip:Andy_and_Melly@190.213.188.244:5060.
DialPlan 19:57:18:626 sip1(4916): SDP on UAC response had public IP not mangled, RTP socket 190.213.188.244:16418.
DialPlan 19:57:18:626 sip1(4916): Cancelling all call legs for ForkCall app.
DialPlan 19:57:18:626 sip1(4916): Answering client call with a response status of 200.
DialPlan 19:57:18:688 sip1(4916): Dial command was successfully answered in 6.80s.
DialPlan 19:57:18:688 sip1(4916): Dialplan cleanup for 250809.
DialPlan 19:57:18:954 sip1(4916): Dial plan execution completed with normal clearing.
DialPlan 19:57:20:298 sip1(4880): Google Voice Call timed out waiting for callback.
DialPlan 19:57:21:345 sip1(4880): Google Voice Call to +15926412110 was successfully cancelled.
DialPlan 19:57:21:345 sip1(4880): Google Voice Call failed!
DialPlan 19:57:21:345 sip1(4880): UAS call failed with a response status of 603 and Service Unavailable.
DialPlan 19:57:21:345 sip1(4880): Dialplan cleanup for 250809.
DialPlan 19:57:21:454 sip1(4880): Dial plan execution completed with normal clearing.
DialPlan 19:57:21:782 sip1(4916): Matching dialogue found for BYE to sip:69.59.142.213:5060 from udp:69.59.142.213:5060.
NATKeepAlive 19:57:23:188 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.139.2:1025.
NATKeepAlive 19:57:23:204 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.139.2:5061.
NATKeepAlive 19:57:23:204 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.191.19:5060.
NATKeepAlive 19:57:23:204 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.80.78.52:55555.
NATKeepAlive 19:57:23:235 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:212.150.129.2:30037.
NATKeepAlive 19:57:23:235 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.213.188.244:506[/quote]

My Dial Plan :
[quote]
# Copyright 2010 Mike Telis
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.



require 'mikesgem'

# ************* C O N F I G U R A T I O N    S E C T I O N *************** #

Area = '868'          # my area code, this will be added to 7-digit dialouts
Tz   = -4             # my time zone (GMT format, e.g. Eastern = -5, Central = -6)

# Speed dial entries. Format: "key" => "number"

Speeddial = {
  
  '1'   => '(347) 561-4880',           # Michelle home
  '2'   => '(646) 573-2819',           # Michelle Cell
  '3'   => '(347) 210-6631',           # Vijay Cell
  '4'   => '(443) 636-7891',           # Paro Cell
  '5'   => '(360) 812-2613',           # Dad ipkall usa #
  '6'   => '008613375798811@powervoip',# Lu Peck Cell
  '7'   => '203@Nygames[ma=false]',    # Vijay home ext
  '7599373'   => '2508091@local',     # Test
  '203' => '203@Nygames',              # Vijay home ext
  '204' => '(213) 884-6354',           # Tangir Alam
  '444' => 'ecuador@local',              # Ecuador ext
  '266' => 'Bharrath@local',           # Dad home
  '269' => 'Ashtoniphone@local',           # Dad home
  '268' => 'Mellyphone@local',           # Dad home
  '253' => 'amyboodhram@local',        # Amy
  '264' => 'mmplas@local',             # office
  '263' => 'Andy_and_Melly@local',     # Home
  '265' => 'AdeshOffice@local',        # adesh
  '270' => '00115922271360@voipbusterpro',
  '273' => 'donna123@local',           # Donna Dos Santos
  '275' => '5926243120@PSTN',       # Donna Cell
  '274' => '00115926835784@powervoip',       # Ignatius cell
  '277' => '5922271360@Nygames',       # Donna Home
  '712'   => '*#2 454-1234',           # San Jose Voice Mail, dial my SJ GV using SFO GV acnt
  '713'   => '*#1 (415) 335-1234',     # San Francisco Voice Mail, dial my SFO GV using SJ GV acnt
  '714'  => '*#1 (773) 778-1234',      # San Francisco Voice Mail, dial my Chicago GV using SJ GV acnt
  '411' => '(800) 466-4411',           # Google's Directory Assistance, GOOG-411
  '200' => '303@sip.blueface.ie&612@fwd.pulver.com',
  '300' => '441923287748@Voxalot',     # BT speaking clock 
  '666' => '4153767253@podlinez.net',  # CNN Headlines (266 = "CNN")
  '677' => '8186882773@podlinez.net',  # NPR's most e-mailed stories (677 ="NPR")
  '742' => '6506441934@podlinez.net',  # Prairie Home Companion's, or PHC's
                                       # News from Lake Wobegon (742 = "PHC")
  '932' => '7755333366',               # Columbus OH-based national weather (932 = "WEA[ther]")
}

# CNAM table: number in ENUM format => caller's name

CNAM = {
'(212) 555-1212' => 'Dear mom',
'(240) 418-3987' => 'Aunty Tina',
'(718) 908-2828' => 'Ali infinity',
'(718) 656-1001' => 'Michelle Gomez Work',
'(443) 850-7625' => 'Aunty Ann Aponte',
'(864) 502-8863' => 'Daddy',
'(347) 857-9902' => 'Aunty Donna Guyana',
'(347) 441-0605' => 'Amy and Richard',
'(347) 561-4880' => 'Michelle Gomez Home',
'(443) 739-9497' => 'Diana Pinky Ramlal cell',
'(315) 895-1479' => 'Hey people Wake Up it is Six AM',
'(646) 573-2819' => 'Michelle Gomez Cell',
'(718) 502-8863' => 'Andy and Melly',
'(718) 879-8933' => 'Vijay Home', 
'(347) 210-6631' => 'Vijay Cell',
'(917) 443-2170' => 'Nishal Ramnarine',
'(754) 245-3916' => 'Rachael Diaz',
'(213) 884-6354' => 'Tangir Alam',
'(215) 333-2211' => 'Bratty kid',
}

# Uncomment next line and insert your White Pages API key, if you have it
# WP_key = '70XXXXXX74b4b1dafa62fe72fc'     # White Pages API key

# Uncomment line below to enable misdialing safeguards
# EnableSafeguards = 1

# Excluded Prefixes. Provides a safeguard against accidentally calling premium numbers

ExcludedPrefixes = [
   ' 1 (900 | 809)',               # USA Premium
   ' 1 \d\d\d 555 1212',           # USA Directory assistance
   '44 (9 | 55 | 70 | 84 | 87)',   # UK Premium
   '49 (1 [^567] | 900)',          # Germany Premium
   '39 (1 | 84 | 89)',             # Italy Premium
   '420 90',                       # Czech Premium
   '32 (70 | 90\d)',               # Belgium Premium
]

# Yet another safeguard, list of blessed country codes

Allowed_Country = %w{
1 33 36 37[0-2] 380 39 41 420 44 49 61 7 86 883 886 90 972 998
}

# My own ENUM database

MyENUM = {
'+1 (408) 334-1234' => 'brother@local', # Brother George
}

# Enum database list

EnumDB = [
  MyENUM,                             # look in MyENUM first
'e164.org',
'e164.info',
'e164.arpa',
'e164.televolution.net',
'enum.org',
]

# Serviced domains, must be in lowercase!

Domains  = ['sipsorcery.com','sip.sipsorcery.com','sip1.sipsorcery.com','sip2.sipsorcery.com','69.59.142.213']
Host     = 'sipsorcery.com'        # Replaces "host" on incoming calls

# Google Voice accounts

GoogleVoice   = GV.new  '#2', nil, 'Google Voice', :usr => 'XXXXX', :pwd => 'XXXXXXXXX',
                                                   :cb => '(305) 060-4525', :match => '7995028863'

Voipstunt     = VSP.new '#3', '00 ${EXTEN}@Voxalot', 'Voipstunt'
Nygames       = VSP.new '#4', '01 ${EXTEN}@Voxalot', 'Voipstunt'

PSTN          = VSP.new '#1', '${EXTEN:1}@pstn', 'SPA3102 at home'

   
# ********************  s e l e c t   V S P  *******************************

def selectVSP    # VoIP provider selection

  case @num
    when /(^1(868)\d{6})/                 # Trinidad
              route_to PSTN, 'Local call', false

    when /^\*/                                       # For *500, *600 and other Voxalot services
      route_to Voxalot, "Voxalot Services", false

    when /(^1([2-9]\d\d)[2-9]\d{6})/                 # North America
      @num = $1                                      # Truncate to 11 digits
      route_to GoogleVoice, 'USA/Can', false

  else
    rejectCall(603,"Number's too short, check & dial again") if @num.length < 9
    route_to Voipstunt
  end
end



# ------------ O P T I O N A L   C O N F I G U R A T I O N --------------- #

# ********************  i n c o m i n g   C a l l  *************************

def incomingCall
  sys.SetFromHeader(formatNum(@cname || @cid,true), nil, Host)  # Set FromName & FromHost for sys.Dial

  # Forward call to the bindings (ATA / softphone)
  # Change FromURI when forwarding to @local, or else Bria won't find contact in its phonebook!

  callswitch("#{@user}@local[fu=#{@cid}]",45) unless (2230..2231) === @t.hour*100 + @t.min # reject incoming calls from 10:30p to 10:31p

  @code, @reason = 480, "#{@user} is asleep" unless @code # if nothing else, must be the night hour
  @code = 486 if @trunk =~ /IPCOMM/i ## *** temporary fix for IPCOMMS ***
end

# **************************  t o   E N U M  *******************************

def to_ENUM num
  num.gsub!(/[^0-9*+]/,'') # Delete all fancy chars (only digits, '+' and '*' allowed)

  # Check if the number begins with one of international prefixes:
  #  '+' - international format
  #   00 - European style international prefix (00)
  #  011 - US style international prefix (011)

  num =~ /^(\+|00|011)/ and return $' # if yes, remove prefix and return

  case num                    # Special cases
    when /^[2-9]\d{6}$/       # Local call, 7-digit number
      '1' + Area + num        # prefix it with country and area code
    when /^[01]?([2-9]\d{9})/ # US number with or without "1" country code
      '1' + $1                # add country code and truncate number to 10-digit
    when /^\*/                # Voxalot voicemail, echotest & other special numbers
      num                     # ... as is
    else
      rejectCall(603,"Wrong number: '#{num}', check & dial again")
  end
end

# ****** E N D   O F   C O N F I G U R A T I O N    S E C T I O N ******** #

# **************************  C A L L    S W I T C H  **********************

def callswitch(num,*args)
  @timeout = args[0]
  num.gsub!(/%([0-9A-F]{2})/) {$1.to_i(16).chr} # Convert %hh into ASCII
  @num = Speeddial[num] || num  # If there is speed dial entry for it...

  if @num =~ /@/              # If we already have URI, just dial and return
    sys.Log("URI dialing: #@num")
    dial(@num,*args)
  else                        # Not URI
    rexp = VSP.tab.keys.sort {|a,b| b.length <=> a.length}.map {|x| Regexp.escape(x)}.join('|')
    if @num =~ /^(#{rexp})/   # If number starts with VSP selection prefix
      @num = $'; @forcedRoute = VSP.tab[$1]
      @noSafeGuards = (@forcedRoute.fmt =~ /Disable\s*Safe\s*Guards/i)
    end

    @num = to_ENUM(@num)      # Convert to ENUM

    rejectCall(503,"Number's empty") if @num.empty?
    sys.Log("Number in ENUM format: #{@num}")
    if @forcedRoute && !@noSafeGuards
      route_to @forcedRoute, "Forced routing!", false # if forced with prefix, skip ENUM, safeguards & VSP selection
    else
      checkNum if defined?(EnableSafeguards) && !@noSafeGuards
      selectVSP               # Pick appropriate provider for the call
    end
  end   # URI
end

# ***************************  R O U T E _ T O  ****************************

def route_to vsp, dest=nil, enum = EnumDB
  enum.to_a.each do |db|   # if enum enabled, look in all enum databases
    if uri = (db.class == Hash)? db[@num] : sys.ENUMLookup("#{@num}.#{db}")
      sys.Log("ENUM entry found: '#{uri}' in #{db.class == Hash ? 'local' : db} database")
      dial(uri)
    end
  end                   # ENUM not found or failed, call via regular VSP

  return unless vsp     # No VSP - do nothing

  uri = vsp.fmt.gsub(/\s+/,'').gsub(/\$\{EXTEN(:([^:}]+)(:([^}]+))?)?\}/) {@num[$2.to_i,$4? $4.to_i : 100]}
  dest &&= " (#{dest})"; with = vsp.name; with &&= " with #{with}"
  sys.Log("Calling #{formatNum(@num)}#{dest}#{with}")

  if vsp.is_gv?
    vsp.repeat.times do |i|
      @code, @reason = 200, "OK"  # assume OK
      sys.GoogleVoiceCall *vsp.getparams(uri, i + (vsp.rand ? @t.to_i : 0))
      sys.Log("Google Voice Call failed!")
      @code, @reason = 603, 'Service Unavailable'
    end
  else
    vsp.repeat.times do
      dial(uri, @timeout || vsp.tmo || 300) # Dial, global time-out overrides account
    end
  end
end

# *******************************  D I A L  ********************************

def dial *args
  @code, @reason = nil
  sys.Dial *args    # dial URI
  status()          # We shouldn't be here! Get error code...
  sys.Log("Call failed: code #{@code}, #{@reason}")
end

# *****************************  S T A T U S  ******************************

def status
  begin
    @code, @reason = 487, 'Cancelled by Sipsorcery'
    sys.LastDialled.each do |ptr|
      if ptr
        ptr = ptr.TransactionFinalResponse
        @code = ptr.StatusCode; @reason = ptr.ReasonPhrase; break if @code == 200
#       sys.Log("#{ptr.ToString()}")
      end
    end
  rescue
  end
end

# ************************  r e j e c t C a l l  ***************************

def rejectCall code, reason
  @code = code; @reason = reason
  sys.Respond code, reason
end

# ****************************  C H E C K   N U M **************************

def checkNum
  return if @num.match(/^\D/)  # skip if number doesn't begin with a digit

  # Reject calls to not blessed countries and premium numbers
  # (unless VSP was forced using #n dial prefix)

  rejectCall(503,"Calls to code #{formatNum(@num).split(' ')[0]} not allowed") \
    unless @num.match "^(#{Allowed_Country.join('|')})"

  rejectCall(503,"Calls to '#{formatNum($&)}' not allowed") if @num.match \
    '^(' + ExcludedPrefixes.map { |x| "(:?#{x.gsub(/\s*/,'')})" }.join('|') + ')'
end

# **********************  k e y s   t o   E N U M  *************************

def keys_to_ENUM (table)
  Hash[*table.keys.map! {|key| to_ENUM(key.dup)}.zip(table.values).flatten]
end

# **************************  g e t T I M E  *******************************

def getTime
  Time.now + ((Tz+7)*60*60) # Get current time and adjust to local. SS Server is in GMT-8
end

# *******************************  M A I N  ********************************

begin
  sys.Log("** Call from #{req.Header.From} to #{req.URI.User} **")
  sys.ExtendScriptTimeout(15)   # preventing long running dialscript time-out
  @t = getTime()
  sys.Log(@t.strftime('Local time: %c'))
  EnumDB.map! {|x| x.class == Hash ? keys_to_ENUM(x) : x } # rebuild local ENUM table

  if sys.In               # If incoming call...
    @cid = req.Header.from.FromURI.User.to_s    # Get caller ID

    # Prepend 10-digit numbers with "1" (US country code) and remove int'l prefix (if present)

    @cid = ('1' + @cid) if @cid =~ /^[2-9]\d\d[2-9]\d{6}$/
    @cid.sub!(/^(\+|00|011)/,'')   # Remove international prefixes, if any

    prs = req.URI.User.split('.')  # parse User into chunks
    @trunk = prs[-2]               # get trunk name
    @user  = prs[-1]               # called user name

    # Check CNAM first. If not found and US number, try to lookup caller's name in Whitepages

    if !(@cname = keys_to_ENUM(CNAM)[@cid]) && @cid =~ /^1([2-9]\d\d[2-9]\d{6})$/ && defined?(WP_key)
      url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Fapi.whitepages.com%2Freverse_phone%2F1.0%2F%3Fphone%3D#{$1}%3Bapi_key%3D#{WP_key}'%20and%20itemPath%3D'wp.listings.listing'&format=json"
      if js = sys.WebGet(url,4).to_s
        @cname, dname, city, state = %w(businessname displayname city state).map {|x| js =~ /"#{x}":"([^"]+)"/; $1}
        @cname ||= dname; @cname ||= "#{city}, #{state}" if city && state
      end
    end

    sys.Log("Caller's number: '#{@cid}'"); sys.Log("Caller's name:   '#{@cname}'") if @cname
    incomingCall()        # forward incoming call

  else                    # Outbound call ...

    # 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.include?(host)   # URI dialing unless host is in our domain list

    callswitch(num)

  end
  sys.Respond(@code,@reason) # Forward error code to ATA
rescue
   # Gives a lot more details at what went wrong (borrowed from Myatus' dialplan)
   sys.Log("** Error: " + $!) unless $!.to_s =~ /Thread was being aborted./
end
Best Regards
Last edited by arampe on Mon Oct 17, 2011 1:26 pm, edited 1 time in total.

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

Re: Help with a Guyana Dial Plan

Post by MikeTelis » Sat Oct 15, 2011 8:42 am

The call goes to GV because the number matches this:
when /(^1([2-9]\d\d)[2-9]\d{6})/ # North America
@num = $1 # Truncate to 11 digits
route_to GoogleVoice, 'USA/Can', false
(US number format without leading '1').
It's possible to adjust my dialplan to virtually any country, just tell me about dialing habits in your country. Do you always need to dial 592 followed by 7-digits for domestic calls or there is a short form (like last 7-digits) for local calls? What prefix you have to dial for out-of-city and out-of-country numbers?

> Mike

arampe
Posts: 70
Joined: Mon Nov 15, 2010 11:38 pm

Re: Help with a Guyana Dial Plan

Post by arampe » Sat Oct 15, 2011 1:02 pm

Thank you Mike for coming on...

First off,

I am living in trinidad and tobago.

My VSP's are as follows:
Nygames
powervoip
voipbusterpro
voipstunt
voxalot
PSTN
..

I use a sipura 3102 ( great device)

for local trinidad calls I dial 7 digits and the area code is only 868 so a # here will be 868 299 6565
any 3 digit # should go through SS cause my ext's and speed dials .
Only 203 and 270 should go to Nygames
all usa calls goes via my google voice account ,
All china # are dialed like 86xxxxxxxxxxx , begins with 86 and has 11 digits after. ( if it is easier I can dial 0086..) goes via powervoip
Guyana # are dialed like 592 xxxxxxx , always begins with 592 and 7 digits after. it goes via PSTN
Uk # I normally dial 44 should go to Voxalot

The Tricky part....
I have a spa 3102 in Trinidad ( T ) that registers fine with SS servers as PSTN.
I also have a spa 3102 in guyana, ( G ), I setup my T ata so it registers G as one of the gateways.
that means when I call a 592 # using my T ata it goes via G ata.
The call does not touch SS , it goes from T ata to G ata.
I want to be able to allow any of my ext's , when 592 # is dialed to go to my T ata and it forwards to G ata.

G ata does not have a static IP , I have access to it cause we are on the same network via VPN.
That is why I cannot register that on SS.


I know my dial plan needs work ...but where,,thank you mike ...

Best Regards
Adesh.

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

Re: Help with a Guyana Dial Plan

Post by MikeTelis » Sun Oct 16, 2011 4:26 am

Hi Adesh,

I don't like your idea of routing, everybody uses prefixes (like a prefix for long-distance call, international call prefix). May I suggest that you dial 7-digit numbers for local calls, 0-area-number for long-distance and 00-country-national number for international?

arampe
Posts: 70
Joined: Mon Nov 15, 2010 11:38 pm

Re: Help with a Guyana Dial Plan

Post by arampe » Sun Oct 16, 2011 10:25 am

Thanks mike ,
I agree , let's go with your idea and the int'l prefixes.

Best regards
Adesh.

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

Re: Help with a Guyana Dial Plan

Post by MikeTelis » Sun Oct 16, 2011 10:27 am

Okay, then I need to know local number format (how many digits), area code (if any), long-distance and international prefixes you wish to use.

arampe
Posts: 70
Joined: Mon Nov 15, 2010 11:38 pm

Re: Help with a Guyana Dial Plan

Post by arampe » Sun Oct 16, 2011 12:17 pm

Thank you Mike ,

Lets go...

My local country is Triniadad
just one area code 868 .
then i dial 7 digits .
6411 is telephone directory ( no 868 )
9 xx xxxx are premium ( donot want to dial that).

I agree with you, lets use all your prefixes in your dial plan for international calls..

My VSP's are as follows:
Nygames
powervoip
voipbusterpro
voipstunt
voxalot
PSTN
..

Guyana area code is 592 that goes via PSTN vsp. ( eg of guyana # is 592 227 1360 )
Uk calls goes via voipstunt
China calls goes via powervoip
when I dial 203 and 270 that goes to Nygames.

I hope this info is what you require...I am a noob so I might be alittle slow ...
Thank again.
Adesh

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

Re: Help with a Guyana Dial Plan

Post by MikeTelis » Sun Oct 16, 2011 5:32 pm

Trinidad is a part of NANP, dialing rules are the same as in the U.S.

So, you need to make "US/Canada" part of selectVSP() more flexible to accomodate special rule for 868 area code. Besides, you need "when" for 44 (UK), 86 (China) and 592 country codes.

Something like this:
def selectVSP # VoIP provider selection

case @num
when /(^1([2-9]\d\d)[2-9]\d{6})/ # North America
@num = $1 # Truncate to 11 digits
case $2 # check area code
when "868" # Trinidad
route_to PSTN, "Trinidad & Tobago"
else
route_to GoogleVoice, 'USA/Can' # all other destinations within US & Canada
end

when /^592\d{7}$/ # Guyana
route_to PSTN, "Guyana"

when /^86/ # China
route_to PowerVOIP, 'China'

when /^\*/ # For *500, *600 and other Voxalot services
route_to Voxalot, "Voxalot Services", nil

else
rejectCall(603,"Number's too short, check & dial again") if @num.length < 9
route_to Voipstunt
end
end
You'll need to add VSP descriptors for missing Voipstunt, PowerVOIP and the others. Hope you'll figure it out how :)

arampe
Posts: 70
Joined: Mon Nov 15, 2010 11:38 pm

Re: Help with a Guyana Dial Plan

Post by arampe » Sun Oct 16, 2011 7:21 pm

Thank you mike , a few errors though...

console ....showing calls to 868 , 592 and 86 ....
only USA calls are working fine..

Code: Select all

NATKeepAlive 19:14:16:444 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.80.78.52:55555.
NATKeepAlive 19:14:21:507 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.188.12:5060.
NATKeepAlive 19:14:21:523 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:212.150.129.3:8194.
NATKeepAlive 19:14:21:523 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.213.188.244:5060.
NATKeepAlive 19:14:21:523 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.139.2:1025.
NATKeepAlive 19:14:21:523 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.139.2:5061.
NATKeepAlive 19:14:26:569 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.80.78.52:55555.
DialPlan 19:14:26:788 sip1(3268): New call from udp:190.213.188.244:5060 successfully authenticated by digest.
DialPlan 19:14:26:804 sip1(3268): Using dialplan Andy_and_Melly for Out call to sip:8686652551@sipsorcery.com.
NewCall 19:14:26:804 sip1(3268): Executing script dial plan for call to 8686652551.
DialPlan 19:14:26:882 sip1(3268): ** Call from "Andy & Melly" <sip:Andy_and_Melly@sipsorcery.com>;tag=acc95ed944c0c933o0 to 8686652551 **
DialPlan 19:14:26:882 sip1(3268): Local time: 10/16/2011 15:14
DialPlan 19:14:26:898 sip1(3268): Number in ENUM format: 18686652551
DialPlan 19:14:26:898 sip1(3268): ** Error: uninitialized constant Object::PSTN
DialPlan 19:14:26:898 sip1(3268): Dialplan cleanup for 250809.
DialPlan 19:14:27:273 sip1(3268): Dial plan execution completed without answering and with no last failure status.
DialPlan 19:14:27:273 sip1(3268): UAS call failed with a response status of 480.
ContactRegisterInProgress 19:14:28:038 sip1(1940): Checking SIP Provider registration for sipgatedonna.
ContactRegisterInProgress 19:14:28:038 sip1(1940): Sending initial register for 250809 and sipgatedonna to udp:204.155.28.10:5060.
ContactRegisterInProgress 19:14:28:054 sip1(1940): Initiating registration for 250809 on sip:sipgate.com.
ContactRegistered 19:14:28:116 sip1(1940): Contact successfully registered for 250809 on sip:sipgate.com, expiry 60s.
NATKeepAlive 19:14:31:616 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.188.12:5060.
NATKeepAlive 19:14:31:632 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:212.150.129.3:8194.
NATKeepAlive 19:14:31:632 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.213.188.244:5060.


NATKeepAlive 19:17:59:011 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.213.188.244:5060.
NATKeepAlive 19:18:04:058 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.80.78.52:55555.
NATKeepAlive 19:18:04:058 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.188.12:5060.
NATKeepAlive 19:18:04:058 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:212.150.129.3:8194.
NATKeepAlive 19:18:04:074 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.139.2:1025.
NATKeepAlive 19:18:04:074 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.139.2:5061.
DialPlan 19:18:04:480 sip1(2528): New call from udp:190.213.188.244:5060 successfully authenticated by digest.
DialPlan 19:18:04:480 sip1(2528): Using dialplan Andy_and_Melly for Out call to sip:5922271360@sipsorcery.com.
NewCall 19:18:04:496 sip1(2528): Executing script dial plan for call to 5922271360.
DialPlan 19:18:04:558 sip1(2528): ** Call from "Andy & Melly" <sip:Andy_and_Melly@sipsorcery.com>;tag=fb3085beb2931c99o0 to 5922271360 **
DialPlan 19:18:04:558 sip1(2528): Local time: 10/16/2011 15:18
DialPlan 19:18:04:605 sip1(2528): Number in ENUM format: 15922271360
DialPlan 19:18:04:824 sip1(2528): Calling +1 (592) 227-1360 (USA/Can) with Google Voice
DialPlan 19:18:04:839 sip1(2528): SDP on GoogleVoiceCall call had public IP not mangled, RTP socket 190.213.188.244:16434.
DialPlan 19:18:04:839 sip1(2528): UAS call progressing with Ringing.
DialPlan 19:18:04:839 sip1(2528): Logging into google.com for arampe.
DialPlan 19:18:04:902 sip1(2528): Google Voice pre-login page loaded successfully.
DialPlan 19:18:04:949 sip1(2528): GALX key yn-kmNGrcCI successfully retrieved.
DialPlan 19:18:05:855 sip1(2528): Google Voice home page loaded successfully.
DialPlan 19:18:05:933 sip1(2528): Call key LIm5F3pGRt/+BONBRMAQPlzvOUA= successfully retrieved for arampe, proceeding with callback.
DialPlan 19:18:05:949 sip1(1812): SIP Proxy setting application server for next call to user 250809 as udp:69.59.142.213:5071.
DialPlan 19:18:06:105 sip1(2528): Google Voice Call to +15922271360 initiated, callback #3057604525, phone type 1, timeout 10s.
DialPlan 19:18:07:464 sip1(2528): Google Voice Call callback received.
DialPlan 19:18:07:464 sip1(2528): Answering client call with a response status of 200.
DialPlan 19:18:07:558 sip1(2528): Google Voice Call was successfully answered in 2.72s.
DialPlan 19:18:07:558 sip1(2528): Dialplan cleanup for 250809.
DialPlan 19:18:07:933 sip1(2528): Dial plan execution completed with normal clearing.
NATKeepAlive 19:18:09:121 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.213.188.244:5060.
ContactRegisterInProgress 19:18:09:683 sip1(1940): Checking SIP Provider registration for sipgatedonna.
ContactRegisterInProgress 19:18:09:683 sip1(1940): Sending initial register for 250809 and sipgatedonna to udp:204.155.28.10:5060.
ContactRegisterInProgress 19:18:09:699 sip1(1940): Initiating registration for 250809 on sip:sipgate.com.
ContactRegistered 19:18:09:761 sip1(1940): Contact successfully registered for 250809 on sip:sipgate.com, expiry 60s.
NATKeepAlive 19:18:14:168 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.80.78.52:55555.
NATKeepAlive 19:18:14:168 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.188.12:5060.
NATKeepAlive 19:18:14:183 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:212.150.129.3:8194.
NATKeepAlive 19:18:14:183 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.139.2:1025.
NATKeepAlive 19:18:14:183 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.139.2:5061.
DialPlan 19:18:14:464 sip1(6816): Matching dialogue found for BYE to sip:69.59.142.213:5060 from udp:69.59.142.213:5060.
NATKeepAlive 19:18:19:230 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.213.188.244:5060.


NATKeepAlive 19:19:35:075 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:212.150.129.3:8194.
NATKeepAlive 19:19:35:091 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.139.2:1025.
NATKeepAlive 19:19:35:091 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.139.2:5061.
DialPlan 19:19:39:669 sip1(6816): New call from udp:190.213.188.244:5060 successfully authenticated by digest.
DialPlan 19:19:39:685 sip1(6816): Using dialplan Andy_and_Melly for Out call to sip:8613472106631@sipsorcery.com.
NewCall 19:19:39:685 sip1(6816): Executing script dial plan for call to 8613472106631.
DialPlan 19:19:39:951 sip1(6816): ** Call from "Andy & Melly" <sip:Andy_and_Melly@sipsorcery.com>;tag=6c619c42ae9f7d16o0 to 8613472106631 **
DialPlan 19:19:39:951 sip1(6816): Local time: 10/16/2011 15:19
DialPlan 19:19:40:044 sip1(6816): Number in ENUM format: 18613472106
NATKeepAlive 19:19:40:122 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.80.78.52:55555.
NATKeepAlive 19:19:40:138 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.213.188.244:5060.
DialPlan 19:19:40:419 sip1(6816): Calling +1 (861) 347-2106 (USA/Can) with Google Voice
DialPlan 19:19:40:435 sip1(6816): SDP on GoogleVoiceCall call had public IP not mangled, RTP socket 190.213.188.244:16436.
DialPlan 19:19:40:435 sip1(6816): UAS call progressing with Ringing.
DialPlan 19:19:40:435 sip1(6816): Logging into google.com for arampe.
DialPlan 19:19:40:482 sip1(6816): Google Voice pre-login page loaded successfully.
DialPlan 19:19:40:513 sip1(6816): GALX key 3TPMkTZtk-M successfully retrieved.
DialPlan 19:19:41:388 sip1(6816): Google Voice home page loaded successfully.
DialPlan 19:19:41:435 sip1(6816): Call key LIm5F3pGRt/+BONBRMAQPlzvOUA= successfully retrieved for arampe, proceeding with callback.
DialPlan 19:19:41:451 sip1(1812): SIP Proxy setting application server for next call to user 250809 as udp:69.59.142.213:5070.
DialPlan 19:19:41:607 sip1(6816): Google Voice Call to +18613472106 initiated, callback #3057604525, phone type 1, timeout 10s.
DialPlan 19:19:42:919 sip1(6816): Google Voice Call callback received.
DialPlan 19:19:42:919 sip1(6816): Answering client call with a response status of 200.
DialPlan 19:19:43:138 sip1(6816): Google Voice Call was successfully answered in 2.70s.
DialPlan 19:19:43:138 sip1(6816): Dialplan cleanup for 250809.
DialPlan 19:19:43:216 sip1(6816): Dial plan execution completed with normal clearing.
NATKeepAlive 19:19:45:185 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.188.12:5060.
NATKeepAlive 19:19:45:185 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:212.150.129.3:8194.
NATKeepAlive 19:19:45:201 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.139.2:1025.
NATKeepAlive 19:19:45:201 sip1(4248): Requesting NAT keep-alive from proxy socket udp:69.59.142.213:5060 to udp:190.83.139.2:5061.
Registrar 19:19:50:091 sip1(4248): Binding update request for amyboodhram@sipsorcery.com from udp:190.83.188.12:5060, expiry requested 600s granted 600s.

Dialplan now ....

Code: Select all


# Copyright 2010 Mike Telis
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
# Donna123 - sipgate - adesh@vijaysconsulting.com - ashton1 - (518) 351-1348
# Amyboodhram - sipgate - adesh@mmplas.com - ashton1 - (650) 284-1494
# Andy and Melly - sipgate - arampe@gmail.com - ashton1 -  


require 'mikesgem'

# ************* C O N F I G U R A T I O N    S E C T I O N *************** #

Area = '868'          # my area code, this will be added to 7-digit dialouts
Tz   = -4             # my time zone (GMT format, e.g. Eastern = -5, Central = -6)

# Speed dial entries. Format: "key" => "number"

Speeddial = {
  
  '1'   => '(347) 561-4880',           # Michelle home
  '2'   => '(646) 573-2819',           # Michelle Cell
  '3'   => '(347) 210-6631',           # Vijay Cell
  '4'   => '(443) 636-7891',           # Paro Cell
  '5'   => '(360) 812-2613',           # Dad ipkall usa #
  '6'   => '008613375798811@powervoip',# Lu Peck Cell
  '7'   => '203@Nygames[ma=false]',    # Vijay home ext
  '7599373'   => '2508091@local',     # Test
  '203' => '203@Nygames',              # Vijay home ext
  '204' => '(213) 884-6354',           # Tangir Alam
  '444' => 'ecuador@local',              # Ecuador ext
  '266' => 'Bharrath@local',           # Dad home
  '269' => 'Ashtoniphone@local',           # Dad home
  '268' => 'Mellyphone@local',           # Dad home
  '253' => 'amyboodhram@local',        # Amy
  '264' => 'mmplas@local',             # office
  '263' => 'Andy_and_Melly@local',     # Home
  '265' => 'AdeshOffice@local',        # adesh
  '270' => '00115922271360@voipbusterpro',
  '273' => 'donna123@local',           # Donna Dos Santos
  '275' => '5926243120@PSTN',       # Donna Cell
  '274' => '00115926835784@powervoip',       # Ignatius cell
  '277' => '5922271360@Nygames',       # Donna Home
  '712'   => '*#2 454-1234',           # San Jose Voice Mail, dial my SJ GV using SFO GV acnt
  '713'   => '*#1 (415) 335-1234',     # San Francisco Voice Mail, dial my SFO GV using SJ GV acnt
  '714'  => '*#1 (773) 778-1234',      # San Francisco Voice Mail, dial my Chicago GV using SJ GV acnt
  '411' => '(800) 466-4411',           # Google's Directory Assistance, GOOG-411
  '200' => '303@sip.blueface.ie&612@fwd.pulver.com',
  '300' => '441923287748@Voxalot',     # BT speaking clock 
  '666' => '4153767253@podlinez.net',  # CNN Headlines (266 = "CNN")
  '677' => '8186882773@podlinez.net',  # NPR's most e-mailed stories (677 ="NPR")
  '742' => '6506441934@podlinez.net',  # Prairie Home Companion's, or PHC's
                                       # News from Lake Wobegon (742 = "PHC")
  '932' => '7755333366',               # Columbus OH-based national weather (932 = "WEA[ther]")
}

# CNAM table: number in ENUM format => caller's name

CNAM = {
'(212) 555-1212' => 'Dear mom',
'(240) 418-3987' => 'Aunty Tina',
'(718) 908-2828' => 'Ali infinity',
'(718) 656-1001' => 'Michelle Gomez Work',
'(443) 850-7625' => 'Aunty Ann Aponte',
'(864) 502-8863' => 'Daddy',
'(347) 857-9902' => 'Aunty Donna Guyana',
'(347) 441-0605' => 'Amy and Richard',
'(347) 561-4880' => 'Michelle Gomez Home',
'(443) 739-9497' => 'Diana Pinky Ramlal cell',
'(315) 895-1479' => 'Hey people Wake Up it is Six AM',
'(646) 573-2819' => 'Michelle Gomez Cell',
'(718) 502-8863' => 'Andy and Melly',
'(718) 879-8933' => 'Vijay Home', 
'(347) 210-6631' => 'Vijay Cell',
'(917) 443-2170' => 'Nishal Ramnarine',
'(754) 245-3916' => 'Rachael Diaz',
'(213) 884-6354' => 'Tangir Alam',
'(215) 333-2211' => 'Bratty kid',
}

# Uncomment next line and insert your White Pages API key, if you have it
# WP_key = '702f53d569ee0374b4b1dafa62fe72fc'     # White Pages API key

# Uncomment line below to enable misdialing safeguards
# EnableSafeguards = 1

# Excluded Prefixes. Provides a safeguard against accidentally calling premium numbers

ExcludedPrefixes = [
   ' 1 (900 | 809)',               # USA Premium
   ' 1 \d\d\d 555 1212',           # USA Directory assistance
   '44 (9 | 55 | 70 | 84 | 87)',   # UK Premium
   '49 (1 [^567] | 900)',          # Germany Premium
   '39 (1 | 84 | 89)',             # Italy Premium
   '420 90',                       # Czech Premium
   '32 (70 | 90\d)',               # Belgium Premium
]

# Yet another safeguard, list of blessed country codes

Allowed_Country = %w{
1 33 36 37[0-2] 380 39 41 420 44 49 61 7 86 883 886 90 972 998
}

# My own ENUM database

MyENUM = {
'+1 (408) 334-1234' => 'brother@local', # Brother George
}

# Enum database list

EnumDB = [
  MyENUM,                             # look in MyENUM first
'e164.org',
'e164.info',
'e164.arpa',
'e164.televolution.net',
'enum.org',
]

# Serviced domains, must be in lowercase!

Domains  = ['sipsorcery.com','sip.sipsorcery.com','sip1.sipsorcery.com','sip2.sipsorcery.com','69.59.142.213']
Host     = 'sipsorcery.com'        # Replaces "host" on incoming calls

# Google Voice accounts

GoogleVoice   = GV.new  '#2', nil, 'Google Voice', :usr => 'fffffff', :pwd => 'vffffgdfgd',
                                                   :cb => '(305) 760-4525', :match => '7185343863'

Voipstunt     = VSP.new '#3', '00 ${EXTEN}@Voxalot', 'Voipstunt'
Nygames       = VSP.new '#4', '01 ${EXTEN}@Voxalot', 'Voipstunt'

PSTN          = VSP.new '#1', '${EXTEN:1}@pstn', 'SPA3102 at home'

   
# ********************  s e l e c t   V S P  *******************************

def selectVSP # VoIP provider selection

case @num
when /(^1([2-9]\d\d)[2-9]\d{6})/ # North America
@num = $1 # Truncate to 11 digits
case $2 # check area code
when "868" # Trinidad
route_to PSTN, "Trinidad & Tobago"
else
route_to GoogleVoice, 'USA/Can' # all other destinations within US & Canada
end

when /^592\d{7}$/ # Guyana
route_to PSTN, "Guyana"

when /^86/ # China
route_to PowerVOIP, 'China'

when /^\*/ # For *500, *600 and other Voxalot services
route_to Voxalot, "Voxalot Services", nil

else
rejectCall(603,"Number's too short, check & dial again") if @num.length < 9
route_to Voipstunt
end
end

# ------------ O P T I O N A L   C O N F I G U R A T I O N --------------- #

# ********************  i n c o m i n g   C a l l  *************************

def incomingCall
  sys.SetFromHeader(formatNum(@cname || @cid,true), nil, Host)  # Set FromName & FromHost for sys.Dial

  # Forward call to the bindings (ATA / softphone)
  # Change FromURI when forwarding to @local, or else Bria won't find contact in its phonebook!

  callswitch("#{@user}@local[fu=#{@cid}]",45) unless (2230..2231) === @t.hour*100 + @t.min # reject incoming calls from 10:30p to 10:31p

  @code, @reason = 480, "#{@user} is asleep" unless @code # if nothing else, must be the night hour
  @code = 486 if @trunk =~ /IPCOMM/i ## *** temporary fix for IPCOMMS ***
end

# **************************  t o   E N U M  *******************************

def to_ENUM num
  num.gsub!(/[^0-9*+]/,'') # Delete all fancy chars (only digits, '+' and '*' allowed)

  # Check if the number begins with one of international prefixes:
  #  '+' - international format
  #   00 - European style international prefix (00)
  #  011 - US style international prefix (011)

  num =~ /^(\+|00|011)/ and return $' # if yes, remove prefix and return

  case num                    # Special cases
    when /^[2-9]\d{6}$/       # Local call, 7-digit number
      '1' + Area + num        # prefix it with country and area code
    when /^[01]?([2-9]\d{9})/ # US number with or without "1" country code
      '1' + $1                # add country code and truncate number to 10-digit
    when /^\*/                # Voxalot voicemail, echotest & other special numbers
      num                     # ... as is
    else
      rejectCall(603,"Wrong number: '#{num}', check & dial again")
  end
end

# ****** E N D   O F   C O N F I G U R A T I O N    S E C T I O N ******** #

# **************************  C A L L    S W I T C H  **********************

def callswitch(num,*args)
  @timeout = args[0]
  num.gsub!(/%([0-9A-F]{2})/) {$1.to_i(16).chr} # Convert %hh into ASCII
  @num = Speeddial[num] || num  # If there is speed dial entry for it...

  if @num =~ /@/              # If we already have URI, just dial and return
    sys.Log("URI dialing: #@num")
    dial(@num,*args)
  else                        # Not URI
    rexp = VSP.tab.keys.sort {|a,b| b.length <=> a.length}.map {|x| Regexp.escape(x)}.join('|')
    if @num =~ /^(#{rexp})/   # If number starts with VSP selection prefix
      @num = $'; @forcedRoute = VSP.tab[$1]
      @noSafeGuards = (@forcedRoute.fmt =~ /Disable\s*Safe\s*Guards/i)
    end

    @num = to_ENUM(@num)      # Convert to ENUM

    rejectCall(503,"Number's empty") if @num.empty?
    sys.Log("Number in ENUM format: #{@num}")
    if @forcedRoute && !@noSafeGuards
      route_to @forcedRoute, "Forced routing!", false # if forced with prefix, skip ENUM, safeguards & VSP selection
    else
      checkNum if defined?(EnableSafeguards) && !@noSafeGuards
      selectVSP               # Pick appropriate provider for the call
    end
  end   # URI
end

# ***************************  R O U T E _ T O  ****************************

def route_to vsp, dest=nil, enum = EnumDB
  enum.to_a.each do |db|   # if enum enabled, look in all enum databases
    if uri = (db.class == Hash)? db[@num] : sys.ENUMLookup("#{@num}.#{db}")
      sys.Log("ENUM entry found: '#{uri}' in #{db.class == Hash ? 'local' : db} database")
      dial(uri)
    end
  end                   # ENUM not found or failed, call via regular VSP

  return unless vsp     # No VSP - do nothing

  uri = vsp.fmt.gsub(/\s+/,'').gsub(/\$\{EXTEN(:([^:}]+)(:([^}]+))?)?\}/) {@num[$2.to_i,$4? $4.to_i : 100]}
  dest &&= " (#{dest})"; with = vsp.name; with &&= " with #{with}"
  sys.Log("Calling #{formatNum(@num)}#{dest}#{with}")

  if vsp.is_gv?
    vsp.repeat.times do |i|
      @code, @reason = 200, "OK"  # assume OK
      sys.GoogleVoiceCall *vsp.getparams(uri, i + (vsp.rand ? @t.to_i : 0))
      sys.Log("Google Voice Call failed!")
      @code, @reason = 603, 'Service Unavailable'
    end
  else
    vsp.repeat.times do
      dial(uri, @timeout || vsp.tmo || 300) # Dial, global time-out overrides account
    end
  end
end

# *******************************  D I A L  ********************************

def dial *args
  @code, @reason = nil
  sys.Dial *args    # dial URI
  status()          # We shouldn't be here! Get error code...
  sys.Log("Call failed: code #{@code}, #{@reason}")
end

# *****************************  S T A T U S  ******************************

def status
  begin
    @code, @reason = 487, 'Cancelled by Sipsorcery'
    sys.LastDialled.each do |ptr|
      if ptr
        ptr = ptr.TransactionFinalResponse
        @code = ptr.StatusCode; @reason = ptr.ReasonPhrase; break if @code == 200
#       sys.Log("#{ptr.ToString()}")
      end
    end
  rescue
  end
end

# ************************  r e j e c t C a l l  ***************************

def rejectCall code, reason
  @code = code; @reason = reason
  sys.Respond code, reason
end

# ****************************  C H E C K   N U M **************************

def checkNum
  return if @num.match(/^\D/)  # skip if number doesn't begin with a digit

  # Reject calls to not blessed countries and premium numbers
  # (unless VSP was forced using #n dial prefix)

  rejectCall(503,"Calls to code #{formatNum(@num).split(' ')[0]} not allowed") \
    unless @num.match "^(#{Allowed_Country.join('|')})"

  rejectCall(503,"Calls to '#{formatNum($&)}' not allowed") if @num.match \
    '^(' + ExcludedPrefixes.map { |x| "(:?#{x.gsub(/\s*/,'')})" }.join('|') + ')'
end

# **********************  k e y s   t o   E N U M  *************************

def keys_to_ENUM (table)
  Hash[*table.keys.map! {|key| to_ENUM(key.dup)}.zip(table.values).flatten]
end

# **************************  g e t T I M E  *******************************

def getTime
  Time.now + ((Tz+7)*60*60) # Get current time and adjust to local. SS Server is in GMT-8
end

# *******************************  M A I N  ********************************

begin
  sys.Log("** Call from #{req.Header.From} to #{req.URI.User} **")
  sys.ExtendScriptTimeout(15)   # preventing long running dialscript time-out
  @t = getTime()
  sys.Log(@t.strftime('Local time: %c'))
  EnumDB.map! {|x| x.class == Hash ? keys_to_ENUM(x) : x } # rebuild local ENUM table

  if sys.In               # If incoming call...
    @cid = req.Header.from.FromURI.User.to_s    # Get caller ID

    # Prepend 10-digit numbers with "1" (US country code) and remove int'l prefix (if present)

    @cid = ('1' + @cid) if @cid =~ /^[2-9]\d\d[2-9]\d{6}$/
    @cid.sub!(/^(\+|00|011)/,'')   # Remove international prefixes, if any

    prs = req.URI.User.split('.')  # parse User into chunks
    @trunk = prs[-2]               # get trunk name
    @user  = prs[-1]               # called user name

    # Check CNAM first. If not found and US number, try to lookup caller's name in Whitepages

    if !(@cname = keys_to_ENUM(CNAM)[@cid]) && @cid =~ /^1([2-9]\d\d[2-9]\d{6})$/ && defined?(WP_key)
      url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Fapi.whitepages.com%2Freverse_phone%2F1.0%2F%3Fphone%3D#{$1}%3Bapi_key%3D#{WP_key}'%20and%20itemPath%3D'wp.listings.listing'&format=json"
      if js = sys.WebGet(url,4).to_s
        @cname, dname, city, state = %w(businessname displayname city state).map {|x| js =~ /"#{x}":"([^"]+)"/; $1}
        @cname ||= dname; @cname ||= "#{city}, #{state}" if city && state
      end
    end

    sys.Log("Caller's number: '#{@cid}'"); sys.Log("Caller's name:   '#{@cname}'") if @cname
    incomingCall()        # forward incoming call

  else                    # Outbound call ...

    # 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.include?(host)   # URI dialing unless host is in our domain list

    callswitch(num)

  end
  sys.Respond(@code,@reason) # Forward error code to ATA
rescue
   # Gives a lot more details at what went wrong (borrowed from Myatus' dialplan)
   sys.Log("** Error: " + $!) unless $!.to_s =~ /Thread was being aborted./
end
Last edited by arampe on Mon Oct 17, 2011 6:38 pm, edited 1 time in total.

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

Re: Help with a Guyana Dial Plan

Post by MikeTelis » Mon Oct 17, 2011 3:54 am

arampe wrote:Thank you mike , a few errors though...
I have copied/pasted this dialplan into my SIP account dialplan to duplicate the problem and I couldn't! Here is what I got:

Code: Select all

NewCall 03:47:19:826 sip1(7784): Executing script dial plan for call to 18686652551.
DialPlan 03:47:19:888 sip1(7784): ** Call from "Mike Telis" <sip:mySIPaccount@sipsorcery.com>;tag=b7168e40 to 18686652551 **
DialPlan 03:47:19:888 sip1(7784): Local time: 10/16/2011 23:47
DialPlan 03:47:19:904 sip1(7784): Number in ENUM format: 18686652551
DialPlan 03:47:20:279 sip1(7784): Calling +1 (868) 665-2551 (Trinidad & Tobago) with SPA3102 at home
DialPlan 03:47:20:279 sip1(7784): Commencing Dial with: 8686652551@pstn.
DialPlan 03:47:20:279 sip1(7784): Attempting to locate a provider for call leg: sip:8686652551@pstn.
DialPlan 03:47:20:279 sip1(7784): ForkCall commencing call leg to sip:8686652551@pstn.
DialPlan 03:47:20:279 sip1(7784): Switching to sip:8686652551@pstn:5060 via udp:69.59.142.213:5060.
DialPlan 03:47:20:279 sip1(7784): SDP on UAC call had RTP socket mangled from 192.168.1.243:8062 to 46.188.18.2:8062.
DialPlan 03:47:21:779 sip1(7784): Response 604 Host pstn unresolvable for sip:8686652551@pstn.
DialPlan 03:47:21:795 sip1(7784): Call failed: code 604, Host pstn unresolvable
DialPlan 03:47:21:795 sip1(7784): UAS call failed with a response status of 604 and Host pstn unresolvable.
DialPlan 03:47:21:795 sip1(7784): Dialplan cleanup for mySIPaccount.
DialPlan 03:47:21:904 sip1(7784): Dial plan execution completed with normal clearing.
As you can see, no complains about uninitialized PSTN object. I believe you did something wrong copying the dialplan into your account dialplan, check it out!

BTW, why don't you enclose the dialplan and console output into Code ... /Code ? It'd make it much more readable :)

Post Reply