|
@@ -50,7 +50,7 @@ class InboundClient:
|
|
self.handler_table = self.scan_esl_event_handlers()
|
|
self.handler_table = self.scan_esl_event_handlers()
|
|
self.default_event_handler = DefaultEslEventHandler(self, self.bot_agent)
|
|
self.default_event_handler = DefaultEslEventHandler(self, self.bot_agent)
|
|
self.host, self.port, self.password = SERVE_HOST, '8021', '4918257983818884358'
|
|
self.host, self.port, self.password = SERVE_HOST, '8021', '4918257983818884358'
|
|
- self.executors = {x: concurrent.futures.ThreadPoolExecutor(max_workers=1) for x in range(self.thread_num)}
|
|
|
|
|
|
+ self.executors = {x: concurrent.futures.ThreadPoolExecutor(max_workers=1, thread_name_prefix="client-event-pool") for x in range(self.thread_num)}
|
|
self.delay_action_executor = concurrent.futures.ThreadPoolExecutor(max_workers=5)
|
|
self.delay_action_executor = concurrent.futures.ThreadPoolExecutor(max_workers=5)
|
|
self.delay_action_scheduler = BackgroundScheduler()
|
|
self.delay_action_scheduler = BackgroundScheduler()
|
|
self.delay_action_scheduler.add_job(self.submit_delay_action, 'interval', seconds=1, max_instances=1)
|
|
self.delay_action_scheduler.add_job(self.submit_delay_action, 'interval', seconds=1, max_instances=1)
|
|
@@ -101,6 +101,7 @@ class InboundClient:
|
|
self.start()
|
|
self.start()
|
|
else:
|
|
else:
|
|
registry.FLASK_ACTIVE_THREADS.set(threading.active_count())
|
|
registry.FLASK_ACTIVE_THREADS.set(threading.active_count())
|
|
|
|
+ # threading.Thread(target=self.process_esl_event, args=(e,)).start()
|
|
self.choose_thread_pool_executor(e).submit(self.process_esl_event, e)
|
|
self.choose_thread_pool_executor(e).submit(self.process_esl_event, e)
|
|
|
|
|
|
def choose_thread_pool_executor(self, e):
|
|
def choose_thread_pool_executor(self, e):
|
|
@@ -540,7 +541,7 @@ class OutboundClient:
|
|
if caller_number in whitelist:
|
|
if caller_number in whitelist:
|
|
# 检查白名单
|
|
# 检查白名单
|
|
_bucket_call_type = 0
|
|
_bucket_call_type = 0
|
|
- con.execute("answer", "", device_id)
|
|
|
|
|
|
+ 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.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)
|
|
self.server.agent.acd_service.transfer_to_agent(call_id, device_id)
|
|
elif bucket and bucket.name == 'AI':
|
|
elif bucket and bucket.name == 'AI':
|
|
@@ -554,18 +555,18 @@ class OutboundClient:
|
|
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)
|
|
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)
|
|
else:
|
|
else:
|
|
# 传统服务
|
|
# 传统服务
|
|
- con.execute("answer", "", device_id)
|
|
|
|
|
|
+ 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.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)
|
|
self.server.agent.acd_service.transfer_to_agent(call_id, device_id)
|
|
|
|
|
|
registry.CALL_INCOMING_REQUESTS.labels(f"{_bucket_call_type}").inc()
|
|
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, destination=destination)
|
|
self.server.dataHandleServer.create_record(call_id, caller_number, _bucket_call_type, service_category=service_category, destination=destination)
|
|
|
|
|
|
- # try:
|
|
|
|
- # con.disconnect()
|
|
|
|
- # self.server.logger.info("connection disconnected !!!")
|
|
|
|
- # except:
|
|
|
|
- # traceback.print_exc()
|
|
|
|
|
|
+ try:
|
|
|
|
+ con.disconnect()
|
|
|
|
+ self.server.logger.info("connection disconnected !!!")
|
|
|
|
+ except:
|
|
|
|
+ traceback.print_exc()
|
|
else:
|
|
else:
|
|
self.server.logger.info("Failed to connect to FreeSWITCH")
|
|
self.server.logger.info("Failed to connect to FreeSWITCH")
|
|
except:
|
|
except:
|
|
@@ -578,6 +579,13 @@ class OutboundClient:
|
|
# Ignore the error if socket is already closed
|
|
# Ignore the error if socket is already closed
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
+ def answer(self, con, call_id, device_id, timeouts=30):
|
|
|
|
+ con.execute("answer", "", device_id)
|
|
|
|
+ con.execute("playback", HOLD_MUSIC_PATH, device_id)
|
|
|
|
+
|
|
|
|
+ delay_action = DelayAction(call_id=call_id)
|
|
|
|
+ self.server.cache.add_delay_message(DelayActionEnum.ACD_TIMEOUT_PLAY.name, delay_action, timeouts)
|
|
|
|
+
|
|
def build_call_info(self, call_type, call_id, device_id, new_device_id, destination, bucket_type, **kwargs):
|
|
def build_call_info(self, call_type, call_id, device_id, new_device_id, destination, bucket_type, **kwargs):
|
|
caller = kwargs.get('Channel-Caller-ID-Number')
|
|
caller = kwargs.get('Channel-Caller-ID-Number')
|
|
called = destination
|
|
called = destination
|