Przeglądaj źródła

回收分机号

刘威 6 miesięcy temu
rodzic
commit
b79033172b

+ 11 - 0
src/core/callcenter/cache.py

@@ -9,6 +9,7 @@ from src.core.datasource import RedisHandler
 
 cacheDay = 7
 deviceCall = {}
+deviceUserPart = {}
 redis_handler = RedisHandler()
 print(redis_handler.redis.info())
 
@@ -75,6 +76,16 @@ def add_device(device_id, call_id):
     deviceCall[device_id] = call_id
 
 
+def get_user_part(device_id):
+    return deviceUserPart.get(device_id)
+
+
+def add_device_user_part(device_id, user_part):
+    if not device_id or not user_part:
+        return
+    deviceUserPart[device_id] = user_part
+
+
 def get_route_gateway(saas_id):
     return RouteGateway(id=1,
                         saas_id=saas_id,

+ 7 - 0
src/core/callcenter/esl/handler/channel_hangup_handler.py

@@ -26,6 +26,7 @@ class ChannelHangupHandler(EslEventHandler):
         self.logger.info(json.loads(event.serialize('json')))
         call_id = EslEventUtil.getCallId(event)
         if not call_id:
+            self.release(event)
             self.logger.info("call_id is null")
             return
         call = Cache.get_call_info(call_id)
@@ -91,6 +92,12 @@ class ChannelHangupHandler(EslEventHandler):
         self.hangup_dir(call, device, cause)
         Cache.add_call_info(call)
 
+    def release(self, event):
+        device_id = event.getHeader("Unique-ID")
+        user_part = Cache.get_user_part(device_id)
+        self.logger.info(f"release device_id={device_id}, user_part={user_part}")
+        self.bot_agent.release(user_part)
+
     def next_cmd(self, call: CallInfo, device: DeviceInfo, next_command: NextCommand, cause):
         # 呼入转到坐席,坐席拒接和坐席sip呼不通的时候,都需要再次转回来到技能组排队。
         if NextType.NEXT_CALL_BRIDGE == next_command.next_type or NextType.NEXT_LISTEN_CALL == next_command.next_type:

+ 5 - 4
src/core/callcenter/esl/handler/channel_park_handler.py

@@ -2,6 +2,7 @@
 # encoding:utf-8
 
 import json
+import src.core.callcenter.cache as Cache
 from src.core.callcenter.esl.annotation import EslEventName
 from src.core.callcenter.esl.constant.event_names import CHANNEL_PARK
 from src.core.callcenter.esl.handler.esl_event_handler import EslEventHandler
@@ -19,18 +20,18 @@ class ChannelParkHandler(EslEventHandler):
             self.process_fxo_calling(event)
             return
 
-
     def process_fxo_calling(self, event):
         kwargs = json.loads(event.serialize('json'))
         destination = self.bot_agent.register(**kwargs)
         # destination = '1001'
         # 获取通话的 UUID
-        call_uuid = event.getHeader("Unique-ID")
+        device_id = event.getHeader("Unique-ID")
         service = event.getHeader("variable_service")
-        print(f"Incoming call with UUID: {call_uuid}  {service} is transfer to {destination}")
+        print(f"Incoming call with UUID: {device_id}  {service} is transfer to {destination}")
         # self.inbound_client.con.execute("transfer", f"{destination} XML default", call_uuid)
         # self.con.execute("answer", "", call_uuid)
-        self.inbound_client.con.execute("bridge", f"user/{destination}", call_uuid)
+        Cache.add_device_user_part(device_id, destination)
+        self.inbound_client.con.execute("bridge", f"user/{destination}", device_id)
 
         # destination = "user/1001"
         # msg = ESL.ESLevent("sendmsg", call_uuid)

+ 6 - 2
src/core/voip/bot.py

@@ -75,10 +75,9 @@ class MyAudioMediaPort(pj.AudioMediaPort):
 
             player_queue_size = self.call.player_queue.qsize()
             if (player_queue_size > 0 and not self.cur_player_file) or (player_queue_size > 0 and play_complete):
-                print('onFrameReceived:player_queu_size=', player_queue_size, 'play_complete=', play_complete)
+                print('onFrameReceived:player_queue_size=', player_queue_size, 'play_complete=', play_complete)
                 self.cur_player_file = self.get_player_file()
                 self.call.send_bot_speaker(self.cur_player_file)
-
         except:
             pass
 
@@ -338,6 +337,10 @@ class BotAgent:
         self.release(user_part)
 
     def release(self, user_part):
+        if not user_part:
+            self.logger.info("release, user_part is None")
+            return
+
         def element_in_queue(q, element):
             with q.mutex:  # 确保线程安全
                 for item in list(q.queue):  # 将队列转换为列表进行遍历
@@ -346,6 +349,7 @@ class BotAgent:
             return False
 
         if element_in_queue(self.user_part_pool, user_part):
+            self.logger.info("release, already exists, user_part :%d, pool.size :%d", user_part, self.user_part_pool.qsize())
             return
         self.user_part_pool.put(user_part)
         self.logger.info("release, user_part :%d, pool.size :%d", user_part, self.user_part_pool.qsize())