My Callback script with automatic provider selection

Catalog of dial plans
Post Reply
jvwelzen
Posts: 716
Joined: Thu Sep 11, 2008 1:56 pm

My Callback script with automatic provider selection

Post by jvwelzen » Sat Aug 29, 2009 1:18 pm

Hi all

I made a callback script with automatic provider selection

It's based on the flexibel controled dialplan from Mike Telis :D

the only thing that does not work is callbacks to sip uri's

EDIT :

Sip Uri Calling is also working now (tested it with my provider budgetphone)

But with betamax it's not working (I tested it with poivy but the poivy client doesn't accept the call because of sound problems, maybe if you use an ata it will work didn't test this)

Code: Select all

Speeddial = { 
 '100' => '9991428711@sip.tropo.com', 
 '101' => '9991428726@sip.tropo.com', 
 '102' => '9991428737@sip.tropo.com', 
 '103' => '9991428728@sip.tropo.com', 
 "1233" => "555@budgetphone-#{sys.Username}" #2 
} 

VSPtab = { 
  '0' => "00001@voicetrading-#{sys.Username}", 
  '1' => "00@voicetrading-#{sys.Username}", 
  '2' => "00000@voicetrading-#{sys.Username}", 
  '3' => "@xs4all-#{sys.Username}", 
  '4' => "@budgetphone-#{sys.Username}", 
  '5' => "@sip.huizenwireless.nl", 
  '6' => "@huizenwireless.nl", 
  '7' => "883510@huizenwireless.nl", 
  '8' => "@81.201.82.50:5060", 
} 

def selectVSP 
  case @num  

    when /^883/ 
       route(8,"Call to Inum services") 

    when /^444$/ 
       route(4,"Call to Budgetphone services") 

when /^31(800)/, 
         /^0(800)/ 
      route(3,"Destination -  NL toll free") 

when /^31(6)/, 
         /^0(6)/ 
      route(0,"Destination -  NL Mobile") 

when /^31(900)/, 
         /^0(900)/ 
      route(0,"Destination -  NL Premium") 

when /^31/, 
         /^0/ 
      route(0,"Destination -  NL Landline") 

    when /(^1([2-9]\d\d)\d{7,7})/ 
      @num = $1 
      case $2 
        when "800", "866", "877", "888" 
          route("0","Destination - US toll free") 
        else 
          route(0,"Destination - Netherlands") 
      end 

    else 
      route(0,"Default route applied") 
  end 
end 

def callswitch(num,*args) 
  route  

  @num = num unless @num = Speeddial[num] 

  unless @num =~ /@/  

    @num.gsub!(/[^0-9*+]/,'')  

   unless @num.sub!(/^(\+|00|011|810)/,'') 
      case @num 
  
         when /^0(\d{9,9})$/ 
           @num = '31' + $1 

         when /^[1-9]\d{9,9}$/ 
           @num = '31' + @num    

      end 
    end 

    if @p.empty?      

      route  
      selectVSP    

    end 
  end    

  dial(*args) 
end  

def dial(*args) 
  sys.Log(@l) unless @l.empty? 
  if tpl=VSPtab[@p.to_s]  
    @num = tpl.sub(/\s*@\s*/) {|x| @num+'@'} 
  end 
  #sys.Dial(@num,*args) 
  sys.Callback("#{sys.Username}@local", @num,*args) 
  status()              
  sys.Log("Call failed: code #{@code}, #{@reason}") 
  sys.Respond(@code,@reason) 
end 

def route(p='', l='') 
  @p = p; @l = l 
end 

def status 
  if (ptr = sys.LastDialled[0]).nil? 
    @code = 487; @reason = 'Geannuleerd door Huizen Wireless' 
  else 
    ptr = ptr.TransactionFinalResponse 
    @code = ptr.StatusCode; @reason = ptr.ReasonPhrase  
  end 
end 

    num = req.URI.User.to_s; reqHost = req.URI.Host.to_s 

    host = reqHost.downcase.slice(/[^:]+/)  

    num << '@' << reqHost unless Domains.find {|x| x == host} 

    num = num.sub(/(@sipsorcery.com)/, '') 

    callswitch(num) 

Post Reply