|
@@ -1,8 +1,10 @@
|
|
|
#!/usr/bin/env python3
|
|
|
# encoding:utf-8
|
|
|
|
|
|
+import time
|
|
|
+from src.core.callcenter.constant import saasId, get_record_prefix
|
|
|
import src.core.callcenter.cache as Cache
|
|
|
-from src.core.callcenter.enumeration import NextType
|
|
|
+from src.core.callcenter.enumeration import NextType, AnswerFlag, Direction, DeviceType
|
|
|
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
|
|
@@ -35,24 +37,75 @@ class ChannelAnswerHandler(EslEventHandler):
|
|
|
|
|
|
if NextType.NEXT_CALL_OTHER == next_command.next_type:
|
|
|
self.call_other(call_info, device_info)
|
|
|
- elif NextType.NEXT_TRANSFER_CALL == next_command.next_type:
|
|
|
- self.transfer_call(call_info, next_command, event)
|
|
|
elif NextType.NEXT_CALL_BRIDGE == next_command.next_type:
|
|
|
self.call_bridge(call_info, device_info, next_command, event)
|
|
|
+ elif NextType.NEXT_TRANSFER_CALL == next_command.next_type:
|
|
|
+ self.transfer_call(call_info, next_command, event)
|
|
|
elif NextType.NEXT_LISTEN_CALL == next_command.next_type:
|
|
|
self.listen(call_info, device_info, next_command, event)
|
|
|
else:
|
|
|
- self.logger.warn("can not match command :%s, callId:%s", next_command.next_type, call_id)
|
|
|
+ self.logger.warn("can not match command :%s, callId :%s", next_command.next_type, call_id)
|
|
|
Cache.add_call_info(call_info)
|
|
|
|
|
|
def call_other(self, call: CallInfo, device: DeviceInfo):
|
|
|
- pass
|
|
|
+ call_id = call.call_id
|
|
|
+ device_id = device.device_id
|
|
|
|
|
|
- def transfer_call(self, call: CallInfo, next_command: NextCommand, event):
|
|
|
- pass
|
|
|
+ # 启用录音, 生产时候打开
|
|
|
+ # record = get_record_prefix(call) + '/' + call_id + '.wav'
|
|
|
+ # self.inbound_client.record(device.device_id, 'start', record, 0)
|
|
|
+ # device.record = record
|
|
|
+ # device.record_start_time = device.answer_time
|
|
|
+
|
|
|
+ call.direction = Direction.OUTBOUND
|
|
|
+ call.answer_flag = AnswerFlag.AGENT_ANSWER
|
|
|
+
|
|
|
+ new_device_id = 'D' + self.snowflake.next_id()
|
|
|
+ call.device_list.append(new_device_id)
|
|
|
+ called = call.called
|
|
|
+
|
|
|
+ self.logger.info("呼另外一侧电话: callId: %s, display:%s, called:%s, deviceId: %s ",
|
|
|
+ call_id, call.called_display, called, device_id)
|
|
|
+ route_gateway = Cache.get_route_gateway(saasId)
|
|
|
+ if not route_gateway:
|
|
|
+ self.logger.warn("callId:%s routeGetway error, called:%s", call_id, called)
|
|
|
+ self.inbound_client.hangup_call(call_id, device_id)
|
|
|
+ return
|
|
|
+
|
|
|
+ now = lambda: int(round(time.time() * 1000))
|
|
|
+ new_device = DeviceInfo(device_id=new_device_id, call_id=call_id, agent_key=call.agent_key,
|
|
|
+ called=called, display=call.called_display, caller=call.called_display,
|
|
|
+ call_time=now, device_type=DeviceType.CUSTOMER)
|
|
|
+ call.next_commands.append(NextCommand(device_id=device_id, next_type=NextType.NEXT_CALL_BRIDGE, next_value=new_device_id))
|
|
|
+ call.device_info_map[new_device_id] = new_device
|
|
|
+ Cache.add_call_info(call)
|
|
|
+
|
|
|
+ self.client.make_call(route_gateway, call.caller, called, call_id, new_device_id)
|
|
|
|
|
|
def call_bridge(self, call: CallInfo, device: DeviceInfo, next_command: NextCommand, event):
|
|
|
- pass
|
|
|
+ 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)
|
|
|
+ device1 = call.device_info_map.get(next_command.device_id)
|
|
|
+ device2 = call.device_info_map.get(next_command.next_value)
|
|
|
+
|
|
|
+ if not device1.bridge_time:
|
|
|
+ device1.bridge_time = EslEventUtil.getEventDateTimestamp(event)
|
|
|
+ if not device2.bridge_time:
|
|
|
+ device2.bridge_time = EslEventUtil.getEventDateTimestamp(event)
|
|
|
+ Cache.add_call_info(call)
|
|
|
+
|
|
|
+ self.inbound_client.bridge_call(call.call_id, next_command.device_id, next_command.next_value)
|
|
|
+
|
|
|
+ def transfer_call(self, call: CallInfo, next_command: NextCommand, event):
|
|
|
+ # 转接电话 deviceInfo为被转接设备
|
|
|
+ from_device_id = next_command.device_id
|
|
|
+ device_id = EslEventUtil.getDeviceId(event)
|
|
|
+ call.next_commands.append(NextCommand(device_id, NextType.NEXT_TRANSFER_SUCCESS, 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)
|
|
|
|
|
|
def listen(self, call: CallInfo, device: DeviceInfo, next_command: NextCommand, event):
|
|
|
- pass
|
|
|
+ device_id = EslEventUtil.getDeviceId(event)
|
|
|
+ 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)
|
|
|
+
|