Просмотр исходного кода

sdk ws server + call接口定义

刘威 6 месяцев назад
Родитель
Сommit
f3e3084096
47 измененных файлов с 303 добавлено и 155 удалено
  1. 11 0
      src/core/__init__.py
  2. BIN
      src/core/callcenter/annotation/__pycache__/__init__.cpython-39.pyc
  3. 51 0
      src/core/callcenter/call.py
  4. 0 0
      src/core/callcenter/constant.py
  5. BIN
      src/core/callcenter/constant/__pycache__/constant.cpython-38.pyc
  6. BIN
      src/core/callcenter/constant/__pycache__/event_names.cpython-39.pyc
  7. 44 89
      src/core/callcenter/enumeration.py
  8. 0 0
      src/core/callcenter/esl/annotation/__init__.py
  9. 20 17
      src/core/callcenter/esl/client.py
  10. 0 0
      src/core/callcenter/esl/constant/__init__.py
  11. 0 0
      src/core/callcenter/esl/constant/esl_constant.py
  12. 0 0
      src/core/callcenter/esl/constant/event_names.py
  13. 0 0
      src/core/callcenter/esl/constant/sip_header_constant.py
  14. 0 0
      src/core/callcenter/esl/handler/__init__.py
  15. 3 3
      src/core/callcenter/esl/handler/channel_answer_handler.py
  16. 3 3
      src/core/callcenter/esl/handler/channel_bridge_handler.py
  17. 3 3
      src/core/callcenter/esl/handler/channel_hangup_complete_handler.py
  18. 3 3
      src/core/callcenter/esl/handler/channel_hangup_handler.py
  19. 3 3
      src/core/callcenter/esl/handler/channel_park_handler.py
  20. 3 3
      src/core/callcenter/esl/handler/channel_progress_media_handler.py
  21. 1 1
      src/core/callcenter/esl/handler/default_esl_event_handler.py
  22. 3 3
      src/core/callcenter/esl/handler/detected_tone_handler.py
  23. 3 3
      src/core/callcenter/esl/handler/dtmf_handler.py
  24. 0 0
      src/core/callcenter/esl/handler/esl_event_handler.py
  25. 3 3
      src/core/callcenter/esl/handler/playback_stop_handler.py
  26. 3 3
      src/core/callcenter/esl/handler/record_stop_handler.py
  27. 2 1
      src/core/callcenter/esl/utils/call_cache_util.py
  28. 0 0
      src/core/callcenter/esl/utils/esl_event_util.py
  29. BIN
      src/core/callcenter/handler/__pycache__/__init__.cpython-39.pyc
  30. BIN
      src/core/callcenter/handler/__pycache__/channel_answer_handler.cpython-39.pyc
  31. BIN
      src/core/callcenter/handler/__pycache__/channel_bridge_handler.cpython-39.pyc
  32. BIN
      src/core/callcenter/handler/__pycache__/channel_hangup_complete_handler.cpython-39.pyc
  33. BIN
      src/core/callcenter/handler/__pycache__/channel_hangup_handler.cpython-39.pyc
  34. BIN
      src/core/callcenter/handler/__pycache__/channel_park_handler.cpython-39.pyc
  35. BIN
      src/core/callcenter/handler/__pycache__/channel_progress_media_handler.cpython-39.pyc
  36. BIN
      src/core/callcenter/handler/__pycache__/default_esl_event_handler.cpython-39.pyc
  37. BIN
      src/core/callcenter/handler/__pycache__/detected_tone_handler.cpython-39.pyc
  38. BIN
      src/core/callcenter/handler/__pycache__/dtmf_handler.cpython-39.pyc
  39. BIN
      src/core/callcenter/handler/__pycache__/esl_event_handler.cpython-39.pyc
  40. BIN
      src/core/callcenter/handler/__pycache__/playback_stop_handler.cpython-39.pyc
  41. BIN
      src/core/callcenter/handler/__pycache__/record_stop_handler.cpython-39.pyc
  42. 52 0
      src/core/callcenter/model.py
  43. 34 5
      src/core/callcenter/server.py
  44. BIN
      src/core/callcenter/utils/__pycache__/call_cache_util.cpython-38.pyc
  45. BIN
      src/core/callcenter/utils/__pycache__/esl_event_util.cpython-39.pyc
  46. 57 0
      src/core/callcenter/ws.py
  47. 1 12
      src/core/datasource.py

