Browse Source

Merge branch 'dev_transfer_20241123' of ssh://gitlab.fuxicarbon.com:1111/client_service/voice-gateway-service into dev_transfer_20241123

余尚辉 4 months ago
parent
commit
a30fbb3a94

+ 2 - 2
src/core/callcenter/cache.py

@@ -76,8 +76,8 @@ def get_call_info(call_id):
     text = None
     if call_id:
         text = redis_handler.get(CALL_INFO + call_id)
-        print('get_call_info', call_id, text)
-        sys.stdout.flush()  # 强制刷新输出缓冲区
+        # print('get_call_info', call_id, text)
+        # sys.stdout.flush()  # 强制刷新输出缓冲区
     if text:
         return CallInfo.from_json(text)
 

+ 86 - 69
src/core/callcenter/esl/handler/channel_hangup_handler.py

@@ -2,6 +2,9 @@
 # encoding:utf-8
 
 import json
+import sys
+import traceback
+
 import src.core.callcenter.cache as Cache
 from src.core.callcenter.acd import AcdService
 from src.core.callcenter.call import CallService
@@ -23,77 +26,91 @@ class ChannelHangupHandler(EslEventHandler):
         self.call_service = CallService(inbound_client, logger)
 
     def handle(self, address, event, coreUUID):
-        self.logger.info(json.loads(event.serialize('json')))
-        call_id = EslEventUtil.getCallId(event)
-        if not call_id:
-            self.release(event)
-            self.logger.info("call_id is null")
-            return
-        call = Cache.get_call_info(call_id)
-        if not call:
-            self.logger.info("call:%s is null", call_id)
-            return
-        device_id = EslEventUtil.getDeviceId(event)
-        device = call.device_info_map.get(device_id)
-        if not device:
-            self.logger.info("device:%s is null", device_id)
-            return
-
-        count = len(call.device_list)
-        self.logger.info('hangup, call_id=%s, device_id=%s, count=%s', call_id, device_id, count)
+        print(json.loads(event.serialize('json')))
         try:
-            call.device_list.remove(device_id)
-        except:
-            pass
-        cause = EslEventUtil.getCallHangupCause(event)
-        caller = EslEventUtil.getCallerCallerIdNumber(event)
-        called = EslEventUtil.getCallerDestinationNumber(event)
-        sip_status = EslEventUtil.getSipStatus(event)
-        sip_protocol = EslEventUtil.getSipProtocol(event)
-        rtp_use_codec = EslEventUtil.getRtpUseCodec(event)
-        channel_name = EslEventUtil.getCallerChannelName(event)
-        timestamp = EslEventUtil.getEventDateTimestamp(event)
-        hangup_cause = EslEventUtil.getVariableSipHPLIBRAHangupCause(event)
-        hangup_reason = EslEventUtil.getLIBRAHangupReason(event)
-
-        device.hangup_cause = cause
-        device.sip_protocol = sip_protocol
-        device.sip_status = sip_status
-        device.channel_name = channel_name
-        device.end_time = timestamp
-
-        # 计算通话时长
-        if device.answer_time:
-            device.talk_time = int(device.end_time) - int(device.answer_time)
-        else:
-            device.ring_start_time = device.end_time
-        # 计算录音时长
-        if device.record_start_time:
-            device.record_time = int(device.end_time) - int(device.record_start_time)
-        call.device_info_map[device.device_id] = device
-
-        # 如果是转人工
-        if 'transferToAgent' == hangup_reason and DeviceType.ROBOT.code == device.device_type:
-            call.answer_flag = AnswerFlag.TRANSFER_TO_AGENT.code
-            service_id = EslEventUtil.getLIBRAServiceId(event)
+            call_id = EslEventUtil.getCallId(event)
+            print('call_id is ', call_id)
+            sys.stdout.flush()  # 强制刷新输出缓冲区
+            if not call_id:
+                self.release(event)
+                print("call_id is null")
+                return
+            call = Cache.get_call_info(call_id)
+            print('call_info is ', call)
+            sys.stdout.flush()  # 强制刷新输出缓冲区
+            if not call:
+                print("call:%s is null", call_id)
+                return
+            device_id = EslEventUtil.getDeviceId(event)
+            device = call.device_info_map.get(device_id)
+            print('device_id is ', device_id)
+            sys.stdout.flush()  # 强制刷新输出缓冲区
+            if not device:
+                print("device:%s is null", device_id)
+                return
+
+            count = len(call.device_list)
+            print('ChannelHangupHandler, call_id=%s, device_id=%s, count=%s'% (call_id, device_id, count))
+            sys.stdout.flush()  # 强制刷新输出缓冲区
+            try:
+                call.device_list.remove(device_id)
+            except:
+                pass
+            cause = EslEventUtil.getCallHangupCause(event)
+            caller = EslEventUtil.getCallerCallerIdNumber(event)
+            called = EslEventUtil.getCallerDestinationNumber(event)
+            sip_status = EslEventUtil.getSipStatus(event)
+            sip_protocol = EslEventUtil.getSipProtocol(event)
+            rtp_use_codec = EslEventUtil.getRtpUseCodec(event)
+            channel_name = EslEventUtil.getCallerChannelName(event)
+            timestamp = EslEventUtil.getEventDateTimestamp(event)
+            hangup_cause = EslEventUtil.getVariableSipHPLIBRAHangupCause(event)
+            hangup_reason = EslEventUtil.getLIBRAHangupReason(event)
+
+            device.hangup_cause = cause
+            device.sip_protocol = sip_protocol
+            device.sip_status = sip_status
+            device.channel_name = channel_name
+            device.end_time = timestamp
+
+            # 计算通话时长
+            if device.answer_time:
+                device.talk_time = int(device.end_time) - int(device.answer_time)
+            else:
+                device.ring_start_time = device.end_time
+            # 计算录音时长
+            if device.record_start_time:
+                device.record_time = int(device.end_time) - int(device.record_start_time)
+            call.device_info_map[device.device_id] = device
+            print('ChannelHangupHandler, hangup_reason=%s, device_type=%s' % (hangup_reason, device.device_type))
+            # 如果是转人工
+            sys.stdout.flush()  # 强制刷新输出缓冲区
+            if 'transferToAgent' == hangup_reason and DeviceType.ROBOT.code == device.device_type:
+                call.answer_flag = AnswerFlag.TRANSFER_TO_AGENT.code
+                service_id = EslEventUtil.getLIBRAServiceId(event)
+                Cache.add_call_info(call)
+                self.acd_service.transfer_to_agent(call, device, service_id)
+                sys.stdout.flush()  # 强制刷新输出缓冲区
+                return
+
+            # 如果有下一步
+            next_command = call.next_commands[0] if len(call.next_commands) > 0 else None
+            if next_command:
+                self.next_cmd(call, device, next_command, cause)
+                sys.stdout.flush()  # 强制刷新输出缓冲区
+                return
+
+            # 一般情况下,挂断其他所有设备
+            if device.cdr_type <= 4 and not call.end_time:
+                call.end_time = device.end_time
+                self.call_service.hangup_all(call, CallCause.HANGUP_EVENT)
+
+            # 判断挂机方向 && 更新缓存
+            self.hangup_dir(call, device, cause)
             Cache.add_call_info(call)
