http cli的原理是cti模块实现了一个http server 接收http get请求,执行FreeSWITCH命令后把执行结果返回给http client,常用的使用场景包含http接口实现挂断指定的通话,http接口实现点击拨号(先呼叫坐席电话,座席接听后再呼叫客户电话),以及监听,强插,转接电话等功能。
cti.conf.xml http_cli节点就是配置http server监听的IP和端口,以及接口的KEY。
例子 http://ip:88/cli?cmd=log&arg=测试&key=abc
每个字段都要求url编码,支持各种URL编码格式。
最基本的例子呼叫分机1000,分机1000接听后,听到自己声音
key = abc
cmd = bgapi
arg = originate user/1000 &echo
http://127.0.0.1:88/cli?key=abc&cmd=bgapi&arg=originate user/1000 &echo
URL编码后(对arg=后面参数进行url编码)
http://127.0.0.1:88/cli?key=abc&cmd=bgapi&arg=originate+user%2f1000+%26echo
先呼叫分机user/121,分机应答后,再使用线路组default呼叫手机 5555
呼叫分机使用主叫clicktocall,呼叫手机使用主叫121,并且手机接听后开始录音
http://127.0.0.1:88/cli?key=abc&cmd=bgapi&arg=cti_originate {origination_caller_id_number=clicktocall,origination_nested_vars=true,execute_on_answer_set_record_filename='export record_filename=$${recordings_dir}/${strftime(%Y-%m-%d)}/${uuid}.wav'}user/121 &bridge({origination_caller_id_number=121,execute_on_answer_start_record='record_session \${record_filename}'}linegroup/default/5555)
URL编码后
http://127.0.0.1:88/cli?key=abc&cmd=bgapi&arg=cti_originate%20%7Borigination_caller_id_number%3Dclicktocall%2Corigination_nested_vars%3Dtrue%2Cexecute_on_answer_set_record_filename%3D%27export%20record_filename%3D%24%24%7Brecordings_dir%7D%2F%24%7Bstrftime(%25Y-%25m-%25d)%7D%2F%24%7Buuid%7D.wav%27%7Duser%2F121%20%26bridge(%7Borigination_caller_id_number%3D121%2Cexecute_on_answer_start_record%3D%27record_session%20%5C%24%7Brecord_filename%7D%27%7Dlinegroup%2Fdefault%2F5555)
如果需要分机应答就开始录音
http://127.0.0.1:88/cli?key=abc&cmd=bgapi&arg=cti_originate {origination_caller_id_number=clicktocall}user/121 export:record_filename=$${recordings_dir}/${strftime(%Y-%m-%d)}/${uuid}.wav,record_session:${record_filename},bridge:{origination_caller_id_number=121}linegroup/default/1380000000 inline
URL编码后
http://127.0.0.1:88/cli?key=abc&cmd=bgapi&arg=cti_originate%20%7Borigination_caller_id_number%3Dclicktocall%7Duser%2F121%20export%3Arecord_filename%3D%24%24%7Brecordings_dir%7D%2F%24%7Bstrftime(%25Y-%25m-%25d)%7D%2F%24%7Buuid%7D.wav%2Crecord_session%3A%24%7Brecord_filename%7D%2Cbridge%3A%7Borigination_caller_id_number%3D121%7Dlinegroup%2Fdefault%2F1380000000%20inline
http://127.0.0.1:88/cli?key=abc&cmd=bgapi&arg=cti_originate+{origination_nested_vars=true,instant_ringback=true,transfer_ringback=声音文件路径,origination_caller_id_number=9999}user/1000 &bridge({origination_caller_id_number=1000,execute_on_answer='record_session /fs/recording/20220624144610983/100000102896000118380317308.wav',ignore_early_media=true}linegroup/default/138000000)
arg的格式是 cti_originate空格{呼叫分机的变量}拨号串空格&bridge({呼叫手机的变量}拨号串)
例子: cti_originate {var=val}usr/分机号 &bridge({var=val}sofia/external/手机号@落地IP)
注意:
如果先呼叫分机后呼叫手机,变量要分开设置,不要把呼叫手机用的变量设置到呼叫分机去了。
拨号串格式
参数说明
nolocal:
例子:{nolocal:sip_h_X-AutoAccept=true,export_vars=‘nolocal:sip_h_X-AutoAccept’}http://127.0.0.1:88/cli?cmd=bgapi&arg=cti_originate {ignore_early_media=true,origination_caller_id_number=1390000000,话术变量=话术变量的值}user/1000 'cti_robot:话术,set:park_timeout=3600,park' inline
http://127.0.0.1:88/cli?cmd=bgapi&arg=cti_originate {ignore_early_media=true,origination_caller_id_number=1390000000,话术变量=话术变量的值}linegroup/线路组/号码 'cti_robot:话术,set:park_timeout=3600,park' inline
http://127.0.0.1:88/cli?cmd=bgapi&arg=cti_originate {ignore_early_media=true,origination_caller_id_number=1390000000}sofia/external/1380000000@vosIP &playback(声音文件路径)
http://127.0.0.1:88/cli?key=123456&cmd=bgapi&arg=cti_originate {ignore_early_media=true,origination_caller_id_number=1390000000}sofia/external/[email protected]:6066 'playback:file_string://http://ip/uploads/audio/20200526/getaudio493c5/202005261100135ecc863db4775.wav' inline
http://127.0.0.1:88/cli?cmd=bgapi&arg=cti_originate {ignore_early_media=true,origination_caller_id_number=1390000000}sofia/external/1380000000@vosIP &playback(file_string://文件1.wav!文件2.wav)
http://127.0.0.1:88/cli?key=abc&cmd=bgapi&arg=cti_originate {ignore_early_media=true,origination_caller_id_number=1390000000}user/123 'playback:file_string://http://127.0.0.1:9989/tts?text=这个测试是放音文字转语音测试' inline
http://ip:88/cli?key=key&cmd=uuid_broadcast&arg=uuid 放音文件 放音方式
UUID: 通话的UUID
声音文件: 可以是FS服务器的本地文件,也可以是http连接的wav文件(8K16bit单声道)。
放音方式: [aleg|bleg|holdb|both] aleg 对A端放音,bleg对B段放音, holdb b端口播放hold, both双端放音, 不设置A端放音B端播放hold
例子
http://down.ddrj.com:88/cli?key=abc&cmd=uuid_broadcast&arg=b2961087-c353-45f6-a50e-1fd957e23fec http://127.0.0.1:9989/tts?text=这个测试是放音文字转语音测试 both
http://ip:88/cli?key=key&cmd=uuid_cti_background&arg=uuid 放音文件 放音方式