Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Add the following to your FreeSWITCH dialpan (change expressions to meet your needs):

Code Block
   <extension name="Page Test">
     <condition field="destination_number" expression="^(3402)$">
      <action application="lua" data="/usr/local/freeswitch/scripts/page_outcall.lua $1"/>
      <action application="set" data="ivr_path=/usr/local/freeswitch/scripts/page_int.php"/>
      <action application="socket" data="127.0.0.1:9097 async full"/>
     </condition>
   </extension>

   <extension name="outbound-socket">
      <condition field="destination_number" expression="^(3403)$">
      <action application="lua" data="/usr/local/freeswitch/scripts/page_time_set.lua"/>
    </condition>
   </extension>

...

Code Block
titlepage_outcall.lua
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","fail2sxppassword123","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")
	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
Code Block
titlepage_time_set.lua
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","fail2sxppassword123","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)
session:hangup()
-- Kill DB
cur:close()
con:close()
env:close()