-            self.acd_service.transfer_to_agent(call, device, service_id)
-            return
-
-        # 如果有下一步
-        next_command = call.next_commands[0] if len(call.next_commands) > 0 else None
-        if next_command:
-            self.next_cmd(call, device, next_command, cause)
-            return
-
-        # 一般情况下,挂断其他所有设备
-        if device.cdr_type <= 4 and not call.end_time:
-            call.end_time = device.end_time
-            self.call_service.hangup_all(call, CallCause.HANGUP_EVENT)
-
-        # 判断挂机方向 && 更新缓存
-        self.hangup_dir(call, device, cause)
-        Cache.add_call_info(call)
+            sys.stdout.flush()  # 强制刷新输出缓冲区
+        except:
+            traceback.print_exc()
 
     def release(self, event):
         device_id = event.getHeader("Unique-ID")

+ 2 - 2
src/core/callcenter/esl/utils/esl_event_util.py

@@ -77,8 +77,8 @@ VARIABLE_SIP_LIBRA_CALLID = "variable_sip_h_P-LIBRA-CallId"
 VARIABLE_SIP_LIBRA_IS_LAST_CALL = "variable_sip_h_P-LIBRA-IsLastCall"
 VARIABLE_ORIGINATION_UUID = "variable_origination_uuid"
 VARIABLE_SIP_LIBRA_DEVICE_ID = "variable_sip_h_P-LIBRA-DeviceId"
-VARIABLE_SIP_WHD_HANGUP_REASON = "variable_sip_bye_h_X-CIN-HangUpReason"
-VARIABLE_SIP_WHD_SERVICE_ID = "variable_sip_bye_h_X-CIN-ServiceId"
+VARIABLE_SIP_WHD_HANGUP_REASON = "variable_sip_bye_h_P-LIBRA-HangUpReason"
+VARIABLE_SIP_WHD_SERVICE_ID = "variable_sip_bye_h_P-LIBRA-ServiceId"
 VARIABLE_SIP_H_P_LIBRA_IS_EAVESDROP = "variable_sip_h_P-LIBRA-is-eavesdrop"
 
 BRIDGE_A_UNIQUE_ID = "Bridge-A-Unique-ID"

+ 6 - 7
src/core/voip/bot.py

@@ -355,8 +355,8 @@ class MyCall(pj.Call):
             self.agent.hangup(self.user_part)
         elif action_code == 'transfer':  # 转人工
             print('todo 转人工')
-            sip_headers = {'bye_h_X-CIN-HangUpReason':'transferToAgent'}
-            self.agent.hangup(self.user_part, sip_headers=sip_headers)
+            sip_headers = {'P-LIBRA-HangUpReason':'transferToAgent'}
+            self.agent.hangup(self.user_part, **sip_headers)
 
 class ToTextBotAgent:
     def __init__(self, user_asr_text, call_agent):
@@ -546,14 +546,13 @@ class BotAgent:
         call_op_param.statusCode = pj.PJSIP_SC_OK
         call_op_param.reason = reason
         call_op_param.txOption = pj.SipTxOption()
-        # sip_header_vector = pj.SipHeaderVector()
-        sip_header_vector = []
+        sip_header_vector = pj.SipHeaderVector()
         for k, v in sip_headers.items():
             _sip_header = pj.SipHeader()
-            _sip_header.hName = f"sip_h_{k}"
+            _sip_header.hName = str(k)
             _sip_header.hValue = str(v)
-            sip_header_vector.append(_sip_header)
-            # sip_header_vector.push_back(_sip_header)
+            print('hangup, header_name=%s, header_value=%s'%(k, v))
+            sip_header_vector.push_back(_sip_header)
         call_op_param.txOption.headers = sip_header_vector
 
         acc = self.accounts.get(user_part)