require "luasql.postgres"
-- Get caller's SIP URI
sipuri = session:getVariable("sip_from_uri")
-- Connect to DB
env = assert (luasql.postgres())
con = assert (env:connect("conftest","conftest","fail2sxp","localhost"))
cur = assert (con:execute("SELECT sip_uri FROM page_data WHERE sip_uri = '" .. sipuri .. "'"))
row = cur:fetch ({}, "a")
uri_table = {}
i = 1
while row do
uri_table[i] = row.sip_uri
row = cur:fetch(row, "a")
i = i + 1
end
-- WAKE UP! :-)
session:answer()
session:sleep(1000)
-- If user isn't in DB then they don't need to set a timeout, now do they?
if uri_table[1] == nil then
session:streamFile("/usr/local/freeswitch/sounds/en/us/callie/voicemail/16000/vm-that_was_an_invalid_ext.wav")
else
-- Get amount of minutes user wants to be on timeout for
digits = session:playAndGetDigits(1, 2, 1, 3000, "#", "/usr/local/freeswitch/sounds/tones/enter-minutes.wav", "/usr/local/freeswitch/sounds/en/us/callie/voicemail/16000/vm-abort.wav", ".+")
end
-- Get current epoch
today = os.time()
-- If user doesn't enter anything then why continue?
if tonumber(digits) == nil then
session:hangup()
-- Update DB, split out at 20 to make file playback easier
elseif tonumber(digits) < 20 then
new_time = today + (tonumber(digits) * 60)
session:streamFile("/usr/local/freeswitch/sounds/en/us/callie/digits/16000/" .. digits .. ".wav")
session:streamFile("/usr/local/freeswitch/sounds/en/us/callie/time/16000/minutes.wav")
res = assert (con:execute("UPDATE page_data SET page_timeout=to_timestamp(" .. new_time .. ") WHERE sip_uri = '" .. sipuri .. "'"))
else
new_time = today + (tonumber(digits) * 60)
digsplit = {}
for dig in digits:gmatch("%d") do table.insert(digsplit, dig) end
session:streamFile("/usr/local/freeswitch/sounds/en/us/callie/digits/16000/" .. digsplit[1] .. "0.wav")
session:streamFile("/usr/local/freeswitch/sounds/en/us/callie/digits/16000/" .. digsplit[2] .. ".wav")
session:streamFile("/usr/local/freeswitch/sounds/en/us/callie/time/16000/minutes.wav")
res = assert (con:execute("UPDATE page_data SET page_timeout=to_timestamp(" .. new_time .. ") WHERE sip_uri = '" .. sipuri .. "'"))
end
session:sleep(500) |