+ 11 - 0
src/core/__init__.py

@@ -0,0 +1,11 @@
+
+
+def singleton(cls):
+    _instance = {}
+
+    def inner():
+        if cls not in _instance:
+            _instance[cls] = cls()
+        return _instance[cls]
+
+    return inner

BIN
src/core/callcenter/annotation/__pycache__/__init__.cpython-39.pyc


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

@@ -1,8 +1,59 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
+from src.core.callcenter.enumeration import CallCauseEnum
+from src.core.callcenter.model import MakeCallRequest, AgentInfo, CallInfo, HangupCallRequest, CheckInCallRequest
+
 
 class CallService:
 
     def __init__(self):
         pass
+
+    def call(self, request: MakeCallRequest, agent: AgentInfo):
+        pass
+
+    def get_call_info(self, call_id):
+        pass
+
+    def add_call_info(self, call_info: CallInfo):
+        pass
+
+    def add_device(self, device_id, call_id):
+        pass
+
+    def get_call_info_by_device_id(self, device_id):
+        pass
+
+    def hold(self, call_info: CallInfo, device_id):
+        pass
+
+    def transfer(self, call_info: CallInfo, agent_number, service_id):
+        pass
+
+    def hangup(self, request: HangupCallRequest):
+        pass
+
+    def hangup_all(self, call_info: CallInfo, caseEnum: CallCauseEnum):
+        pass
+
+    def hangup_by_call_id(self, call_id):
+        pass
+
+    def checkin_call(self, request: CheckInCallRequest):
+        pass
+
+    def add_call_set(self, saas_id, call_id, call_type):
+        pass
+
+    def get_call_set(self, saas_id, call_type):
+        pass
+
+    def remove_from_call_set(self, saas_id, call_id, call_type):
+        pass
+
+    def clear_call_set(self, saas_id, call_type):
+        pass
+
+    def load_call_id_by_device_id(self, device_id):
+        pass

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


BIN
src/core/callcenter/constant/__pycache__/constant.cpython-38.pyc


BIN
src/core/callcenter/constant/__pycache__/event_names.cpython-39.pyc


+ 44 - 89
src/core/callcenter/enumeration.py

@@ -5,104 +5,59 @@ from enum import Enum
 
 
 class CallType(Enum):
-    # IM
-    IM = 0
-    # 呼入
-    INBOUND_CALL = 1
-    # 手动外呼
-    OUTBOUND_CALL = 2
-    # 预测外呼
-    AUTO_CALL = 3
-    # 机器人外呼
-    BOOT_CALL = 4
-    # 双向外呼
-    BOTH_CALL = 5
-    # 硬话机外呼
-    SIP_OUTBOUND_CALL = 6
-    # 内呼
-    INNER_CALL = 6
+    IM = (0, 'IM')
+    INBOUND_CALL = (1, '呼入')
+    OUTBOUND_CALL = (2, '手动外呼')
+    AUTO_CALL = (3, '预测外呼')
+    BOOT_CALL = (4, '机器人外呼')
+    BOTH_CALL = (5, '双向外呼')
+    SIP_OUTBOUND_CALL = (6, '硬话机外呼')
+    INNER_CALL = (7, '内呼')
 
-    def __init__(self, code):
-        self._code = code
-
-    @property
-    def code(self):
-        return self._code
+    def __init__(self, code, description):
+        self.code = code
+        self.description = description
 
 
 class Direction(Enum):
-    # 呼入
-    INBOUND = 1
-    # 外呼
-    OUTBOUND = 2
+    INBOUND = (1, '呼入')
+    OUTBOUND = (2, '外呼')
 
-    def __init__(self, code):
+    def __init__(self, code, description):
         self._code = code
-
-    @property
-    def code(self):
-        return self._code
+        self.description = description
 
 
 class NextType(Enum):
