FreeSWITCH 拨号脚本之public.xml

#!/usr/bin/lua --Author:jncheng --Version:20150520 --Email:butte@sina.com ---------------------------------------------------------------------------------------- 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,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

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念