How to count the duration of call? When a user join 3200 and wait for 10 seconds and nobody yet joined, 3200 then i want to play audio file.
But how do i count the duration any idea please? I have tried following but its not working cause it only triggers after the call hang up. but i need the counter starts when call was started.
/usr/local/freeswitch/script/wait.py
import os
from freeswitch import *
def hangup_hook(session, what):
consoleLog("info","hangup hook for %s!!\n\n" % what)
return
def input_callback(session, what, obj):
if (what == "dtmf"):
consoleLog("info", what + " " + obj.digit + "\n")
else:
consoleLog("info", what + " " + obj.serialize() + "\n")
return "pause"
def handler(session, args):
new_api_obj = API()
new_api_obj.executeString("pyrun postprocessing " + session.getVariable('caller_id_number'))
session.answer()
session.setHangupHook(hangup_hook)
session.setInputCallback(input_callback)
session.execute("conference", "$1-${domain_name}@ultrawideband")
session.hangup()
/usr/local/freeswitch/script/postprocessing.py
import os, sys, time
from freeswitch import *
def runtime(arg1):
time.sleep(10)
# is there 2 person or 1 person?
# if 1 person after 10 second play
#session.streamFile("/var/tmp/ivr/sara4.wav")
# if 2 person after 10 second do nothing
consoleLog( "info", "Caller: %s hung up 10s ago!\n" % arg1 )
Now the postprocessing.py is running when the call end