-    NORNAL = 1
-    # 呼叫另外一侧
-    NEXT_CALL_OTHER = 2
-    # 呼叫另外一测
-    NEXT_CALL_OTHER = 3
-    # 桥接
-    NEXT_CALL_BRIDGE = 4
-    # 咨询坐席
-    NEXT_CONSULT_AGENT = 5
-    # 咨询外线
-    NEXT_CONSULT_CALLOUT = 6
-    # 转到坐席
-    NEXT_CALL_AGENT = 7
-    # 完成转接
-    NEXT_TRANSFER_SUCCESS = 8
-    # 转接后桥接
-    NEXT_TRANSFER_BRIDGE = 9
-    # 电话转接
-    NEXT_TRANSFER_CALL = 10
-    # 强插电话
-    NEXT_INSERT_CALL = 11
-    # 监听电话
-    NEXT_LISTEN_CALL = 12
-    # 耳语电话
-    NEXT_WHISPER_CALL = 13
-    # 进vdn
-    NEXT_VDN = 14
-    # 进技能组
-    NEXT_GROUP = 15
-    # 进ivr
-    NEXT_IVR = 16
-    # 挂机处理
-    NEXT_HANGUP = 17
-    # 放音queue
-    NEXT_QUEUE_PLAY = 18
-    # 溢出队列
-    NEXT_QUEUE_OVERFLOW_GROUP = 19
-    # 溢出进IVR
-    NEXT_QUEUE_OVERFLOW_IVR = 20
-    # 溢出进vdn
-    NEXT_QUEUE_OVERFLOW_VDN = 21
-    # 播放音频
-    NEXT_PLAY_START = 22
-    # 等待按键播放音频
-    NEXT_WAIT_KEY = 23
-    # 通知音频播放结束
-    NEXT_NOTICE_MUSIC_DONE = 24
-    # 播放音频
-    NEXT_PLAY_KEY_MUSIC = 25
-    # 停止放音
-    NEXT_QUEUE_PLAY_STOP = 26
-
-    def __init__(self, code):
-        self._code = code
+    NORNAL = (1, '默认')
+    NEXT_CALL_OTHER = (2, '呼叫另外一测')
+    NEXT_CALL_BRIDGE = (3, '桥接')
+    NEXT_CONSULT_AGENT = (4, '咨询坐席')
+    NEXT_CONSULT_CALLOUT = (5, '咨询外线')
+    NEXT_CALL_AGENT = (6, '转到坐席')
+    NEXT_TRANSFER_SUCCESS = (7, '完成转接')
+    NEXT_TRANSFER_BRIDGE = (8, '转接后桥接')
+    NEXT_TRANSFER_CALL = (9, '电话转接')
+    NEXT_INSERT_CALL = (10, '强插电话')
+    NEXT_LISTEN_CALL = (11, '监听电话')
+    NEXT_WHISPER_CALL = (12, '耳语电话')
+    NEXT_VDN = (13, '进vdn')
+    NEXT_GROUP = (14, '进技能组')
+    NEXT_IVR = (15, '进ivr')
+    NEXT_HANGUP = (16, '挂机处理')
+    NEXT_QUEUE_PLAY = (17, '放音queue')
+    NEXT_QUEUE_OVERFLOW_GROUP = (18, '溢出队列')
+    NEXT_QUEUE_OVERFLOW_IVR = (19, '溢出进IVR')
+    NEXT_QUEUE_OVERFLOW_VDN = (20, '溢出进vdn')
+    NEXT_PLAY_START = (21, '播放音频')
+    NEXT_WAIT_KEY = (22, '等待按键播放音频')
+    NEXT_NOTICE_MUSIC_DONE = (23, '通知音频播放结束')
+    NEXT_PLAY_KEY_MUSIC = (24, '播放音频')
+    NEXT_QUEUE_PLAY_STOP = (25, '停止放音')
 
-    @property
-    def code(self):
-        return self._code
+    def __init__(self, code, description):
+        self.code = code
+        self.description = description
 
 
 class CallCauseEnum(Enum):
@@ -125,4 +80,4 @@ class CallCauseEnum(Enum):
 
     def __init__(self, code, description):
         self.code = code
