package.path = "/usr/local/share/lua/5.2/?.lua"
package.cpath = "/usr/local/lib/lua/5.2/?.so;"
local socket = require "socket"
local http = require "socket.http"
http.TIMEOUT = 10
local ltn12 = require("ltn12")
--智能客服机器人的hashcode
local robothashcode = ""
--能力平台appkey
local appKey = "ac5d5453"
--机器人问答渠道id
local channelId = "1";
local receiverId = 8185
--broker问答地址
local brokerAddress = "http://10.248.17.3:8080/CSRBroker"
--主叫号码
local call_num_link = session:getVariable("caller_id_number")
--被叫号码
local talkerId = session:getVariable("destination_number")
local uuid = argv[1]
math.randomseed(os.time())
--通话的唯一标识
local callUserId = math.random() * 100000000000000
--TTS名称
local ttsName = "ZhuRuiv9"
--用户信息接口
local getCustomerInfo = "http://10.248.17.3:8083/api/customer/basic/getCustomerInfo"
--结果回传接口
local updateUserInfoUrl = "http://10.248.17.3:8083/api/customer/basic/updateResult"
--呼叫开始时间
local startTime = ""
local endTime = ""
--local record_file = session:getVariable("record_file")
--录音文件保存地址
local subdir = os.date("%Y-%m-%d", os.time())
local datestr = session:getVariable("datestr")
local record_file = "/home/data/recordings/archive/renrendai/" .. subdir .. "/" .. call_num_link .. "_" .. datestr .. ".wav"
function printLog(text)
if (text) then
freeswitch.consoleLog("warning", text .. "\n")
else
freeswitch.consoleLog("warning", "object is nil")
end
end
--字符串分隔方法
function string_split(str, split_char)
local sub_str_tab = {};
while (true) do
local pos = string.find(str, split_char);
if (not pos) then
sub_str_tab[#sub_str_tab + 1] = str;
break;
end
local sub_str = string.sub(str, 1, pos - 1);
sub_str_tab[#sub_str_tab + 1] = sub_str;
str = string.sub(str, pos + 1, #str);
end
return sub_str_tab;
end
--分隔主叫号码传递参数
local str_Arr = string_split(call_num_link, "*")
--主叫号码
--local call_num = "15034032390"
local call_num = str_Arr[1]
--业务类型
--local transparam = "7"
local transparam = str_Arr[2]
--local userId = str_Arr[3]
local userId = "20"
--[[
--主叫号码
local call_num = "15034032390"
--业务类型
local transparam = 7
local userId = "20"
--分隔主叫号码传递参数
local str_Arr = string_split(call_num_link, "*")
if(#str_Arr == 3) then
call_num = str_Arr[1]
transparam = str_Arr[2]
userId = str_Arr[3]
end
--]]
freeswitch.consoleLog("warning", "*******************LOG*****************" .. uuid)
freeswitch.consoleLog("warning", "*****************call_num_link:*****************[" .. call_num_link .. "]")
freeswitch.consoleLog("warning", "*****************talkerId:*****************[" .. talkerId .. "]")
callUserId = "renrendai_" .. call_num .. "_" .. math.floor(callUserId)
function parseargs_xml(s)
local arg = {}
string.gsub(s, "(%w+)=([\"'])(.-)%2", function(w, _, a)
arg[w] = a
end)
return arg
end
function parse_xml(s)
local stack = {};
local top = {};
table.insert(stack, top);
local ni, c, label, xarg, empty;
local i, j = 1, 1;
while true do
ni, j, c, label, xarg, empty = string.find(s, "<(%/?)(%w+)(.-)(%/?)>", i);
if not ni then
break
end
local text = string.sub(s, i, ni - 1);
if not string.find(text, "^%s*$") then
table.insert(top, text);
end
if empty == "/" then
table.insert(top, { label = label, xarg = parseargs_xml(xarg), empty = 1 });
elseif c == "" then
top = { label = label, xarg = parseargs_xml(xarg) };
table.insert(stack, top);
else
local toclose = table.remove(stack);
top = stack[#stack];
if #stack < 1 then
error("nothing to close with " .. label);
end
if toclose.label ~= label then
error("trying to close " .. toclose.label .. " with " .. label);
end
table.insert(top, toclose);
end
i = j + 1;
end
local text = string.sub(s, i);
if not string.find(text, "^%s*$") then
table.insert(stack[stack.n], text);
end
if #stack > 1 then
error("unclosed " .. stack[stack.n].label);
end
return stack[1];
end
-- Used to parse the XML results.
function getResults(s)
local xml = parse_xml(s);
local stack = {}
local top = {}
table.insert(stack, top)
top = { grammar = xml[1].xarg.grammar, score = xml[1].xarg.score, text = xml[1][1][1] }
table.insert(stack, top)
return top;
end
local function json2true(str, from, to)
return true, from + 3
end
local function json2false(str, from, to)
return false, from + 4
end
local function json2null(str, from, to)
return nil, from + 3
end
local function json2nan(str, from, to)
return nul, from + 2
end
local numberchars = {
['-'] = true,
['+'] = true,
['.'] = true,
['0'] = true,
['1'] = true,
['2'] = true,
['3'] = true,
['4'] = true,
['5'] = true,
['6'] = true,
['7'] = true,
基于freeswitch1.6的IVR智能语音机器人交互逻辑lua脚本
最新推荐文章于 2025-07-18 15:58:59 发布

本文详细介绍了如何利用freeswitch1.6构建IVR系统,并通过lua脚本实现智能语音机器人的交互逻辑。讨论了lua脚本在语音识别和响应中的应用,以及如何优化交互体验。
最低0.47元/天 解锁文章
2956

被折叠的 条评论
为什么被折叠?



