Browse Source

网关接口开发

刘威 6 months ago
parent
commit
d39e13ef5d

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

@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 # encoding:utf-8
-# from src.core.datasource import MysqlHandler
+from src.core.datasource import MysqlHandler
 from src.core.callcenter.model import AgentActionRequest, AgentInfo, AgentQueryRequest, AgentRequest
 
 
@@ -9,8 +9,8 @@ class AgentService:
     def __init__(self, client, logger):
         self.inbound_client = client
         self.logger = logger
-        # self.mysql_handler = MysqlHandler()
-    #
+        self.mysql_handler = MysqlHandler()
+
     def checkin(self, request: AgentActionRequest):
         pass
 

+ 9 - 1
src/core/callcenter/cache.py

@@ -34,7 +34,15 @@ def get_agent_number(token):
 
 
 # 缓存坐席
-def add_agent_info(agent: AgentInfo):
+def add_agent_info(call_info: CallInfo = None, agent: AgentInfo = None, call_id=None, device_id=None):
+    if call_info and not agent:
+        agent = get_agent_info(call_info.agent_key)
+    if not agent:
+        return
+    if call_id:
+        agent.call_id = call_id
+    if device_id:
+        agent.device_id = device_id
     redis_handler.set(AGENT_INFO + agent.agent_number, json.dumps(agent), cacheDay * 24 * 60 * 60)
 
 

+ 2 - 0
src/core/callcenter/call.py

@@ -36,6 +36,7 @@ class CallService:
         call_info.device_info_map[device_id] = device_info
         Cache.add_call_info(call_info)
         self.client.make_call(route_gateway, request.called, request.caller, call_id, device_id)
+        return call_id
 
     def hold(self, call_info: CallInfo, device_id):
         devices = call_info.device_list
@@ -63,6 +64,7 @@ class CallService:
         # agent.sip_server
         route_gateway = Cache.get_route_gateway(saasId)
         Cache.add_call_info(call_info)
+        Cache.add_agent_info(agent=agent, call_id=call_id, device_id=device_id)
         self.client.make_call(route_gateway, caller, agent_number, call_id, device_id)
 
     def hangup(self, request: HangupCallRequest):

+ 6 - 0
src/core/callcenter/constant.py

@@ -1,6 +1,7 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
+import json
 from src.core.callcenter.model import CallInfo
 
 saasId = "mdj"
@@ -77,6 +78,11 @@ ADMIN_INFO = "ADMIN_INFO:"
 CALL_INFO = "CALL_INFO:"
 
 
+def success(data=""):
+    response = json.dumps({"code": 0, "data": data})
+    return response, 200, {"Content-Type": "application/json"}
+
+
 def format_time_millis(time_millis, pattern='%Y%m%d'):
     from datetime import datetime
     dt = datetime.utcfromtimestamp(time_millis)

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

@@ -79,6 +79,7 @@ class ChannelAnswerHandler(EslEventHandler):
         call.next_commands.append(NextCommand(device_id=device_id, next_type=NextType.NEXT_CALL_BRIDGE, next_value=new_device_id))
         call.device_info_map[new_device_id] = new_device
         Cache.add_call_info(call)
+        Cache.add_agent_info(call_info=call, call_id=call_id, device_id=device_id)
 
         self.client.make_call(route_gateway, call.caller, called, call_id, new_device_id)
 

+ 14 - 12
src/core/callcenter/model.py

