After hangup
Let's go to the actual beginning of our main script, welcome.lua
, in the following screenshot:
After including the utils.lua
and LuaRunWeb()
function, we check the env
object.
If env
is a valid object, the script has been called a API Hangup Hook.
The call leg has already been destroyed, so the session object is not valid any more. But we have in env
a copy of all channel variables. In addition to all those variables, we have also the definitive values and the only reliable source of valid accounting timers available via FreeSWITCH scripting (you have all of them via ESL, but that's another chapter).
We repeat: if you want to do accounting from scripting, API Hangup Hook is the only way to have ready-made accurate durations for all call phases.
We use env:getHeader()
to assign some of those values to local variables, then we print it on FreeSWITCH's console as a warning message.
Then we reopen the same filename that was opened, written, and closed the first time this script was run...