余尚辉 před 4 měsíci
rodič
revize
629f10b760

+ 1 - 1
src/core/callcenter/call.py

@@ -34,7 +34,7 @@ class CallService:
         agent = self.cache.get_agent_info(request.saas_id, request.agent_id)
         route_gateway = self.cache.get_route_gateway(request.saas_id)
         call_info = CallInfo(cti_flow_id=request.cti_flow_id, call_id=call_id, agent_key=agent.agent_number, sip_server=agent.sip_server,
-                             caller=agent.agent_number, called=request.called, direction=Direction.OUTBOUND.code,
+                             caller=agent.agent_number, called=request.called, direction=Direction.INBOUND.code,
                              caller_display=request.caller_display, called_display=request.called_display,
                              call_type=request.call_type.code, call_time=now, follow_data=request.follow_data,
                              uuid1=request.uuid1, uuid2=request.uuid2, saas_id=saasId,

+ 10 - 1
src/core/callcenter/constant.py

@@ -3,6 +3,8 @@
 
 import json
 
+from src.core.callcenter.enumeration import CallStage
+
 saasId = "mdj"
 
 UTF_8 = "UTF-8"
@@ -116,4 +118,11 @@ def format_time_millis(time_millis, pattern='%Y%m%d'):
 
 def get_record_prefix(call):
     # 确保所有的值都是字符串类型
-    return BASE_RECORD_PATH + str(call.call_type) + '/' + str(call.saas_id) + '/' + str(call.caller) + '/' + format_time_millis(call.call_time)
+    return BASE_RECORD_PATH + str(call.call_type) + '/' + str(call.saas_id) + '/' + str(call.caller) + '/' + format_time_millis(call.call_time)
+
+def get_record_file_name(call_id, stage: CallStage):
+    if stage.ROBOT == stage:
+        return call_id + '_0'
+    if stage.AGENT == stage:
+        return call_id + '_1'
+    return call_id

+ 15 - 8
src/core/callcenter/enumeration.py

@@ -277,14 +277,9 @@ class DeviceType(Enum):
 
 
 class CallType(Enum):
-    IM = (0, 'IM')
-    INBOUND_CALL = (1, '呼入')
-    OUTBOUND_CALL = (2, '手动外呼')
-    AUTO_CALL = (3, '预测外呼')
-    BOOT_CALL = (4, '机器人外呼')
-    BOTH_CALL = (5, '双向外呼')
-    SIP_OUTBOUND_CALL = (6, '硬话机外呼')
-    INNER_CALL = (7, '内呼')
+    AGENT_CALL = (1, '手动外呼')
+    BOT_CALL = (2, '机器人外呼')
+    BOTH_CALL = (3, '双向外呼')
 
     def __init__(self, code=None, description=None):
         self.code = code
@@ -294,6 +289,18 @@ class CallType(Enum):
     def get_by_code(cls, code):
         return next((member for member in cls if member.code == code), None)
 
+class CallStage(Enum):
+    ROBOT = (1, "机器人")
+    AGENT = (2, "人工坐席")
+    ALL = (3, "总")
+
+    def __init__(self, code=None, description=None):
+        self.code = code
+        self.description = description
+
+    @classmethod
+    def get_by_code(cls, code):
+        return next((member for member in cls if member.code == code), None)
 
 class Direction(Enum):
     INBOUND = (1, '呼入')

+ 2 - 2
src/core/callcenter/esl/client.py

@@ -358,7 +358,7 @@ class InboundClient:
             str(limit)
         ]
         command = ' '.join(builder)
