Created
September 2, 2016 12:49
-
-
Save moteus/10e795545f40b7c1e3258270a904be8b to your computer and use it in GitHub Desktop.
Add call block number to FusionPBX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- In dialplan | |
-- | |
-- actin set pin_number=123456 | |
-- actin lua add_call_block.lua | |
-- | |
require "resources.functions.split" | |
local Database = require "resources.functions.database" | |
local log = require "resources.functions.log".call_block | |
local api = freeswitch.API() | |
if not session:ready() then return end | |
local domain_name = session:getVariable("domain_name") | |
local domain_uuid = session:getVariable("domain_uuid") | |
local sounds_dir = session:getVariable("sounds_dir") | |
local default_language = session:getVariable("default_language") or 'en' | |
local default_dialect = session:getVariable("default_dialect") or 'us' | |
local default_voice = session:getVariable("default_voice") or 'callie' | |
local pin_number = session:getVariable("pin_number") | |
local sounds_dir_lang = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice | |
session:answer() | |
session:sleep(500) | |
if pin_number and #pin_number > 0 then | |
local max_tries, min_digits, max_digits, digit_timeout = 3, 2, 20, 5000 | |
local authorized = false | |
for i = 1, max_tries do | |
if i > 1 then | |
session:streamFile("phrase:voicemail_fail_auth:#") | |
end | |
session:sleep(500) | |
local digits = session:playAndGetDigits( | |
min_digits, max_digits, max_tries, digit_timeout, | |
"#", "phrase:voicemail_enter_pass:#", "", "\\d+" | |
) | |
local pin_number_table = split(pin_number, "[,;]") | |
for _, pin_number in ipairs(pin_number_table) do | |
if digits == pin_number then | |
session:setVariable("pin_number", pin_number); | |
authorized = true | |
break | |
end | |
end | |
if authorized then break end | |
end | |
if not authorized then | |
session:streamFile("phrase:voicemail_fail_auth:#") | |
session:hangup("NORMAL_CLEARING") | |
return | |
end | |
end | |
local max_tries, min_digits, max_digits, digit_timeout = 3, 3, 20, 5000 | |
local number = session:playAndGetDigits( | |
min_digits, max_digits, max_tries, digit_timeout, "#", | |
sounds_dir_lang .. "/ivr/ivr-enter_destination_telephone_number.wav", "", "\\d+" | |
) | |
if not (number and #number > 0) then | |
--! @todo change audio file | |
session:streamFile("phrase:voicemail_fail_auth:#") | |
session:hangup("NORMAL_CLEARING") | |
return | |
end | |
--! @todo allow select action | |
local call_block_action = 'Reject' | |
local call_block_uuid = api:executeString("create_uuid") | |
--! @todo add extension number who set it | |
local call_block_name = '' | |
local dbh = Database.new('system') | |
local sql = string.format([[ | |
select call_block_uuid from v_call_block where domain_uuid='%s' and call_block_number='%s' | |
]], domain_uuid, number) | |
if not dbh:first_value(sql) then | |
local sql = string.format([[ | |
INSERT INTO v_call_block( | |
domain_uuid, call_block_uuid, call_block_name, call_block_number, call_block_action, | |
date_added, call_block_enabled, call_block_count) | |
VALUES ('%s', '%s', '%s', '%s', '%s', %d, 'true', 0); | |
]], domain_uuid, call_block_uuid, call_block_name, number, call_block_action, os.time()) | |
dbh:query(sql) | |
else | |
--! @todo play info or update number | |
end | |
dbh:release() | |
session:hangup("NORMAL_CLEARING") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment