...
Code Block | ||
---|---|---|
| ||
require "luasql.postgres"
-- Exit if no argument
if argv[1] == nil then
print ("One argument is required")
os.exit(0)
end
-- Get current epoch
today = os.time()
-- Connect to DB, get page info
env = assert (luasql.postgres())
con = assert (env:connect("conftest","conftest","password123","localhost"))
cur = assert (con:execute("SELECT entry_id, page_group, sip_uri, extract(epoch FROM page_timeout) FROM page_data WHERE page_group = " .. argv[1]))
row = cur:fetch ({}, "a")
page_table = {}
i = 1
-- iterate through list of extensions to be paged and discard those on timeout
while row do
if tonumber(row.date_part) > today then
print ("Skipping")
-- keeps system from paging the pager :-P
elseif row.sip_uri == sipuri then
print ("Skipping")
else
page_table[i] = row.sip_uri
end
row = cur:fetch(row, "a")
i = i + 1
end
-- Close DB connection as we won't be needing it anymore
cur:close()
con:close()
env:close()
session:answer()
cidname = session:getVariable("caller_id_name")
session:execute("export", "sip_invite_params=intercom=true")
session:execute("export", "sip_auto_answer=true")
session:execute("set", "conference_auto_outcall_caller_id_name=Page From " .. cidname)
session:execute("set", "conference_auto_outcall_caller_id_number=" .. argv[1])
session:execute("set", "conference_auto_outcall_timeout=60")
-- Make the calls
for i,v in pairs (page_table) do
session:execute("conference_set_auto_outcall", "{alert_info=sipXpage}sofia/custom_dialplan/" .. v .. ";sipx-noroute=VoiceMail;sipx-userforward=false+flags")
end
|
...