|
@@ -27,7 +27,7 @@ import src.core.callcenter.esl.utils.esl_event_util as EslEventUtil
|
|
|
import src.core.callcenter.esl.handler as event_handler
|
|
|
from src.core.callcenter.esl.constant.sip_header_constant import sipHeaderHoldMusic, profile1, profile2, sipHeaderCallId
|
|
|
from src.core.callcenter.enumeration import CallCause, DeviceType, DelayActionEnum, HangupDir, CallType, NextType, \
|
|
|
- Direction, CdrType, BizErrorCode
|
|
|
+ Direction, CdrType, BizErrorCode, WhiteTypeEnum
|
|
|
from src.core.callcenter.esl.handler.default_esl_event_handler import DefaultEslEventHandler
|
|
|
from src.core.callcenter.snowflake import Snowflake
|
|
|
from src.core.datasource import SERVE_HOST
|
|
@@ -537,28 +537,28 @@ class OutboundClient:
|
|
|
service_category = 0
|
|
|
bucket = self.server.get_bucket(call_id)
|
|
|
whitelist = self.server.get_whitelist()
|
|
|
- self.server.logger.info('call incoming call_id=%s, caller_number=%s, device_id=%s, new_device_id=%s, bucket=%s', call_id, caller_number, device_id, new_device_id, bucket.name)
|
|
|
-
|
|
|
- if self.in_whitelist(caller_number, whitelist):
|
|
|
+ _in_whitelist = self.in_whitelist(caller_number, whitelist)
|
|
|
+ self.server.logger.info('call incoming call_id=%s, caller_number=%s, device_id=%s, new_device_id=%s, in_whitelist=%s, bucket=%s', call_id, caller_number, device_id, new_device_id, _in_whitelist, bucket.name)
|
|
|
+ if _in_whitelist:
|
|
|
# 检查白名单
|
|
|
- _bucket_call_type = 0
|
|
|
- self.answer(con, call_id, device_id)
|
|
|
- self.build_call_info(CallType.INCOMING_AGENT_CALL.code, call_id, device_id, new_device_id, destination=None, bucket_type=_bucket_call_type, **kwargs)
|
|
|
- self.server.agent.acd_service.transfer_to_agent(call_id, device_id)
|
|
|
- elif bucket and bucket.name == 'AI':
|
|
|
- #转到ai机器人
|
|
|
- _bucket_call_type = 1
|
|
|
- service_category = 1
|
|
|
- destination = self.server.agent.register(**kwargs)
|
|
|
- self.server.logger.info("device_id=%s, destination=%s, new_device_id=%s" % (device_id, destination, new_device_id))
|
|
|
- self.build_call_info(CallType.INCOMING_BOT_CALL.code, call_id, device_id, new_device_id, str(destination), bucket_type=_bucket_call_type, **kwargs)
|
|
|
- self.server.cache.add_device_user_part(device_id, destination)
|
|
|
- con.execute("bridge", "{sip_h_P-LIBRA-CallId=%s,sip_h_P-LIBRA-DeviceId=%s,origination_uuid=%s}user/%s" % (call_id, new_device_id, new_device_id, destination), device_id)
|
|
|
+ if WhiteTypeEnum.AI == _in_whitelist:
|
|
|
+ # 转到ai机器人
|
|
|
+ _bucket_call_type = 0
|
|
|
+ service_category = 1
|
|
|
+ destination = self.bridge_ai(con, _bucket_call_type, call_id, device_id, new_device_id, **kwargs)
|
|
|
+ else:
|
|
|
+ _bucket_call_type = 0
|
|
|
+ self.transfer_custom(con, _bucket_call_type, call_id, device_id, new_device_id, **kwargs)
|
|
|
else:
|
|
|
- # 传统服务
|
|
|
- self.answer(con, call_id, device_id)
|
|
|
- self.build_call_info(CallType.INCOMING_AGENT_CALL.code, call_id, device_id, new_device_id, destination=None, bucket_type=_bucket_call_type, **kwargs)
|
|
|
- self.server.agent.acd_service.transfer_to_agent(call_id, device_id)
|
|
|
+ # 自然分流
|
|
|
+ if bucket and bucket.name == 'AI':
|
|
|
+ #转到ai机器人
|
|
|
+ _bucket_call_type = 1
|
|
|
+ service_category = 1
|
|
|
+ destination = self.bridge_ai(con, _bucket_call_type, call_id, device_id, new_device_id, **kwargs)
|
|
|
+ else:
|
|
|
+ # 传统服务
|
|
|
+ self.transfer_custom(con, _bucket_call_type, call_id, device_id, new_device_id, **kwargs)
|
|
|
|
|
|
registry.CALL_INCOMING_REQUESTS.labels(f"{_bucket_call_type}").inc()
|
|
|
self.server.dataHandleServer.create_record(call_id, caller_number, _bucket_call_type, service_category=service_category, user_id=destination if _bucket_call_type == 1 else None , user_name= f"机器人{destination}" if _bucket_call_type ==1 else None)
|
|
@@ -580,11 +580,26 @@ class OutboundClient:
|
|
|
# Ignore the error if socket is already closed
|
|
|
pass
|
|
|
|
|
|
+ def transfer_custom(self, con, _bucket_call_type, call_id, device_id, new_device_id, kwargs):
|
|
|
+ self.answer(con, call_id, device_id)
|
|
|
+ self.build_call_info(CallType.INCOMING_AGENT_CALL.code, call_id, device_id, new_device_id, destination=None, bucket_type=_bucket_call_type, **kwargs)
|
|
|
+ self.server.agent.acd_service.transfer_to_agent(call_id, device_id)
|
|
|
+
|
|
|
+ def bridge_ai(self, con, _bucket_call_type, call_id, device_id, new_device_id, kwargs):
|
|
|
+ destination = self.server.agent.register(**kwargs)
|
|
|
+ self.server.logger.info("call_id=%s, device_id=%s, destination=%s, new_device_id=%s" % (call_id, device_id, destination, new_device_id))
|
|
|
+ self.build_call_info(CallType.INCOMING_BOT_CALL.code, call_id, device_id, new_device_id, str(destination), bucket_type=_bucket_call_type, **kwargs)
|
|
|
+ self.server.cache.add_device_user_part(device_id, destination)
|
|
|
+ con.execute("bridge", "{sip_h_P-LIBRA-CallId=%s,sip_h_P-LIBRA-DeviceId=%s,origination_uuid=%s}user/%s" % (call_id, new_device_id, new_device_id, destination), device_id)
|
|
|
+ return destination
|
|
|
+
|
|
|
def in_whitelist(self, caller_number, whitelist):
|
|
|
for x in whitelist:
|
|
|
- if caller_number in x or caller_number in x:
|
|
|
- return True
|
|
|
- return False
|
|
|
+ phone, _type = x
|
|
|
+ if caller_number in phone or phone in caller_number:
|
|
|
+ return WhiteTypeEnum.get_by_code(_type)
|
|
|
+
|
|
|
+ return None
|
|
|
|
|
|
def answer(self, con, call_id, device_id, timeouts=30):
|
|
|
con.execute("answer", "", device_id)
|
|
@@ -652,7 +667,7 @@ class OutboundClient:
|
|
|
def update_whitelist(self):
|
|
|
with self.app.app_context():
|
|
|
phones = Whitelist.query.filter_by(del_flag=0).all()
|
|
|
- self.whitelist = [phone.phone for phone in phones]
|
|
|
+ self.whitelist = [(phone.phone, phone.type) for phone in phones]
|
|
|
self.logger.info("Whitelist updated: %s", self.whitelist)
|
|
|
|
|
|
def get_whitelist(self):
|