Javascript Example - set hook
Illustrates how to set a hook.
Click here to expand Table of Contents
playFileWithHangupHook.js
function on_hangup(hup_session, how)
{
console_log("err", how + " HOOK" + " name: " + hup_session.name + " cause: " + hup_session.cause + "\n");
//exit here would end the script so you could cleanup and just be done
exit();
}
//set the on_hangup function to be called when this session is hungup
session.setHangupHook(on_hangup);
function onPlayFile(s, type, obj, arg)
{
try {
if (type == "dtmf") {
console_log("info", "DTMF digit: " + s.name + " [" + obj.digit + "] len [" + obj.duration + "]\n\n");
session.execute("phrase", "spell," + obj.digit);
}
} catch (e) {
console_log("err", e + "\n");
}
return true;
}
session.answer();
while(session.ready()) {
session.streamFile("/ram/swimp.raw", onPlayFile);
}