Browse Source

转人工测试

774056846 4 months ago
parent
commit
767e1cdaab

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

@@ -5,7 +5,7 @@ from datetime import datetime
 from queue import Queue
 from queue import Queue
 from typing import Dict, Any, Optional
 from typing import Dict, Any, Optional
 import src.core.callcenter.cache as Cache
 import src.core.callcenter.cache as Cache
-from src.core.callcenter.agent import AgentService
+from src.core.callcenter.agent import AgentOperService
 from src.core.callcenter.call import CallService
 from src.core.callcenter.call import CallService
 from src.core.callcenter.api import CallInfo, AgentActionRequest
 from src.core.callcenter.api import CallInfo, AgentActionRequest
 from apscheduler.schedulers.background import BackgroundScheduler
 from apscheduler.schedulers.background import BackgroundScheduler
@@ -19,7 +19,7 @@ class AcdService:
         self.client = client
         self.client = client
         self.logger = logger
         self.logger = logger
         self.call_service = CallService(client, logger)
         self.call_service = CallService(client, logger)
-        self.agent_service = AgentService(client, logger)
+        self.agent_service = AgentOperService(client, logger)
         self.holdsQueue: Dict[str, Queue] = {}
         self.holdsQueue: Dict[str, Queue] = {}
         self.pool = ThreadPoolExecutor(max_workers=4)
         self.pool = ThreadPoolExecutor(max_workers=4)
         # checkIdleScheduler = BackgroundScheduler()
         # checkIdleScheduler = BackgroundScheduler()

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

@@ -17,7 +17,7 @@ class CallService:
     def __init__(self, client, logger):
     def __init__(self, client, logger):
         self.client = client
         self.client = client
         self.logger = logger
         self.logger = logger
-        self.snowflake = Snowflake(worker_id=1, data_center_id=1)
+        self.snowflake = Snowflake()
 
 
     def call(self, request: AgentCallRequest):
     def call(self, request: AgentCallRequest):
         call_id = 'C' + str(self.snowflake.next_id())
         call_id = 'C' + str(self.snowflake.next_id())

+ 9 - 2
src/core/callcenter/esl/client.py

@@ -26,6 +26,7 @@ import src.core.callcenter.esl.handler as event_handler
 from src.core.callcenter.esl.constant.sip_header_constant import sipHeaderHoldMusic, profile1, profile2
 from src.core.callcenter.esl.constant.sip_header_constant import sipHeaderHoldMusic, profile1, profile2
 from src.core.callcenter.enumeration import CallCause, DeviceType, DelayActionEnum, HangupDir, CallType, NextType
 from src.core.callcenter.enumeration import CallCause, DeviceType, DelayActionEnum, HangupDir, CallType, NextType
 from src.core.callcenter.esl.handler.default_esl_event_handler import DefaultEslEventHandler
 from src.core.callcenter.esl.handler.default_esl_event_handler import DefaultEslEventHandler
+from src.core.callcenter.snowflake import Snowflake
 from src.core.datasource import SERVE_HOST
 from src.core.datasource import SERVE_HOST
 from src.core.voip.constant import *
 from src.core.voip.constant import *
 from src.core.callcenter.dao import *
 from src.core.callcenter.dao import *
@@ -479,6 +480,7 @@ class OutboundClient:
 
 
     def __init__(self, agent, logger):
     def __init__(self, agent, logger):
         self.logger = logger
         self.logger = logger
+        self.snowflake = Snowflake()
         # self.whitelist = self.load_whitelist()
         # self.whitelist = self.load_whitelist()
         #threading.Thread(target=self.start, args=('0.0.0.0', 8084, agent, logger)).start()
         #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 = threading.Thread(target=self.start, args=('0.0.0.0', 8084, agent, logger))
@@ -510,13 +512,16 @@ class OutboundClient:
                     #     # 直接转接到指定用户
                     #     # 直接转接到指定用户
                     #     print('come in whitelist')
                     #     print('come in whitelist')
                     #     return
                     #     return
-                    
+
+                    call_id = 'C' + str(self.server.snowflake.next_id())
+                    new_device_id = 'D' + str(self.server.snowflake.next_id())
+
                     kwargs = json.loads(info.serialize('json'))
                     kwargs = json.loads(info.serialize('json'))
                     destination = self.server.agent.register(**kwargs)
                     destination = self.server.agent.register(**kwargs)
                     self.server.logger.info("device_id=%s, destination=%s", device_id, destination)
                     self.server.logger.info("device_id=%s, destination=%s", device_id, destination)
 
 
                     Cache.add_device_user_part(device_id, destination)
                     Cache.add_device_user_part(device_id, destination)
-                    con.execute("bridge", f"user/{destination}", device_id)
+                    con.execute("bridge", "{sip_h_P-LIBRA-CallId=%s,sip_h_P-LIBRA-DeviceId=%s}user/%s"%(call_id, new_device_id, destination), device_id)
 
 
                     # destination = "user/1001"
                     # destination = "user/1001"
                     # msg = ESL.ESLevent("sendmsg", uuid)
                     # msg = ESL.ESLevent("sendmsg", uuid)
@@ -540,6 +545,8 @@ class OutboundClient:
             except:
             except:
                 traceback.print_exc()
                 traceback.print_exc()
 
 
+
+
     class CustomTCPServer(socketserver.TCPServer):
     class CustomTCPServer(socketserver.TCPServer):
         def __init__(self, server_address, RequestHandlerClass, agent, logger):
         def __init__(self, server_address, RequestHandlerClass, agent, logger):
             self.agent = agent
             self.agent = agent

+ 1 - 1
src/core/callcenter/esl/handler/channel_answer_handler.py

@@ -20,7 +20,7 @@ class ChannelAnswerHandler(EslEventHandler):
 
 
     def __init__(self, inbound_client, bot_agent, logger):
     def __init__(self, inbound_client, bot_agent, logger):
         super().__init__(inbound_client, bot_agent, logger)
         super().__init__(inbound_client, bot_agent, logger)
-        self.snowflake = Snowflake(worker_id=1, data_center_id=1)
+        self.snowflake = Snowflake()
         self.push_handler = PushHandler(logger)
         self.push_handler = PushHandler(logger)
 
 
     def handle(self, address, event, coreUUID):
     def handle(self, address, event, coreUUID):

+ 13 - 11
src/core/callcenter/snowflake.py

@@ -4,9 +4,12 @@
 import time
 import time
 import random
 import random
 
 
+from src.core import singleton
 
 
+
+@singleton
 class Snowflake:
 class Snowflake:
-    def __init__(self, worker_id, data_center_id):
+    def __init__(self, worker_id=1, data_center_id=1):
         ### 机器标识ID
         ### 机器标识ID
         self.worker_id = worker_id
         self.worker_id = worker_id
         ### 数据中心ID
         ### 数据中心ID
@@ -39,13 +42,12 @@ class Snowflake:
 
 
     ### test
     ### test
 
 
-
-if __name__ == '__main__':
-    worker_id = 1
-    data_center_id = 1
-    snowflake = Snowflake(worker_id, data_center_id)
-    for i in range(10):
-        try:
-            print(snowflake.next_id())
-        except Exception as e:
-            print("Clock moved backwards:", e)
+# if __name__ == '__main__':
+#     worker_id = 1
+#     data_center_id = 1
+#     snowflake = Snowflake(worker_id, data_center_id)
+#     for i in range(10):
+#         try:
+#             print(snowflake.next_id())
+#         except Exception as e:
+#             print("Clock moved backwards:", e)