|
@@ -30,16 +30,16 @@ from src.core.callcenter.esl.handler.default_esl_event_handler import DefaultEsl
|
|
|
from src.core.callcenter.snowflake import Snowflake
|
|
|
from src.core.datasource import SERVE_HOST
|
|
|
from src.core.voip.constant import *
|
|
|
-from src.core.callcenter.dao import *
|
|
|
-
|
|
|
+from src.core.callcenter.data_handler import *
|
|
|
class InboundClient:
|
|
|
|
|
|
- def __init__(self, agent, logger):
|
|
|
+ def __init__(self, agent, logger,app):
|
|
|
self.con = None
|
|
|
self.thread_num = 12
|
|
|
self.is_stopping = False
|
|
|
self.logger = logger
|
|
|
self.bot_agent = agent
|
|
|
+ self.app = app
|
|
|
self.handler_table = self.scan_esl_event_handlers()
|
|
|
self.default_event_handler = DefaultEslEventHandler(self, self.bot_agent, self.logger)
|
|
|
self.host, self.port, self.password = SERVE_HOST, '8021', '4918257983818884358'
|
|
@@ -528,6 +528,8 @@ class OutboundClient:
|
|
|
# 定时更新白名单
|
|
|
threading.Thread(target=self.refresh_whitelist, daemon=True).start()
|
|
|
|
|
|
+
|
|
|
+ self.dataHandleServer = dataHandleServer(app)
|
|
|
#threading.Thread(target=self.start, args=('0.0.0.0', 8084, agent, logger)).start()
|
|
|
server_thread = threading.Thread(target=self.start, args=('0.0.0.0', 8084, agent, logger))
|
|
|
server_thread.daemon = True # 设置守护线程
|
|
@@ -553,6 +555,7 @@ class OutboundClient:
|
|
|
agent_nums = [agent.agent_num for agent in agents]
|
|
|
return agent_nums
|
|
|
|
|
|
+
|
|
|
class ESLRequestHandler(socketserver.BaseRequestHandler):
|
|
|
def setup(self):
|
|
|
try:
|
|
@@ -569,29 +572,39 @@ class OutboundClient:
|
|
|
caller_number = info.getHeader("Caller-Caller-ID-Number") # 获取来电号码
|
|
|
whitelist = self.server.load_whitelist()
|
|
|
|
|
|
- # 检查白名单
|
|
|
- if caller_number in whitelist:
|
|
|
- # 直接转接到人工坐席
|
|
|
- agents = self.server.load_agent_monitor()
|
|
|
- # 随机取一个坐席号
|
|
|
- destination = random.choice(agents)
|
|
|
- # 直接转接到人工坐席
|
|
|
- self.server.logger.info("Caller %s is in whitelist, directly transferring call, agents: %s, destination: %s", caller_number, agents,destination)
|
|
|
- return
|
|
|
-
|
|
|
-
|
|
|
call_id = 'C' + str(Snowflake().next_id())
|
|
|
new_device_id = 'D' + str(Snowflake().next_id())
|
|
|
|
|
|
kwargs = json.loads(info.serialize('json'))
|
|
|
kwargs['variable_sip_h_P-LIBRA-CallId'] = call_id
|
|
|
- destination = self.server.agent.register(**kwargs)
|
|
|
- self.server.logger.info("debugger::device_id=%s, destination=%s, new_device_id=%s", device_id, destination, new_device_id)
|
|
|
-
|
|
|
- self.build_call_info(call_id, device_id, new_device_id, str(destination), **kwargs)
|
|
|
- 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)
|
|
|
-
|
|
|
+ call_info = {
|
|
|
+ "session_id": call_id,
|
|
|
+ "time_begin": datetime.utcnow(),
|
|
|
+ "category": 0,
|
|
|
+ "phone": caller_number
|
|
|
+ }
|
|
|
+ # 检查白名单
|
|
|
+ if caller_number in whitelist:
|
|
|
+ agents = self.server.load_agent_monitor()
|
|
|
+ destination = random.choice(agents) # 随机取一个坐席号
|
|
|
+ # 直接转接到人工坐席
|
|
|
+ self.server.logger.info( "Caller %s is in whitelist, agents: %s, destination: %s", caller_number, agents, destination)
|
|
|
+ call_info['type']= 0
|
|
|
+ call_info['agent_num'] = destination
|
|
|
+ else:
|
|
|
+ #转到ai机器人
|
|
|
+ destination = self.server.agent.register(**kwargs)
|
|
|
+ self.server.logger.info("debugger::device_id=%s, destination=%s, new_device_id=%s", device_id, destination, new_device_id)
|
|
|
+ call_info['type'] = 1
|
|
|
+ call_info['service_category'] = 1
|
|
|
+ call_info['user_id'] = destination
|
|
|
+ call_info['user_name'] = f"机器人{destination}"
|
|
|
+ self.build_call_info(call_id, device_id, new_device_id, str(destination), **kwargs)
|
|
|
+ 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)
|
|
|
+
|
|
|
+ self.server.dataHandleServer.create_record(call_info)
|
|
|
+ print("ceshiyixkeheh")
|
|
|
# destination = "user/1001"
|
|
|
# msg = ESL.ESLevent("sendmsg", uuid)
|
|
|
# msg.addHeader("call-command", "execute")
|
|
@@ -638,16 +651,17 @@ class OutboundClient:
|
|
|
|
|
|
|
|
|
class CustomTCPServer(socketserver.TCPServer):
|
|
|
- def __init__(self, server_address, RequestHandlerClass, agent, logger,whitelist_loader,load_agent_monitor):
|
|
|
+ def __init__(self, server_address, RequestHandlerClass, agent, logger,whitelist_loader,load_agent_monitor,dataHandleServer):
|
|
|
self.agent = agent
|
|
|
self.logger = logger
|
|
|
self.load_whitelist = whitelist_loader
|
|
|
self.load_agent_monitor = load_agent_monitor
|
|
|
+ self.dataHandleServer = dataHandleServer
|
|
|
super().__init__(server_address, RequestHandlerClass)
|
|
|
|
|
|
def start(self, HOST='0.0.0.0', PORT=8084, agent=None, logger=None):
|
|
|
# HOST, PORT = "0.0.0.0", 8084
|
|
|
# 创建一个 TCP 服务器
|
|
|
- with self.CustomTCPServer((HOST, PORT), self.ESLRequestHandler, agent, logger, self.load_whitelist, self.load_agent_monitor) as server:
|
|
|
+ with self.CustomTCPServer((HOST, PORT), self.ESLRequestHandler, agent, logger, self.load_whitelist, self.load_agent_monitor,self.dataHandleServer) as server:
|
|
|
self.logger.info(f"ESL server listening on {HOST}:{PORT}")
|
|
|
server.serve_forever()
|