mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
Add JSON handling (optional) to selfhosted API
This commit is contained in:
@@ -118,12 +118,14 @@
|
||||
end
|
||||
if (transcribe_provider == "selfhosted") then
|
||||
local transcription_server = settings:get('voicemail', 'transcription_server', 'text') or '';
|
||||
local api_key2 = settings:get('voicemail', 'api_key', 'text') or '';
|
||||
local api_key = settings:get('voicemail', 'api_key', 'text') or '';
|
||||
local json_enabled = settings:get('voicemail', 'json_enabled', 'boolean') or "false";
|
||||
if (transcription_server ~= '') then
|
||||
transcribe_cmd = "curl -L " .. transcription_server .. " -F file=@"..file_path
|
||||
transcribe_cmd = "curl -X POST " .. transcription_server .. " -H 'Authorization: Bearer " .. api_key .. "' -F file=@"..file_path
|
||||
local handle = io.popen(transcribe_cmd);
|
||||
local transcribe_result = esc(handle:read("*a"));
|
||||
handle:close();
|
||||
|
||||
if (debug["info"]) then
|
||||
freeswitch.consoleLog("notice", "[voicemail] CMD: " .. transcribe_cmd .. "\n");
|
||||
freeswitch.consoleLog("notice", "[voicemail] RESULT: " .. transcribe_result .. "\n");
|
||||
@@ -133,6 +135,18 @@
|
||||
freeswitch.consoleLog("notice", "[voicemail] TRANSCRIPTION: (null) \n");
|
||||
return ''
|
||||
end
|
||||
if (json_enabled == "true") then
|
||||
local transcribe_json = JSON.decode(transcribe_result);
|
||||
if (transcribe_json["message"] == nil) then
|
||||
freeswitch.consoleLog("notice", "[voicemail] TRANSCRIPTION: " .. transcribe_result .. "\n");
|
||||
transcribe_result = '';
|
||||
end
|
||||
if (transcribe_json["error"] ~= nil) then
|
||||
freeswitch.consoleLog("notice", "[voicemail] TRANSCRIPTION: " .. transcribe_result .. "\n");
|
||||
transcribe_result = '';
|
||||
end
|
||||
transcribe_result = transcribe_json["message"];
|
||||
end
|
||||
return transcribe_result;
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user