774056846 5 maanden geleden
bovenliggende
commit
0b6087c72e

+ 20 - 32
src/core/callcenter/__init__.py

@@ -7,6 +7,8 @@ from flask import Flask, request, render_template_string
 from flask_sqlalchemy import SQLAlchemy
 from flask_cors import CORS
 from .constant import error_response
+# from .exception import BizException
+
 db = SQLAlchemy()
 
 
@@ -20,42 +22,28 @@ def create_app():
     # with app.app_context():
     #     from . import views  # Import routes
 
-    from src.core.voip.bot import BotAgent
-    from .call import CallService
-    from .agent import AgentService, AgentOperService
-    from .esl.client import InboundClient, OutboundClient
-
-    agent = BotAgent(_app.logger)
+    # # from src.core.voip.bot import BotAgent
+    # from .call import CallService
+    # from .agent import AgentService, AgentOperService
+    # from .esl.client import InboundClient, OutboundClient
+    #
+    # # agent = BotAgent(_app.logger)
     # agent, _outbound_client = None, None
-    _inbound_client = InboundClient(agent, _app.logger)
-    _outbound_client = OutboundClient(agent, _app.logger)
-    _call_service = CallService(_inbound_client, _app.logger)
-    _agent_service = AgentService(_inbound_client, _app.logger)
-    _agent_oper_service = AgentOperService(_inbound_client, _app.logger)
-    return _app, _inbound_client, _outbound_client, _call_service , _agent_service, _agent_oper_service
-
-
-app, inbound_client, outbound_client, call_service , agent_service, agent_oper_service = create_app()
+    # _inbound_client = InboundClient(agent, _app.logger)
+    # _outbound_client = OutboundClient(agent, _app.logger)
+    # _call_service = CallService(_inbound_client, _app.logger)
+    # _agent_service = AgentService(_inbound_client, _app.logger)
+    # _agent_oper_service = AgentOperService(_inbound_client, _app.logger)
+    # return _app, _inbound_client, _outbound_client, _call_service , _agent_service, _agent_oper_service
+    return _app
 
+app = create_app()
 
-class BizException(Exception):
-    def __init__(self, message, status_code=400):
-        super().__init__(message)
-        self.message = message
-        self.status_code = status_code
 
-
-class SipUriSyntaxException(Exception):
-    def __init__(self, message, status_code=400):
-        super().__init__(message)
-        self.message = message
-        self.status_code = status_code
-
-
-@app.errorhandler(BizException)
-def handle_biz_exception(error):
-    traceback.print_exc()
-    return error_response(msg=str(error), http_code=200)
+# @app.errorhandler(BizException)
+# def handle_biz_exception(error):
+#     traceback.print_exc()
+#     return error_response(msg=str(error), http_code=200)
 
 # Generic error handler for uncaught exceptions
 @app.errorhandler(Exception)

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

@@ -9,7 +9,7 @@ from src.core.callcenter.enumeration import AgentState, AgentCheck, AgentHeartSt
     AgentScene, BizErrorCode, WorkStatus, DownEvent, HumanState
 from sqlalchemy import or_
 from src.core.callcenter.dao import *
-from src.core.callcenter import BizException
+from src.core.callcenter.exception import BizException
 from src.core.callcenter.api import AgentActionRequest, AgentInfo, AgentQueryRequest, AgentRequest, AgentEventData, \
     AgentStateData, HumanServiceQueryRequest, AgentMonitorData
 from src.core.callcenter.push import PushHandler

+ 3 - 4
src/core/callcenter/api.py

@@ -5,6 +5,7 @@ import json
 from typing import Dict, Any, Optional, List
 
 from src.core.callcenter.constant import get_json_dict
+from src.core.callcenter.exception import SipUriSyntaxException
 from src.core.datasource import SIP_SERVER
 from src.core.callcenter.esl.constant.esl_constant import SPLIT, SIP_HEADER
 from src.core.callcenter.enumeration import CallType, DeviceType, Direction, CdrType, NextType
@@ -307,15 +308,13 @@ class SipURI:
 
         scheme = f"{self.SIP_SCHEME}{self.SCHEME_SEPARATOR}"
         if not sip_uri.startswith(scheme):
-            # raise SipUriSyntaxException(f"SIP URI must start with {scheme}")
-            return
+            raise SipUriSyntaxException(f"SIP URI must start with {scheme}")
 
         buf = sip_uri[len(scheme):]
         at_pos = buf.find("@")
 
         if at_pos == 0:
-            # raise SipUriSyntaxException("userinfo cannot start with a '@'")
-            return
+            raise SipUriSyntaxException("userinfo cannot start with a '@'")
         if at_pos > 0:
             self.userinfo = buf[:at_pos]
             buf = buf[at_pos + 1:]

+ 15 - 42
src/core/callcenter/exception.py

@@ -1,42 +1,15 @@
-# #!/usr/bin/env python3
-# # encoding:utf-8
-#
-# import traceback
-# from . import app
-# from .constant import error_response
-#
-#
-# class BizException(Exception):
-#     def __init__(self, message, status_code=400):
-#         super().__init__(message)
-#         self.message = message
-#         self.status_code = status_code
-#
-#
-# class SipUriSyntaxException(Exception):
-#     def __init__(self, message, status_code=400):
-#         super().__init__(message)
-#         self.message = message
-#         self.status_code = status_code
-#
-#
-# @app.errorhandler(BizException)
-# def handle_biz_exception(error):
-#     traceback.print_exc()
-#     return error_response(msg=str(error), http_code=200)
-#
-# # Generic error handler for uncaught exceptions
-# @app.errorhandler(Exception)
-# def handle_generic_exception(error):
-#     traceback.print_exc()
-#     return error_response(msg=str(error), http_code=500)
-#
-# # Specific error handler for 404 Not Found errors
-# @app.errorhandler(404)
-# def handle_404_error(error):
-#     return error_response(msg="Resource not found", http_code=404)
-#
-# # Specific error handler for 400 Bad Request errors
-# @app.errorhandler(400)
-# def handle_400_error(error):
-#     return error_response(msg="Bad Request", http_code=400)
+#!/usr/bin/env python3
+# encoding:utf-8
+
+class BizException(Exception):
+    def __init__(self, message, status_code=400):
+        super().__init__(message)
+        self.message = message
+        self.status_code = status_code
+
+
+class SipUriSyntaxException(Exception):
+    def __init__(self, message, status_code=400):
+        super().__init__(message)
+        self.message = message
+        self.status_code = status_code

+ 14 - 1
src/core/callcenter/views.py

@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
-from . import app, call_service , agent_service, agent_oper_service
+from . import app
 import src.core.callcenter.cache as Cache
 from src.core.callcenter.constant import success_response, error_response
 from src.core.callcenter.enumeration import CallType
@@ -10,6 +10,19 @@ from flask import Flask, request, render_template_string
 from src.core.callcenter.api import AgentCallRequest, AgentActionRequest, HangupCallRequest, \
     HumanServiceQueryRequest
 
+# from src.core.voip.bot import BotAgent
+from .call import CallService
+from .agent import AgentService, AgentOperService
+from .esl.client import InboundClient, OutboundClient
+
+# agent = BotAgent(_app.logger)
+agent, _outbound_client = None, None
+inbound_client = InboundClient(agent, app.logger)
+# outbound_client = OutboundClient(agent, app.logger)
+call_service = CallService(inbound_client, app.logger)
+agent_service = AgentService(inbound_client, app.logger)
+agent_oper_service = AgentOperService(inbound_client, app.logger)
+
 
 
 @app.route('/')