davidliu преди 4 месеца
родител
ревизия
ac93d77e7a
променени са 3 файла, в които са добавени 54 реда и са изтрити 11 реда
  1. 10 1
      src/core/callcenter/constant.py
  2. 14 2
      src/core/callcenter/enumeration.py
  3. 30 8
      src/core/callcenter/esl/handler/channel_answer_handler.py

+ 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"
@@ -115,4 +117,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

+ 14 - 2
src/core/callcenter/enumeration.py

@@ -279,9 +279,9 @@ class DeviceType(Enum):
 class CallType(Enum):
     IM = (0, 'IM')
     INBOUND_CALL = (1, '呼入')
-    OUTBOUND_CALL = (2, '手动外呼')
+    AGENT_CALL = (2, '手动外呼')
     AUTO_CALL = (3, '预测外呼')
-    BOOT_CALL = (4, '机器人外呼')
+    BOT_CALL = (4, '机器人外呼')
     BOTH_CALL = (5, '双向外呼')
     SIP_OUTBOUND_CALL = (6, '硬话机外呼')
     INNER_CALL = (7, '内呼')
@@ -294,6 +294,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, '呼入')

+ 30 - 8
src/core/callcenter/esl/handler/channel_answer_handler.py

@@ -3,8 +3,9 @@
 import json
 import time
 from datetime import datetime
-from src.core.callcenter.constant import saasId, get_record_prefix
-from src.core.callcenter.enumeration import NextType, AnswerFlag, Direction, DeviceType, AgentScene, CdrType
+from src.core.callcenter.constant import saasId, get_record_prefix, get_record_file_name
+from src.core.callcenter.enumeration import NextType, AnswerFlag, Direction, DeviceType, AgentScene, CdrType, CallType, \
+    CallStage
 from src.core.callcenter.esl.annotation import EslEventName
 import src.core.callcenter.esl.utils.esl_event_util as EslEventUtil
 from src.core.callcenter.esl.constant.event_names import CHANNEL_ANSWER
@@ -39,7 +40,9 @@ class ChannelAnswerHandler(EslEventHandler):
         if not next_command:
             return
 
+
         if device_info.device_type == DeviceType.CUSTOMER.code:
+            self.record(event, device_id)
             self.push_handler.push_on_ring_start(saas_id=call_info.saas_id, flow_id=call_info.cti_flow_id, user_id=call_info.agent_key, scene=AgentScene.MANUAL, call_id=call_info.call_id)
 
         device_info.answer_time = EslEventUtil.getEventDateTimestamp(event)
@@ -48,7 +51,7 @@ class ChannelAnswerHandler(EslEventHandler):
         call_info.next_commands.remove(next_command)
 
         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:
@@ -59,16 +62,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
@@ -100,6 +102,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)
 
@@ -115,6 +118,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)
@@ -126,3 +130,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