简体   繁体   English

Freeswitch:在桥接入站和出站呼叫时如何确定呼叫是否已应答?

[英]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.

相关问题 从浏览器拨打电话时,如何以编程方式告知呼叫何时被应答? - When making a call from the browser, how can I tell programmatically when the call has been answered? 在类创建中,未应答函数调用 - In class creation, the function call is not answered 使用套接字测试出站HTTP调用? - Testing an outbound HTTP call with sockets? 如何使用 Twilio 进行出站 SIP 呼叫? - how can I make an outbound SIP call using Twilio? 如何使用 Python 从出站 Twilio 调用中检索信息? - How to retrieve information from outbound Twilio call with Python? Python-入站出站参数 - Python - inbound outbound argument 当第一个号码未使用AWS connect start_outbound_voice_contact API响应时,如何呼叫另一个号码? - How to call another number when the first one is not responding using AWS connect start_outbound_voice_contact API? 本地电脑 python Z319C3206A7F10C957C464FZ twilio API 通话后如何保存入站通话录音 - How will I save inbound call recording after the call from twilio API in the local pc python flask 如何在 twilio 中使用 python 在入站短信中捕获用户没有响应,然后退出入站,然后发送出站短信? - How to capture no response from user in inbound sms with python in twilio to then exit the inbound and then send an outbound sms message? Twilio-如何确定电话会议的时长? - Twilio - How to determine the length of a conference call?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM