import os import re import sys from freeswitch import * import logging,sys _REVISION_ = "$Revision: 1891 $" # HANGUP HOOK # # session is a session object # what is "hangup" or "transfer" # if you pass an extra arg to setInputCallback then append 'arg' to get that value # def hangup_hook(session, what, arg): def hangup_hook(session, what): consoleLog("INFO", "hangup hook for %s!!\n\n" % what) return # INPUT CALLBACK # # session is a session object # what is "dtmf" or "event" # obj is a dtmf object or an event object depending on the 'what' var. # if you pass an extra arg to setInputCallback then append 'arg' to get that value # def input_callback(session, what, obj, arg): def input_callback(session, what, obj): if (what == "dtmf"): consoleLog("INFO", what + " " + obj.digit + "\n") else: consoleLog("INFO", what + " " + obj.serialize() + "\n") return "pause" # APPLICATION # # default name for apps is "handler" it can be overridden with :: # session is a session object # args is all the args passed after the module name def handler(session, args): # try: session.setHangupHook(hangup_hook) session.setInputCallback(input_callback) destination_extension = int(session.getVariable("dialed_extension")) caller_number = session.getVariable("caller_id_number") domain = session.getVariable("domain_name") consoleLog("INFO", "TEST: Destination-extension "+str(destination_extension)+"\n") session.execute("set","continue_on_fail=true") session.execute("set","hangup_after_bridge=true") uuid = session.getVariable("uuid") consoleLog("WARNING", "TEST 1 for UUID "+str(uuid)+", src "+str(caller_number)+" dest "+str(destination_extension)+"\n") session.execute("sleep","1000") consoleLog("WARNING", "TEST 2 for UUID "+str(uuid)+", src "+str(caller_number)+" dest "+str(destination_extension)+"\n") session.execute("sleep","1000") consoleLog("WARNING", "TEST 3 for UUID "+str(uuid)+", src "+str(caller_number)+" dest "+str(destination_extension)+"\n") session.execute("sleep","1000") session.execute('info') session.execute("bridge","[leg_timeout=%s][origination_caller_id_number=%s]user/%s@${domain_name}" % ('15',str(caller_number), str(destination_extension))) session.execute('info') originate_disposition = session.getVariable("originate_disposition") consoleLog("WARNING", "TEST X for UUID "+str(uuid)+", src "+str(caller_number)+" dest "+str(destination_extension)+"\n") consoleLog("WARNING", "TEST: Originate Disposition after bridge is "+str(originate_disposition)+"\n") #if originate_disposition == "PICKED_OFF" or originate_disposition == "ORIGINATOR_CANCEL" or\ # originate_disposition == "SUCCESS": #or originate_disposition == 'ATTENDED_TRANSFER' or \ # #originate_disposition == 'BLIND_TRANSFER': # consoleLog("WARNING", "Sending call to park\n") # session.execute("park") #else: consoleLog("WARNING", "TEST 4 for UUID "+str(uuid)+", src "+str(caller_number)+" dest "+str(destination_extension)+"\n") session.execute("sleep","1000") consoleLog("WARNING", "TEST 5 for UUID "+str(uuid)+", src "+str(caller_number)+" dest "+str(destination_extension)+"\n") session.execute("sleep","1000") consoleLog("WARNING", "TEST 6 for UUID "+str(uuid)+", src "+str(caller_number)+" dest "+str(destination_extension)+"\n") session.execute("sleep","1000") # FSAPI CALL FROM CLI, DP HTTP etc # # default name for python FSAPI is "fsapi" it can be overridden with :: # stream is a switch_stream, anything written with stream.write() is returned to the caller # env is a switch_event # args is all the args passed after the module name # session is a session object when called from the dial plan or the string "na" when not. def fsapi(session, stream, env, args): stream.write("w00t!\n" + env.serialize()) # RUN A FUNCTION IN A THREAD # # default name for pyrun is "runtime" it can be overridden with :: # args is all the args passed after the module name def runtime(args): print args + "\n"