Skip to main content

Lua Mail on NoAnswer example

About

In this example we show how to test the bridge status and send mail to the destination's owner telling him/her that someone was looking for them.

This assumes that the user has in his directory entry a variable named sendNoans; if it has a valuie of 1 then the user wants such a mail, which is sent to the address in the vm-mailto parameter.

The dial plan

First, you need the following two statements before the bridge command in order to regain control after Bridge fails:

<action application="set" data="hangup_after_bridge=false" />
<action application="set" data="continue_on_fail=true" />

After the Bridge command add the following commands:

<action application="set" data="eml=${user_data(${sip_callee_id_number}@${domain_name} param vm-mailto)}" />
<action application="set" data="sna=${user_data(${sip_callee_id_number}@${domain_name} var sendNoans)}" />
<action application="lua" data="TestNoAns.lua ${originate_disposition} '${caller_id_number}' '${destination_number}' '${sna}' '${eml}' " />

The first two commands sets the parameters, and the last one calls the script to test whether to send Email or not.

The script

-- TestNoAns.lua
-- If destination not answered and has double ring - send mail to yehavi
------------------------------
local disPosition = argv[1] or ''; -- how the call ended
local callee = argv[2] or ''; -- callee number
local dest = argv[3] or ''; -- Destination number
local sna = argv[4] or ''; -- SetNoAnswer
local eml = argv[5] or ''; -- Email
if (disPosition ~= 'SUCCESS') then
if (sna == '1') then
if (eml ~= '') then
os.execute(string.format("/usr/bin/mutt -n -f /dev/null -s \"[%s] got no answer, from [%s]\" %s < /dev/null",callee,dest,eml));
end
end
end