Quellcode durchsuchen

Merge branch 'dev_holdfix_20241216' into dev_20241205

DavidLiu vor 3 Monaten
Ursprung
Commit
279fdcc1e3

+ 4 - 4
src/core/callcenter/acd.py

@@ -31,16 +31,16 @@ class AcdService:
         self.checkIdleScheduler.add_job(self.try_transfer_agent, 'interval', seconds=2, max_instances=1)
         self.checkIdleScheduler.start()
 
-    def transfer_to_agent(self, call_id, device_id, service_id='00000000000000000'):
+    def transfer_to_agent(self, call_id, device_id, service_id='00000000000000000', hold=False):
         call_info = self.cache.get_call_info(call_id)
         self.logger.info('transfer_to_agent, come in, call_id:%s, call_info:%s'%(call_id, call_info))
         if not call_info:
             return
         call_info.answer_flag = AnswerFlag.TRANSFER_TO_AGENT.code
         # 1. hold住并且播放等待音
-        self.call_service.hold(call_info, device_id)
-        self.wait_timeout(call_id)
-
+        if hold:
+            self.call_service.hold(call_id, device_id)
+            self.wait_timeout(call_id)
         # 获得空闲坐席
         agent_number = self.agent_service.assign(AgentActionRequest(saas_id=saasId, service_id=service_id))
         if not agent_number:

+ 18 - 12
src/core/callcenter/call.py

@@ -70,18 +70,24 @@ class CallService:
         self.agent_actionlog_service.insert_service_state(agent_monitor, AgentServiceState.DIALING, AgentLogState.DIALING)
         self.data_handle_server.create_record(call_info.call_id, call_info.called, call_info.call_type, service_category=0, destination=agent_id, category=1)
 
-    def hold(self, call_info: CallInfo, device_id):
-        devices = call_info.device_list
-        # try:
-        #     devices.remove(device_id)
-        # except:
-        #     pass
-        # custom_device_id = devices[0]
-        custom_device_id = device_id
-        self.logger.info('hold, custom_device_id=%s'%custom_device_id)
-        self.client.bridge_break(call_info.call_id, custom_device_id)
-        self.cache.set_need_play_hold_music(call_info.call_id)
-        self.logger.info('hold success custom_device_id=%s'%custom_device_id)
+    def hold(self, call_id, device_id):
+        self.logger.info('hold, custom_device_id=%s'%device_id)
+        self.client.bridge_break(call_id, device_id)
+        self.cache.set_need_play_hold_music(call_id)
+        self.logger.info('hold success custom_device_id=%s'%device_id)
+
+    # def hold(self, call_info: CallInfo, device_id):
+    #     devices = call_info.device_list
+    #     # try:
+    #     #     devices.remove(device_id)
+    #     # except:
+    #     #     pass
+    #     # custom_device_id = devices[0]
+    #     custom_device_id = device_id
+    #     self.logger.info('hold, custom_device_id=%s'%custom_device_id)
+    #     self.client.bridge_break(call_info.call_id, custom_device_id)
+    #     self.cache.set_need_play_hold_music(call_info.call_id)
+    #     self.logger.info('hold success custom_device_id=%s'%custom_device_id)
 
     def cancel_hold(self, call_info: CallInfo, device_id):
         self.client.bridge_call(call_info.call_id, call_info.device_list[0], call_info.device_list[1])

+ 1 - 1
src/core/callcenter/callback.py

@@ -21,7 +21,7 @@ class Callback(object):
         self.logger = app.logger
         self.cache = Cache(app)
         self.event_queue = queue.Queue()
-        self.executors = {x: concurrent.futures.ThreadPoolExecutor(max_workers=1) for x in range(thread_num)}
+        self.executors = {x: concurrent.futures.ThreadPoolExecutor(max_workers=1, thread_name_prefix="callback-event-pool") for x in range(thread_num)}
         self.agent_event_service = AgentEventService(app)
         threading.Thread(target=self.start).start()
 

+ 16 - 8
src/core/callcenter/esl/client.py

@@ -50,7 +50,7 @@ class InboundClient:
         self.handler_table = self.scan_esl_event_handlers()
         self.default_event_handler = DefaultEslEventHandler(self, self.bot_agent)
         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_scheduler = BackgroundScheduler()
         self.delay_action_scheduler.add_job(self.submit_delay_action, 'interval', seconds=1, max_instances=1)
@@ -101,6 +101,7 @@ class InboundClient:
                     self.start()
                 else:
                     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)
 
     def choose_thread_pool_executor(self, e):
@@ -540,7 +541,7 @@ class OutboundClient:
                     if caller_number in whitelist:
                         # 检查白名单
                         _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.server.agent.acd_service.transfer_to_agent(call_id, device_id)
                     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)
                     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.server.agent.acd_service.transfer_to_agent(call_id, device_id)
 
                     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)
 
-                    # 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:
                     self.server.logger.info("Failed to connect to FreeSWITCH")
             except:
@@ -578,6 +579,13 @@ class OutboundClient:
                     # Ignore the error if socket is already closed
                     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):
             caller = kwargs.get('Channel-Caller-ID-Number')
             called = destination

+ 1 - 1
src/core/voip/bot.py

@@ -596,7 +596,7 @@ class BotAgent:
 
     def transfer(self, user_part, call_id, device_id, service_id='00000000000000000'):
         if self.acd_service:
-            self.acd_service.transfer_to_agent(call_id, device_id, service_id)
+            self.acd_service.transfer_to_agent(call_id, device_id, service_id, hold=True)
         # sip_headers = {'P-LIBRA-HangUpReason': 'transferToAgent', 'P-LIBRA-ServiceId': service_id}
         try_count = 100
         while try_count >0: