Improve ring_member.lua with consistent indentation, notes, and more if session:ready to prevent errors.

This commit is contained in:
markjcrane 2016-01-02 13:09:28 -07:00
parent 8512ba0182
commit 89b2da603f
1 changed files with 62 additions and 53 deletions

View File

@ -16,7 +16,7 @@
--
-- The Initial Developer of the Original Code is
-- Mark J Crane <markjcrane@fusionpbx.com>
-- Copyright (C) 2010
-- Copyright (C) 2010-2016
-- All Rights Reserved.
--
-- Contributor(s):
@ -30,13 +30,14 @@
require "resources.functions.database_handle";
dbh = database_handle('system');
--set default variables
sounds_dir = "";
recordings_dir = "";
pin_number = "";
max_tries = "3";
digit_timeout = "3000";
--define uuid function
local random = math.random
local function uuid()
local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
@ -46,6 +47,7 @@ local function uuid()
end)
end
--get session variables
if (session:ready()) then
session:answer();
--session:execute("info", "");
@ -53,7 +55,10 @@ if ( session:ready() ) then
pin_number = session:getVariable("pin_number");
sounds_dir = session:getVariable("sounds_dir");
ring_group_uuid = session:getVariable("ring_group_uuid");
end
--get the domain uuid and set other required variables
if (session:ready()) then
--get info for the ring group
sql = "SELECT * FROM v_ring_groups ";
sql = sql .. "where ring_group_uuid = '"..ring_group_uuid.."' ";
@ -64,17 +69,19 @@ if ( session:ready() ) then
destination_timeout = 15;
destination_delay = 0;
--create the primary key uuid
ring_group_destination_uuid = uuid();
end
--pin number is not required
--press 1 to login and 2 to logout
if (session:ready()) then
menu_selection = session:playAndGetDigits(1, 1, max_tries, digit_timeout, "#", "ivr/ivr-enter_destination_telephone_number.wav", "", "\\d+");
freeswitch.consoleLog("NOTICE", "menu_selection: "..menu_selection.."\n");
if (menu_selection == "1") then
--first, check to see if is already in that ring group
--first, check to see if the destination is already in this ring group
sql = [[
SELECT COUNT(*) AS in_group FROM
v_ring_group_destinations
@ -83,7 +90,6 @@ if ( session:ready() ) then
AND ring_group_uuid = ']]..ring_group_uuid..[['
AND destination_number = ']]..destination_number..[['
]];
--freeswitch.consoleLog("NOTICE", "ring_group_member: SQL "..sql.."\n");
assert(dbh:query(sql, function(row)
@ -119,7 +125,6 @@ if ( session:ready() ) then
end
end));
end
if (menu_selection == "2") then
sql = [[
@ -136,10 +141,14 @@ if ( session:ready() ) then
freeswitch.consoleLog("NOTICE", "ring_group_member: LOG OUT\n");
session:streamFile("ivr/ivr-you_are_now_logged_out.wav");
end
end
--wait for the file to be written before proceeding
if (session:ready()) then
--session:sleep(1000);
end
--hangup
if (session:ready()) then
session:hangup();
end