[Freeswitch-users] Run a LUA script when voicemail received
Steven Schoch
schoch+freeswitch.org at xwin32.com
Fri Jun 3 02:26:00 MSD 2016
I got it working! The goal was to run a script to inform users via a text
message when they get a voicemail.
This script looks for a "vm-notify-sms" param in the user's directory
information. It sends the text from user's outbound caller-ID number, which
is set in the standard FS configuration. I'm using the SMS API from
Flowroute.com.
--[[ This script is called by configuration in
autoload_configs/lua.conf.xml.
It is called on a "vm:maintenance" event.
]]
-- The following is specifc to the Flowroute SMS API,
-- documented at https://developer.flowroute.com/docs/messaging
url = "https://api.flowroute.com/v2/messages"
authentication = "user:password"
action = event:getHeader("VM-Action")
if action ~= "leave-message" then return end
user = event:getHeader("VM-User")
domain = event:getHeader("VM-Domain")
caller_id_name = event:getHeader("VM-Caller-ID-Name")
caller_id_number = event:getHeader("VM-Caller-ID-Number")
--[[ We don't care about these:
file_path = event:getHeader("VM-File-Path")
flags = event:getHeader("VM-Flags")
folder = event:getHeader("VM-Folder")
uuid = event:getHeader("VM-UUID")
--]]
message_len = event:getHeader("VM-Message-Len")
timestamp = event:getHeader("VM-Timestamp")
api = freeswitch.API();
from = api:execute("user_data", user .. "@" .. domain .. " var
outbound_caller_id_number")
to = api:execute("user_data", user .. "@" .. domain .. " param
vm-notify-sms")
if to == "" then return end
if caller_id_name == ''
or caller_id_name == 'UNKNOWN'
or caller_id_name == 'UNASSIGNED'
or caller_id_name == 'WIRELESS CALLER'
or caller_id_name == 'TOLL FREE CALL'
or caller_id_name == 'Anonymous'
or caller_id_name == 'Unavailable'
then caller_id_name = nil end
if caller_id_number == ''
then caller_id_number = nil end
message = "Voicemail "
if caller_id_name
then message = message .. "from " .. caller_id_name .. " (" ..
caller_id_number .. ")"
elseif caller_id_number
then message = message .. "from " .. caller_id_number end
message = message .. " at " .. os.date("%I:%M %p", timestamp)
message = message .. " length " .. message_len .. " seconds"
message = message .. " to box " .. user
message = message .. "."
-- Blindly send the text
data = '{ "to": "' .. to .. '", "from": "' .. from .. '", "body": "' ..
message .. '"}'
--[[
Until either Freeswitch has the ability to pass authentication data
to the mod_curl API (FS-9223), or the Flowroute API has the ability
to take authentication data in the POST body (they are working on it),
we are forced to spawn a shell to use the curl from our OS.
]]
-- api.execute("curl", url .. " auth " .. authentication .. " post " ..
data)
os.execute("curl -u " .. authentication .. " -H 'Content-Type:
application/json' -X POST -d '" .. data .. "' " .. url)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20160602/f644e38e/attachment.html
Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users
mailing list