This assumes that Lua is already installed on your system and is configured with FreeSWITCH.

Requirements


Add Voicemail Script in Lua

Here’s the script that does the actual processing. As you may have guessed, load this to /usr/local/freeswitch/scripts and read below for the rest of the configuration needed. Add your user and password in the url section.

--[[     This script is called by configuration in autoload_configs/lua.conf.xml.
     It is called on a "vm:maintenance"event.
]]
-- The following is specific to the Flowroute SMS API,
-- documented at https://developer.flowroute.com/api/messaging/overview/
url = "https://user:password@api.flowroute.com/v2/messages"
action = event:getHeader("VM-Action")
ifaction ~= "leave-message"thenreturnend
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")
ifto == ""thenreturnend
ifcaller_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'
        thencaller_id_name = nil end
ifcaller_id_number == ''
        thencaller_id_number = nil end
message = "Voicemail "
ifcaller_id_name
        thenmessage = message .. "from ".. caller_id_name .. " ("..  caller_id_number .. ")"
        elseif caller_id_number
        thenmessage = message .. "from ".. caller_id_number end
message = message .. " at ".. os.date("%a %H:%M", timestamp)
message = message .. " length ".. message_len .. " seconds"
message = message .. " to box ".. user
message = message .. "."
-- Add JSON string escapes to the message
message = string.gsub(message, "([\\\"'])", "\\%1")
-- Send the text
data = '{ "to": "'.. to .. '", "from": "'.. from .. '", "body": "'.. message .. '"}'
api:execute("curl", url .. " content-type application/json post '".. data .. "'")

            

Enable mod_curl on FreeSWITCH

Edit /usr/src/freeswitch/modules.conf and uncomment applications/mod_curl:

applications/mod_curl
            

Compile FreeSWITCH

Compile FreeSwitch as usual:

#Build FreeSWITCH
make
make install

            

Load mod_curl on Start

Now you will need to have mod_curl load when you start FreeSwitch. Edit /usr/local/freeswitch/conf/autoload_configs/modules.conf.xml:

<load module="mod_curl"/>
            

Uncomment mod_curl and make it look like the above.

Update your default extension

Add the line below to your extension, such as /usr/local/freeswitch/conf/directory/default/1001.xml:

VM Number

<param name="vm-notify-sms"value="1202478xxxx">
            

Be sure to add this within the <params> tag and not <variables>.

This will be the telephone number where you want to receive the alert. Replace it with a legitimate phone number.

In the same file, you will need to consider adding your Flowroute number that you purchased. You must send from a Flowroute phone number that’s associated with your account.

Caller ID

<variable name="outbound_caller_id_number"value="1468856xxxx"/>
            

You can edit /usr/local/freeswitch/conf/vars.xml and have a global caller ID, if desired.

Add Custom Voicemail Event

Add this line to /usr/local/freeswitch/conf/autoload_configs/lua.conf.xml:

<hook event="CUSTOM"subclass="vm::maintenance"script="voicemail-event.lua"/>
            

Ensure this is somewhere between the beginning and ending <settings> tags.

Make a test outbound call

fs_cli to the FreeSWITCH server, make a call and look for something like this after the voicemail is processed:

2016-07-01 04:48:02.930006 [DEBUG] mod_lua.cpp:459 lua event hook: execute ‘voicemail-event.lua’
            

Check the device the SMS was sent to and you’ll see a message like the following:

Voicemail from Extension 1000 (1000) at Fri 04:48 length 6 seconds to box 1001.