-        self.description = description
+        self.description = description

+ 0 - 0
src/core/callcenter/annotation/__init__.py → src/core/callcenter/esl/annotation/__init__.py


+ 20 - 17
src/core/callcenter/client.py → src/core/callcenter/esl/client.py

@@ -1,30 +1,30 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
-import json
 import random
-
+import logging
 import ESL
 import time
 import mmh3
 import threading
 import traceback
-import socketserver
 import concurrent.futures
-from http.server import BaseHTTPRequestHandler
-from http.server import HTTPServer
-import src.core.callcenter.utils.call_cache_util as CacheUtil
-from src.core.callcenter.constant.constant import AT, CO, SK, saasId, EMPTY
-from src.core.callcenter.constant.esl_constant import BRIDGE_VARIABLES, BRIDGE, HANGUP, NORMAL_CLEARING, SIP_HEADER, SPACE, SPLIT, SOFIA, \
+from src.core import singleton
+from src.core.callcenter.constant import SK, EMPTY
+from src.core.callcenter.esl.constant.esl_constant import BRIDGE_VARIABLES, BRIDGE, HANGUP, NORMAL_CLEARING, SIP_HEADER, SPACE, SPLIT, SOFIA, \
     ORIGINATE, PARK, SET, EAVESDROP, SMF_ALEG, EXECUTE, PLAYBACK, PAUSE, TRANSFER, UUID_TRANSFER, UUID_BROADCAST, UUID_BREAK, UUID_HOLD, \
     UUID_RECORD, UUID_SETVAR, UUID_GETVAR
-import src.core.callcenter.utils.esl_event_util as EslEventUtil
-import src.core.callcenter.handler as event_handler
-from src.core.callcenter.constant.sip_header_constant import sipHeaderHoldMusic
+import src.core.callcenter.esl.utils.esl_event_util as EslEventUtil
+import src.core.callcenter.esl.handler as event_handler
+from src.core.callcenter.esl.constant.sip_header_constant import sipHeaderHoldMusic
 from src.core.callcenter.enumeration import CallCauseEnum
-from src.core.callcenter.handler.default_esl_event_handler import DefaultEslEventHandler
+from src.core.callcenter.esl.handler.default_esl_event_handler import DefaultEslEventHandler
+
 
+logger = logging.getLogger(__name__)
 
+
+@singleton
 class InboundClient:
 
     def __init__(self):
@@ -36,8 +36,9 @@ class InboundClient:
         self.host, self.port, self.password = 'localhost', '8021', '4918257983818884358'
         self.executors = {x: concurrent.futures.ThreadPoolExecutor(max_workers=1) for x in range(self.thread_num)}
 
-        gw = CacheUtil.getRouteGetway(saasId)
-        self.make_call(gw, '63366692', '13241676588', 'C111111111', 'D1111111')
+        threading.Thread(target=self.start, args=()).start()
+        # gw = CacheUtil.getRouteGetway(saasId)
+        # self.make_call(gw, '63366692', '13241676588', 'C111111111', 'D1111111')
 
     def scan_esl_event_handlers(self):
         import inspect
@@ -60,6 +61,7 @@ class InboundClient:
         return handlers
 
     def start(self):
+        print('inbound.start')
         self.con = ESL.ESLconnection(self.host, self.port, self.password)
         if self.con.connected():
             print('inbound esl connected ... ')
@@ -71,6 +73,7 @@ class InboundClient:
                     # print(e.serialize('json'))
                 event_name = e.getHeader("Event-Name")
                 if event_name == "SERVER_DISCONNECTED":
+                    print('come in SERVER_DISCONNECTED case')
                     self.con.disconnect()
                     time.sleep(3)
                     self.start()
@@ -165,7 +168,7 @@ class InboundClient:
         builder.append(f"{SOFIA}{SK}{route_gateway.profile}{SK}{called}{PARK}")
         cmd = "".join(builder)
         print(cmd)
-        # self.con.bgapi(ORIGINATE, cmd)
+        self.con.bgapi(ORIGINATE, cmd)
 
     def call_timeout(self, call_id, device_id, timeout):
         """呼叫超时主动挂机"""
