In browsing through the source to mod_curl, I found an option that allows me to use curl without invoking a shell. I made some minor changes to the script, changing the url to this: url = "https://user:password@api.flowroute.com/v2/messages" ... adding some escaping after the message is composed... message = message .. "." -- Add JSON string escapes to the message message = string.gsub(message, "([\\\"'])", "\\%1") ...and using the mod_curl API call to send the text to Flowroute: api:execute("curl", url .. " content-type application/json post '" .. data .. "'") Works, easy, efficient. -- Steve On Thu, Jun 2, 2016 at 3:26 PM, Steven Schoch < schoch+freeswitch.org@xwin32.com> wrote:
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)