|
@@ -505,6 +505,12 @@ class OutboundClient:
|
|
|
def load_whitelist(self):
|
|
|
return self.whitelist
|
|
|
|
|
|
+ def load_agent_monitor(self):
|
|
|
+ with self.app.app_context():
|
|
|
+ agents = AgentMonitor.query.filter_by(check_state=0,service_state=2).all()
|
|
|
+ agent_nums = [agent.agent_num for agent in agents]
|
|
|
+ return agent_nums
|
|
|
+
|
|
|
class ESLRequestHandler(socketserver.BaseRequestHandler):
|
|
|
def setup(self):
|
|
|
try:
|
|
@@ -520,10 +526,15 @@ class OutboundClient:
|
|
|
device_id = info.getHeader("unique-id")
|
|
|
caller_number = info.getHeader("Caller-Caller-ID-Number") # 获取来电号码
|
|
|
whitelist = self.server.load_whitelist()
|
|
|
+ agents = self.server.load_agent_monitor()
|
|
|
+ # 直接转接到人工坐席
|
|
|
+
|
|
|
# 检查白名单
|
|
|
if caller_number in whitelist:
|
|
|
+ # 随机取一个坐席号
|
|
|
+ destination = random.choice(agents)
|
|
|
# 直接转接到人工坐席
|
|
|
- self.server.logger.info("Caller %s is in whitelist, directly transferring call.", caller_number)
|
|
|
+ self.server.logger.info("Caller %s is in whitelist, directly transferring call, agents: %s, destination: %s", caller_number, agents,destination)
|
|
|
return
|
|
|
|
|
|
kwargs = json.loads(info.serialize('json'))
|
|
@@ -556,15 +567,16 @@ class OutboundClient:
|
|
|
traceback.print_exc()
|
|
|
|
|
|
class CustomTCPServer(socketserver.TCPServer):
|
|
|
- def __init__(self, server_address, RequestHandlerClass, agent, logger,whitelist_loader):
|
|
|
+ def __init__(self, server_address, RequestHandlerClass, agent, logger,whitelist_loader,load_agent_monitor):
|
|
|
self.agent = agent
|
|
|
self.logger = logger
|
|
|
self.load_whitelist = whitelist_loader
|
|
|
+ self.load_agent_monitor = load_agent_monitor
|
|
|
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) as server:
|
|
|
+ with self.CustomTCPServer((HOST, PORT), self.ESLRequestHandler, agent, logger, self.load_whitelist, self.load_agent_monitor) as server:
|
|
|
self.logger.info(f"ESL server listening on {HOST}:{PORT}")
|
|
|
server.serve_forever()
|