@@ -13,24 +13,26 @@ class MakeCallRequest:
     呼叫请求对象
     """
 
-    def __init__(self, follow_data: Dict[str, Any], uuid1, uuid2, call_type: CallType, caller, called, caller_display,
-                 called_display):
-        # 随路数据
-        self.follow_data: Dict[str, Any] = follow_data
-        # uuid1
-        self.uuid1: str = uuid1
-        # uuid2
-        self.uuid2: str = uuid2
+    def __init__(self, saas_id, call_type: CallType, caller, called, caller_display="", called_display="",
+                 uuid1=None, uuid2=None, follow_data: Dict[str, Any] = {}):
+        # 租户id
+        self.saas_id = saas_id
         # 呼叫类型
         self.call_type: CallType = call_type
         # 主叫,如果没有传,则使用坐席号码
-        self.caller: Optional[str] = caller
+        self.caller = caller
         # 被叫
-        self.called: str = called
+        self.called = called
         # 主叫显号,接口没有传就用主技能组配置
-        self.caller_display: Optional[str] = caller_display
+        self.caller_display = caller_display
         # 被叫显号,接口没传就用主技能配置
-        self.called_display: Optional[str] = called_display
+        self.called_display = called_display
+        # uuid1
+        self.uuid1 = uuid1
+        # uuid2
+        self.uuid2 = uuid2
+        # 随路数据
+        self.follow_data = follow_data
 
     def to_json_string(self):
         return json.dumps(self.__dict__, ensure_ascii=False)

+ 25 - 7
src/core/callcenter/web.py

@@ -1,15 +1,18 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
+import json
 import threading
 from logging.config import dictConfig
-
+import src.core.callcenter.cache as Cache
 from src.core.callcenter.agent import AgentService
+from src.core.callcenter.constant import success
+from src.core.callcenter.enumeration import CallType
 from src.core.callcenter.esl.client import InboundClient
 from flask import Flask, request, render_template_string
 
 from src.core.callcenter.call import CallService
-from src.core.callcenter.model import MakeCallRequest, AgentInfo, AgentActionRequest
+from src.core.callcenter.model import MakeCallRequest, AgentInfo, AgentActionRequest, HangupCallRequest
 
 dictConfig({
         "version": 1,
@@ -146,16 +149,31 @@ def agent_state():
 @app.route('/open/agent/manual-call', methods=['POST'])
 def manual_call():
     """外呼"""
-    request = MakeCallRequest()
-    agent = AgentInfo()
-    call_service.call(request, agent)
-    return 'Hello World!'
+    # agentId: string
+    # vccId: string
+    # password: string
+    # scene: string
+    # ctiFlowId?: string
+    # monitorScene?: string
+    # called: string
+    # circuitUid: string
+    # ext?: object
+    # callId: string
+    data = request.json()
+    agent = Cache.get_agent_info(data.get('agentId'))
+    req = MakeCallRequest(saas_id=data.get('vccId'), call_type=CallType.OUTBOUND_CALL, caller=agent.agent_number, called=data.get('called'), follow_data=data.get('ext'))
+    res = call_service.call(req, agent)
+    return success(res)
 
 
 @app.route('/open/agent/manual-hang', methods=['POST'])
 def manual_hang():
     """挂断"""
-    return 'Hello World!'
+    data = request.json()
+    agent = Cache.get_agent_info(data.get('agentId'))
+    req = HangupCallRequest(saas_id=data.get('vccId'), call_id=data.get('callId'), agent_number=agent.agent_number)
+    call_service.hangup(req)
+    return success()
 
 
 @app.route('/open/agent/listen', methods=['POST'])

+ 10 - 10
src/core/datasource.py

@@ -16,16 +16,16 @@ from redis import StrictRedis, ConnectionPool
 from src.core.voip.constant import *
 
 
-RADIS_HOST = os.environ.get("REDIS_HOST", "10.0.0.24")
-
-# 设置mysql连接信息 host从容器配置文件获取 默认为测试mysql 如果获取配置文件是9.54 设置线上mysql
-MYSQL_HOST = os.environ.get("MYSQL_HOST", "192.168.9.54")
-MYSQL_PASSWORD = 'Hongshan2024@longjiang'
-
-if MYSQL_HOST == "192.168.9.54":
-    MYSQL_PASSWORD = "Hongshan2024#longjiang%xinyi"
-else:
-    MYSQL_PASSWORD = "Hongshan2024@longjiang"
+# RADIS_HOST = os.environ.get("REDIS_HOST", "10.0.0.24")
+#
+# # 设置mysql连接信息 host从容器配置文件获取 默认为测试mysql 如果获取配置文件是9.54 设置线上mysql
+# MYSQL_HOST = os.environ.get("MYSQL_HOST", "192.168.9.54")
+# MYSQL_PASSWORD = 'Hongshan2024@longjiang'
+#
+# if MYSQL_HOST == "192.168.9.54":
+#     MYSQL_PASSWORD = "Hongshan2024#longjiang%xinyi"
+# else:
+#     MYSQL_PASSWORD = "Hongshan2024@longjiang"
 
 
 # @singleton

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

@@ -34,7 +34,7 @@ def build_demo_script():
 
 
 # SERVE_HOST = os.environ.get("SERVE_HOST")
-SERVE_HOST = "172.16.12.24"
+SERVE_HOST = "192.168.100.195"
 MYSQL_PASSWORD = 'EKoAe3H8xybQKrFPApXM'
 
 if SERVE_HOST != "192.168.100.159":