[英]Freeswitch: How to determine if call was answered when bridging an inbound and outbound call?
In this implementation, I'm trying to do call patching between an inbound call and a outbound call via the session.bridge()
command. 在此实现中,我试图通过session.bridge()
命令在入站呼叫和出站呼叫之间进行呼叫修补。
I have already received the inbound call and my Python script is playing. 我已经收到入站呼叫,并且正在播放Python脚本。 In this script I'm trying to patch the running call with the numbers in the number_list(list of numbers)
one by one until the list is exhausted or till the call is patched and answered. 在此脚本中,我试图用number_list(list of numbers)
一个接一个地修补正在运行的呼叫,直到列表用完或呼叫被修补并应答为止。
My Code: 我的代码:
for cp_num in connObj.cp_list:
ivr_log.debug("Attempting to dial Call Patch Number:%s"%(cp_num['cp_no']))
connObj.patch_uuid = uuid.uuid1()
cmd_str = """{ignore_early_media=true,execute_on_answer=record_session %s/%s_%s.wav,origination_uuid=%s,originate_timeout=45,script_name=gaadi_test}freetdm/wp4/a/%s"""%(connObj.recording_path,connObj.uuid,connObj.caller_id,connObj.patch_uuid,cp_num['cp_no'])
connObj.bridge(cmd_str) #BRIDGE
connObj.hangup_cause = connObj.getVar("last_bridge_hangup_cause")
if connObj.hangup_cause in ['NORMAL_CLEARING', '']:
connObj.cp_status = "SUCCESS"
return True
connObj.cp_status = "FAILED"
connObj.playback(connObj.path_sound + 'all_reps_busy.wav')
return False
Multiple numbers to the bridge command for sequential dialing. 桥接命令的多个号码用于顺序拨号。 From freeswitch documentation: Multiple endpoints sequential -- no limit to failover number 从freeswitch文档中:多个端点是连续的-故障转移数量没有限制
bridge <target_endpoint>[|<target_endpoint>]
My Implementation 我的实施
cmd1 = """{ignore_early_media=true,originate_timeout=45}[origination_uuid=%s,script_name=gaadi_test]freetdm/wp4/a/%s"""%(connObj.patch_uuid1,connObj.cp_list[0]['cp_no'])
cmd2 = """[origination_uuid=%s,script_name=gaadi_test]freetdm/wp4/a/%s"""%(connObj.patch_uuid2,connObj.cp_list[1]['cp_no'])
cmd = "%s[|%s]"%(cmd3,cmd4)
ivr_log.debug("CMD=%s"%(cmd))
connObj.call_patch_start_time = int(time.time())
connObj.patch_start_datetime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
connObj.bridge(cmd)
PS: ConnObj.bridge(cmd) is working perfect for only one target point. PS:ConnObj.bridge(cmd)只能在一个目标点上完美工作。
Sequential Dialing solution: just a little changes in cmd1 and cmd2. 顺序拨号解决方案:在cmd1和cmd2中仅作一些更改。 I have not confirmed if the origination uuid will be different for both the calls. 我尚未确认两个调用的原始uuid是否会有所不同。
cmd1 = """{ignore_early_media=true,originate_timeout=45,script_name=gaadi_test}[origination_uuid=%s]freetdm/wp4/a/%s"""%(connObj.patch_uuid1,connObj.cp_list[0]['cp_no'])
cmd2 = """[origination_uuid=%s]freetdm/wp4/a/%s"""%(connObj.patch_uuid2,connObj.cp_list[1]['cp_no'])
cmd="%s|%s" #removed the brackets and its working now.
connObj.bridge(cmd)
EDIT: 编辑:
Finally I solved the problem with Stanislav's approach. 最后,我用斯坦尼斯拉夫的方法解决了这个问题。 I used api_on_answer. 我使用了api_on_answer。 On answer I wrote a file on the disk and then checked whether the file was present or not. 在回答时,我在磁盘上写了一个文件,然后检查该文件是否存在。 If the file was present then the call was answered. 如果文件存在,则呼叫已应答。
You can set execute_on_answer
variable to execute a hangup: 您可以设置execute_on_answer
变量来执行挂断:
https://wiki.freeswitch.org/wiki/Variable_execute_on_answer https://wiki.freeswitch.org/wiki/Variable_execute_on_answer
But in general, mod_python
is not the right place for such tasks: the script is executed as a thread inside FreeSWITCH process, and you don;t have any control while a freeSWITCH application is being executed (bridge in your case). 但是总的来说, mod_python
不是执行此类任务的正确位置:脚本是作为FreeSWITCH进程内的一个线程执行的,并且在执行freeSWITCH应用程序时您没有任何控制权(在您的情况下为桥)。 A much better option is to use the event socket library (ESL), and then you can control the call flow asynchronously and receive events that are relevant to call state changes. 更好的选择是使用事件套接字库(ESL),然后可以异步控制调用流并接收与调用状态更改相关的事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.