@@ -203,7 +206,7 @@ class InboundClient:
         msg.addHeader("call-command", EXECUTE)
         msg.addHeader("execute-app-name", HANGUP)
         msg.addHeader("execute-app-arg", NORMAL_CLEARING)
-        # log.info("hangupCall挂机 hangup media:{} call: {}, device: {}, ctiCauseEnum:{}", media,callId, deviceId, ctiCauseEnum);
+        logger.info("hangup_call挂机 hangup call: {}, device: {}, ctiCauseEnum:{}", call_id, device_id, case_enum)
         self.send_args(device_id, SET, EslEventUtil.SIP_H_P_WDH_HANGUP_CAUSE + "=" + case_enum.description)
         self.con.sendEvent(msg)
 
@@ -276,7 +279,7 @@ class InboundClient:
 
     def record(self, uuid, action, path, limit):
         builder = [
-            UUID_TRANSFER,
+            UUID_RECORD,
             uuid,
             action,
             path,

+ 0 - 0
src/core/callcenter/handler/__init__.py → src/core/callcenter/esl/constant/__init__.py


+ 0 - 0
src/core/callcenter/constant/esl_constant.py → src/core/callcenter/esl/constant/esl_constant.py


+ 0 - 0
src/core/callcenter/constant/event_names.py → src/core/callcenter/esl/constant/event_names.py


+ 0 - 0
src/core/callcenter/constant/sip_header_constant.py → src/core/callcenter/esl/constant/sip_header_constant.py


+ 0 - 0
src/core/callcenter/esl/handler/__init__.py


+ 3 - 3
src/core/callcenter/handler/channel_answer_handler.py → src/core/callcenter/esl/handler/channel_answer_handler.py

@@ -1,9 +1,9 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
-from src.core.callcenter.annotation import EslEventName
-from src.core.callcenter.constant.event_names import CHANNEL_ANSWER
-from src.core.callcenter.handler.esl_event_handler import EslEventHandler
+from src.core.callcenter.esl.annotation import EslEventName
+from src.core.callcenter.esl.constant.event_names import CHANNEL_ANSWER
+from src.core.callcenter.esl.handler.esl_event_handler import EslEventHandler
 
 
 @EslEventName(CHANNEL_ANSWER)

+ 3 - 3
src/core/callcenter/handler/channel_bridge_handler.py → src/core/callcenter/esl/handler/channel_bridge_handler.py

@@ -1,9 +1,9 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
-from src.core.callcenter.annotation import EslEventName
-from src.core.callcenter.constant.event_names import CHANNEL_BRIDGE
-from src.core.callcenter.handler.esl_event_handler import EslEventHandler
+from src.core.callcenter.esl.annotation import EslEventName
+from src.core.callcenter.esl.constant.event_names import CHANNEL_BRIDGE
+from src.core.callcenter.esl.handler.esl_event_handler import EslEventHandler
 
 
 @EslEventName(CHANNEL_BRIDGE)

+ 3 - 3
src/core/callcenter/handler/channel_hangup_complete_handler.py → src/core/callcenter/esl/handler/channel_hangup_complete_handler.py

@@ -1,9 +1,9 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
-from src.core.callcenter.annotation import EslEventName
-from src.core.callcenter.constant.event_names import CHANNEL_HANGUP_COMPLETE
-from src.core.callcenter.handler.esl_event_handler import EslEventHandler
+from src.core.callcenter.esl.annotation import EslEventName
+from src.core.callcenter.esl.constant.event_names import CHANNEL_HANGUP_COMPLETE
+from src.core.callcenter.esl.handler.esl_event_handler import EslEventHandler
 
 
 @EslEventName(CHANNEL_HANGUP_COMPLETE)

+ 3 - 3
src/core/callcenter/handler/channel_hangup_handler.py → src/core/callcenter/esl/handler/channel_hangup_handler.py

@@ -1,9 +1,9 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
-from src.core.callcenter.annotation import EslEventName
-from src.core.callcenter.constant.event_names import CHANNEL_HANGUP
-from src.core.callcenter.handler.esl_event_handler import EslEventHandler
+from src.core.callcenter.esl.annotation import EslEventName
+from src.core.callcenter.esl.constant.event_names import CHANNEL_HANGUP
+from src.core.callcenter.esl.handler.esl_event_handler import EslEventHandler
 
 
 @EslEventName(CHANNEL_HANGUP)

+ 3 - 3
src/core/callcenter/handler/channel_park_handler.py → src/core/callcenter/esl/handler/channel_park_handler.py

@@ -1,9 +1,9 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
-from src.core.callcenter.annotation import EslEventName
-from src.core.callcenter.constant.event_names import CHANNEL_PARK
-from src.core.callcenter.handler.esl_event_handler import EslEventHandler
+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
 
 
 @EslEventName(CHANNEL_PARK)

+ 3 - 3
src/core/callcenter/handler/channel_progress_media_handler.py → src/core/callcenter/esl/handler/channel_progress_media_handler.py

@@ -1,9 +1,9 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
-from src.core.callcenter.annotation import EslEventName
-from src.core.callcenter.constant.event_names import CHANNEL_PROGRESS_MEDIA
-from src.core.callcenter.handler.esl_event_handler import EslEventHandler
+from src.core.callcenter.esl.annotation import EslEventName
+from src.core.callcenter.esl.constant.event_names import CHANNEL_PROGRESS_MEDIA
+from src.core.callcenter.esl.handler.esl_event_handler import EslEventHandler
 
 
 @EslEventName(CHANNEL_PROGRESS_MEDIA)

+ 1 - 1
src/core/callcenter/handler/default_esl_event_handler.py → src/core/callcenter/esl/handler/default_esl_event_handler.py

@@ -2,7 +2,7 @@
 # encoding:utf-8
 
 import json
-from src.core.callcenter.handler.esl_event_handler import EslEventHandler
+from src.core.callcenter.esl.handler.esl_event_handler import EslEventHandler
 
 
 class DefaultEslEventHandler(EslEventHandler):

+ 3 - 3
src/core/callcenter/handler/detected_tone_handler.py → src/core/callcenter/esl/handler/detected_tone_handler.py

@@ -2,9 +2,9 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
-from src.core.callcenter.annotation import EslEventName
-from src.core.callcenter.constant.event_names import DETECTED_TONE
-from src.core.callcenter.handler.esl_event_handler import EslEventHandler
+from src.core.callcenter.esl.annotation import EslEventName
+from src.core.callcenter.esl.constant.event_names import DETECTED_TONE
+from src.core.callcenter.esl.handler.esl_event_handler import EslEventHandler
 
 
 @EslEventName(DETECTED_TONE)

+ 3 - 3
src/core/callcenter/handler/dtmf_handler.py → src/core/callcenter/esl/handler/dtmf_handler.py

@@ -1,9 +1,9 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
-from src.core.callcenter.annotation import EslEventName
-from src.core.callcenter.constant.event_names import DTMF
-from src.core.callcenter.handler.esl_event_handler import EslEventHandler
+from src.core.callcenter.esl.annotation import EslEventName
+from src.core.callcenter.esl.constant.event_names import DTMF
+from src.core.callcenter.esl.handler.esl_event_handler import EslEventHandler
 
 
 @EslEventName(DTMF)

+ 0 - 0
src/core/callcenter/handler/esl_event_handler.py → src/core/callcenter/esl/handler/esl_event_handler.py


+ 3 - 3
src/core/callcenter/handler/playback_stop_handler.py → src/core/callcenter/esl/handler/playback_stop_handler.py

@@ -1,9 +1,9 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
-from src.core.callcenter.annotation import EslEventName
-from src.core.callcenter.constant.event_names import PLAYBACK_STOP
-from src.core.callcenter.handler.esl_event_handler import EslEventHandler
+from src.core.callcenter.esl.annotation import EslEventName
+from src.core.callcenter.esl.constant.event_names import PLAYBACK_STOP
+from src.core.callcenter.esl.handler.esl_event_handler import EslEventHandler
 
 
 @EslEventName(PLAYBACK_STOP)

+ 3 - 3
src/core/callcenter/handler/record_stop_handler.py → src/core/callcenter/esl/handler/record_stop_handler.py

@@ -1,9 +1,9 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
-from src.core.callcenter.annotation import EslEventName
-from src.core.callcenter.constant.event_names import RECORD_STOP
-from src.core.callcenter.handler.esl_event_handler import EslEventHandler
+from src.core.callcenter.esl.annotation import EslEventName
+from src.core.callcenter.esl.constant.event_names import RECORD_STOP
+from src.core.callcenter.esl.handler.esl_event_handler import EslEventHandler
 
 
 @EslEventName(RECORD_STOP)

+ 2 - 1
src/core/callcenter/utils/call_cache_util.py → src/core/callcenter/esl/utils/call_cache_util.py

@@ -2,7 +2,8 @@
 # encoding:utf-8
 
 import json
-from src.core.callcenter.constant.constant import *
+
+from src.core.callcenter.constant import *
 from src.core.callcenter.model import AgentInfo, CallInfo, RouteGateway
 from src.core.datasource import RedisHandler
 

+ 0 - 0
src/core/callcenter/utils/esl_event_util.py → src/core/callcenter/esl/utils/esl_event_util.py


BIN
src/core/callcenter/handler/__pycache__/__init__.cpython-39.pyc


BIN
src/core/callcenter/handler/__pycache__/channel_answer_handler.cpython-39.pyc


BIN
src/core/callcenter/handler/__pycache__/channel_bridge_handler.cpython-39.pyc


BIN
src/core/callcenter/handler/__pycache__/channel_hangup_complete_handler.cpython-39.pyc


BIN
src/core/callcenter/handler/__pycache__/channel_hangup_handler.cpython-39.pyc


BIN
src/core/callcenter/handler/__pycache__/channel_park_handler.cpython-39.pyc


BIN
src/core/callcenter/handler/__pycache__/channel_progress_media_handler.cpython-39.pyc


BIN
src/core/callcenter/handler/__pycache__/default_esl_event_handler.cpython-39.pyc


BIN
src/core/callcenter/handler/__pycache__/detected_tone_handler.cpython-39.pyc


BIN
src/core/callcenter/handler/__pycache__/dtmf_handler.cpython-39.pyc


BIN
src/core/callcenter/handler/__pycache__/esl_event_handler.cpython-39.pyc


BIN
src/core/callcenter/handler/__pycache__/playback_stop_handler.cpython-39.pyc


BIN
src/core/callcenter/handler/__pycache__/record_stop_handler.cpython-39.pyc


+ 52 - 0
src/core/callcenter/model.py

@@ -3,6 +3,58 @@
 
 import json
 from urllib.parse import urlparse
+from typing import Dict, Any, Optional
+
+from src.core.callcenter.enumeration import CallType
+
+
+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
+        # 呼叫类型
+        self.call_type: CallType = call_type
+        # 主叫,如果没有传,则使用坐席号码
+        self.caller: Optional[str] = caller
+        # 被叫
+        self.called: str = called
+        # 主叫显号,接口没有传就用主技能组配置
+        self.caller_display: Optional[str] = caller_display
+        # 被叫显号,接口没传就用主技能配置
+        self.called_display: Optional[str] = called_display
+
+    def to_json_string(self):
+        return json.dumps(self.__dict__, ensure_ascii=False)
+
+    @classmethod
+    def from_json(cls, json_string):
+        data = json.loads(json_string)
+        return cls(**data)
+
+
+class HangupCallRequest:
+    def __init__(self, saas_id, call_id, agent_number):
+        # saasId(必填)
+        self.saas_id = saas_id
+        # 呼叫唯一id(选填)
+        self.call_id = call_id
+        # 分机号(必填)
+        self.agent_number = agent_number
+
+
+class CheckInCallRequest:
+    """检查是否在通话中实体"""
+    def __init__(self, saas_id, agent_number):
+        self.saas_id = saas_id
+        self.agent_number = agent_number
 
 
 class AgentInfo:

+ 34 - 5
src/core/callcenter/server.py

@@ -2,10 +2,38 @@
 # encoding:utf-8
 import threading
 
-from flask import Flask
-from src.core.callcenter.client import InboundClient
+from flask import Flask, render_template_string
+from src.core.callcenter.esl.client import InboundClient
 
 app = Flask(__name__)
+app.config['SECRET_KEY'] = ''
+inbound_client = InboundClient()
+
+
+@app.route('/')
+def index():
+    return render_template_string("""<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>SocketIO Example</title>
+    <script src="https://cdn.socket.io/4.0.0/socket.io.min.js"></script>
+</head>
+<body>
+    <h1>SocketIO Test</h1>
+    <script>
+        var socket = io('/ws/cs-im');
+        socket.on('response', function(msg) {
+            alert(msg);
+        });
+
+        socket.on('login', function(msg) {
+            alert('Received from server: ' + msg);
+        });
+        socket.emit('login', {'appCode':'1111','userId':'1111','token':'1111'});
+    </script>
+</body>
+</html>""")
 
 
 @app.route('/open/agent/get-cdn-url', methods=['POST'])
@@ -105,8 +133,9 @@ def num_generate():
 
 
 if __name__ == '__main__':
-    on = InboundClient()
     # out = OutboundClient()
     # threading.Thread(target=out.start, args=()).start()
-    threading.Thread(target=on.start, args=()).start()
-    app.run(host='127.0.0.1', port=5000, debug=True)
+    # threading.Thread(target=on.start, args=()).start()
+    from src.core.callcenter.ws import socketio
+    socketio.run(app, host='127.0.0.1', port=5000, allow_unsafe_werkzeug=True, debug=True)
+    # app.run(host='127.0.0.1', port=5000, debug=True)

BIN
src/core/callcenter/utils/__pycache__/call_cache_util.cpython-38.pyc


BIN
src/core/callcenter/utils/__pycache__/esl_event_util.cpython-39.pyc


+ 57 - 0
src/core/callcenter/ws.py

@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+# encoding:utf-8
+
+import logging
+from src.core.callcenter.server import app
+from flask import request, session
+from flask_socketio import SocketIO, Namespace, join_room, leave_room, emit
+
+socketio = SocketIO(app)
+logger = logging.getLogger(__name__)
+
+
+def common_down_data(user_id, data):
+    emit('common_down_data', data, room=user_id)
+
+
+def common_down_cmd(user_id, data):
+    emit('common_down_cmd', data, room=user_id)
+
+
+class MyNamespace(Namespace):
+
+    def on_connect(self):
+        logger.info('Client connected, {}', request.sid)
+
+    def on_login(self, msg):
+        print('login.Received message: {}, {}', str(msg), request.sid)
+        user_id = msg.get('userId')
+        session['user_id'] = user_id
+        join_room(user_id)
+        emit('login', request.sid)
+
+    def on_heartbeat(self, heartbeat):
+        pass
+
+    def on_OnPrompt(self, event):
+        pass
+
+    def on_OnSocketEvent(self, event):
+        pass
+
+    def on_OnSipEvent(self, event):
+        pass
+
+    def on_OnInitalFailure(self, event):
+        pass
+
+    def on_OnCallAnswer(self, msg):
+        pass
+
+    def on_disconnect(self):
+        user_id = session.get('user_id')
+        leave_room(user_id)
+        print('Client disconnected', user_id)
+
+
+socketio.on_namespace(MyNamespace('/ws/cs-im'))

+ 1 - 12
src/core/datasource.py

@@ -10,9 +10,9 @@ import decimal
 import traceback
 import pymysql
 import os
+from src.core import singleton
 from redis import StrictRedis, ConnectionPool
 
-# from constant import *
 
 RADIS_HOST = os.environ.get("REDIS_HOST", "10.0.0.24")
 
@@ -26,17 +26,6 @@ else:
     MYSQL_PASSWORD = "Hongshan2024@longjiang"
 
 
-def singleton(cls):
-    _instance = {}
-
-    def inner():
-        if cls not in _instance:
-            _instance[cls] = cls()
-        return _instance[cls]
-
-    return inner
-
-
 # @singleton
 class MysqlHandler:
     """