Building voice applications
Now that we have covered the basic Lua syntax, let's create a simple Lua script and the corresponding entry in the Dialplan. First, create a new Dialplan extension that will execute the Lua script when a user dials 9910:
Open the
01_Custom.xml
file that we created in Chapter 5, Understanding the XML Dialplan, and add the following new extension:<extension name="Simple Lua Test"> <condition field="destination_number" expression="^(9910)$"> <action application="lua" data="test1.lua"/> </condition> </extension>
Save the file. Launch
fs_cli
and issuereload_xml
,or press F6.
Our Dialplan is now ready to call the Lua script named test1.lua
. Create this new script as follows:
Using your text editor, create
test1.lua
in thefreeswitch/scripts/
directory and add the following lines:-- test1.lua -- Answer call, play a prompt, hangup -- Set the path separator pathsep = '/' -- Windows users do this instead: -- pathsep = '\' --Answer the...