Scripting tips
There are a few things to keep in mind when working with Lua scripts from the Dialplan:
When a Lua script is finished, the call automatically hangs up. If you wish for the Dialplan to continue processing, be sure to execute
session:setAutoHangup(false)
. Consider the following Dialplan snippet:<condition> <action application="lua" data="my_script.lua"/> <!--the following is not executed unless setAutoHangup is false --> <action application="transfer" data="$1 XML default"/> </condition>
The proper way to exit a Lua script is for the script to run out of commands. As of the previous edition of this publication, there was no explicit command to exit a script; however, you may now use the
error()
function to force the script to terminate. Ifsession:setAutoHangup(false)
has been set, then the Dialplan will continue to process.Keeping the previous point in mind, note that calling
session:bridge()
orsession:transfer()
may not work...