-        self.con.bgapi(command, EMPTY)
+        self.bgapi(command, desc="record")
 
     def transfer(self, uuid, smf, dest, dialplan, context):
         builder = [
@@ -597,7 +597,7 @@ class OutboundClient:
 
             call_info = CallInfo(call_id=call_id, agent_key=destination,
                                  caller=caller, called=called, direction=Direction.INBOUND.code,
-                                 call_type=CallType.BOOT_CALL.code, call_time=now,
+                                 call_type=CallType.BOT_CALL.code, call_time=now,
                                  uuid1=call_id, uuid2=device_id, saas_id=saasId,
                                  core_uuid=None, cti_flow_id=None, conference=None, group_id=None, hidden_customer=0, caller_display=None, called_display=None, number_location=None, agent_name=None, login_type=None, ivr_id=None, task_id=None, media_host=None, sip_server=None, client_host=None, record=None, record2=None, record_time=None, answer_flag=None, wait_time=None, answer_count=0, hangup_dir=None, sdk_hangup=0, hangup_code=None, answer_time=None, end_time=None, talk_time=None, first_queue_time=None, queue_start_time=None, queue_end_time=None, overflow_count=0, cdr_notify_url=None, queue_level=None, transfer_agent=None,device_list=[], device_info_map = {}, follow_data = {}, process_data = {}, next_commands=[], call_details=[])
             device_custom = DeviceInfo(device_id=device_id, call_time=now,

+ 25 - 7
src/core/callcenter/esl/handler/channel_answer_handler.py

@@ -58,7 +58,7 @@ class ChannelAnswerHandler(EslEventHandler):
                 self.dataHandleServer.update_agent_monitor_service_state(call_info.agent_key, AgentServiceState.CALLING.code)
 
         if NextType.NEXT_CALL_OTHER.code == next_command.next_type:
-            self.call_other(call_info, device_info)
+            self.call_other(call_info, device_info, event)
         elif NextType.NEXT_CALL_BRIDGE.code == next_command.next_type:
             self.call_bridge(call_info, device_info, next_command, event)
         elif NextType.NEXT_TRANSFER_CALL.code == next_command.next_type:
@@ -69,17 +69,15 @@ class ChannelAnswerHandler(EslEventHandler):
             self.logger.warn("can not match command :%s, callId :%s", next_command.next_type, call_id)
         self.cache.add_call_info(call_info)
 
-
-    def call_other(self, call: CallInfo, device: DeviceInfo):
+    def call_other(self, call: CallInfo, device: DeviceInfo, event):
         call_id = call.call_id
         device_id = device.device_id
 
         # 启用录音, 生产时候打开
-        record = get_record_prefix(call) + '/' + call_id + '.wav'
-        self.inbound_client.record(device.device_id, 'start', record, 0)
-        device.record = record
+        record_url = self.record(event, device_id)
+        device.record = record_url
         device.record_start_time = device.answer_time
-        self.dataHandleServer.update_record(call_id, {"url": record})
+        self.dataHandleServer.update_record(call_id, {"url": record_url})
 
         call.direction = Direction.OUTBOUND.code
         call.answer_flag = AnswerFlag.AGENT_ANSWER.code
@@ -111,6 +109,7 @@ class ChannelAnswerHandler(EslEventHandler):
     def call_bridge(self, call: CallInfo, device: DeviceInfo, next_command: NextCommand, event):
         self.logger.info("开始桥接电话: callId:%s, caller:%s, called:%s, device1:%s, device2:%s"% (call.call_id,
                          call.caller, call.called, next_command.device_id, next_command.next_value))
+        self.record(event, device_id=device.device_id)
         device1 = call.device_info_map.get(next_command.device_id)
         device2 = call.device_info_map.get(next_command.next_value)
 
@@ -126,6 +125,7 @@ class ChannelAnswerHandler(EslEventHandler):
         # 转接电话 deviceInfo为被转接设备
         from_device_id = next_command.device_id
         device_id = EslEventUtil.getDeviceId(event)
+        self.record(event, device_id)
         call.next_commands.append(NextCommand(device_id, NextType.NEXT_TRANSFER_SUCCESS.code, call.device_list[1]))
         self.logger.info("转接电话中 callId:%s, from:%s, to:%s "% (call.call_id, from_device_id, device_id))
         self.inbound_client.transfer_call(device_id, next_command.next_value)
@@ -137,3 +137,21 @@ class ChannelAnswerHandler(EslEventHandler):
         self.logger.info("开始监听 callId:%s, deviceId:%s, nextCommandDeviceId:%s", call.call_id, device_id, next_command.next_value)
         self.inbound_client.listen(device_id, next_command.next_value)
 
+    def record(self, event, device_id):
+        call_id = EslEventUtil.getCallId(event)
+        call = self.cache.get_call_info(call_id)
+        if not call:
+            self.logger.info("answer callInfo is null,call_id:%s"%call_id)
+            return
+
+        device =call.device_info_map.get(device_id)
+        if not device:
+            self.logger.info("answer deviceInfo is null,call_id:%s, device_id:%s"%(call_id, device_id))
+            return
+
+        return self.start_recording(device_id, get_record_file_name(call_id, CallStage.ALL), call)
+
+    def start_recording(self, device_id, file_name, call: CallInfo):
+        record_url = get_record_prefix(call) + '/' + file_name + '.wav'
+        self.inbound_client.record(device_id, 'start', record_url, 0)
+        return record_url

+ 1 - 1
src/core/callcenter/views.py

@@ -143,7 +143,7 @@ def manual_call():
     # ext?: object
     # callId: string
     data = request.get_json()
-    req = AgentCallRequest(saas_id=data.get('saas_id'), call_type=CallType.OUTBOUND_CALL, caller=data.get('caller'),
+    req = AgentCallRequest(saas_id=data.get('saas_id'), call_type=CallType.AGENT_CALL.code, caller=data.get('caller'),
                            agent_id=data.get('agent_id'), called=data.get('called'), cti_flow_id=data.get('ctiFlowId'))
     res = call_service.call(req)
     return success_response(res)