FreeSWITCH 拨号脚本之public.xml

#!/usr/bin/lua 
 
--Author:jncheng
--Version:20150520
--Email:[email protected]


----------------------------------------------------------------------------------------
session:setVariable("continue_on_fail","USER_BUSY,NO_ANSWER,TIMEOUT,NO_USER_RESPONSE")
--get the dial extension number
exten = session:getVariable("destination_number")
exten_len=string.len(exten)
fs_ivr_dir = "/usr/local/freeswitch/sounds"
cai_lin = fs_ivr_dir.."/ring.wav"
session:setVariable("ringback",cai_lin)
--session:setVariable("effective_caller_id_name",src_exten)


if (exten_len == 4) then
 --Connect the local MySQL database(DBname,User,Password)
 --local dbh = freeswitch.Dbh("test","fs","123qwe")
 --Connect the ODBC DSN Database(odbcsourcename:Username:Passwod),in odbc.ini
 local dbh = freeswitch.Dbh("odbc://fs:fs:123qwe")
 assert(dbh:connected())
 --Get the SIP User's Dial string
 dbh:query("select url from registrations where reg_user="..exten,function(row)
       --freeswitch.consoleLog("NOTICE","------------------------------------------")
       --freeswitch.consoleLog("NOTICE",string.format("%s\n",row.url))
       --freeswitch.consoleLog("NOTICE","------------------------------------------")
       exten_url = string.format("%s",row.url)
 end);
 --If the user not registration,answer the call,and tell the user call net called
 if (exten_url == nil) then
     session:answer()
     session:sleep(2000)
     session:streamFile(fs_ivr_dir.."/dialed_again.wav")
     session:sleep(2000)
     session:hangup()
 else
     ---define the split string function,to get the dial string.Not write by me ,From internet
     function Split(szFullString, szSeparator)  
     local nFindStartIndex = 1  
     local nSplitIndex = 1  
     local nSplitArray = {}  
     while true do  
       local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)  
       if not nFindLastIndex then  
         nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))  
       break  
       end  
       nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)  
       nFindStartIndex = nFindLastIndex + string.len(szSeparator)  
       nSplitIndex = nSplitIndex + 1  
     end  
     return nSplitArray  
     end  
     local list = Split(exten_url,";")
     local str_url = list[1]
     session:execute("bridge",str_url)
 --Add tell why not scueefull bridge
 session:answer()
     local fail_cause=session:getVariable("originate_disposition")
 session:streamFile(fs_ivr_dir.."/"..fail_cause..".wav")
 session:sleep(2000)
     session:hangup()
 end
--if the dial length is not 4 ,tell check the number
else
 session:answer()
 session:setVariable("call_time_out","20")
 session:sleep(2000)
 session:streamFile(fs_ivr_dir.."/check_number.wav")
 session:sleep(2000)
 session:hangup()
end


你可能感兴趣的:(lua,freeswitch)