views.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #!/usr/bin/env python3
  2. # encoding:utf-8
  3. from . import app
  4. import src.core.callcenter.cache as Cache
  5. from src.core.callcenter.agent import AgentService, AgentOperService
  6. from src.core.callcenter.constant import success_response, error_response
  7. from src.core.callcenter.enumeration import CallType
  8. from src.core.callcenter.esl.client import InboundClient, OutboundClient
  9. from flask import Flask, request, render_template_string
  10. from src.core.callcenter.call import CallService
  11. from src.core.callcenter.api import AgentCallRequest, AgentActionRequest, HangupCallRequest, \
  12. HumanServiceQueryRequest
  13. from src.core.voip.bot import BotAgent
  14. agent = BotAgent(app.logger)
  15. inbound_client = InboundClient(agent, app.logger)
  16. outbound_client = OutboundClient(agent, app.logger)
  17. call_service = CallService(inbound_client, app.logger)
  18. agent_service = AgentService(inbound_client, app.logger)
  19. agent_oper_service = AgentOperService(inbound_client, app.logger)
  20. @app.route('/')
  21. def index():
  22. return render_template_string("""<!DOCTYPE html>
  23. <html lang="en">
  24. <head>
  25. <meta charset="UTF-8">
  26. <title>SocketIO Example</title>
  27. <script src="https://cdn.socket.io/4.0.0/socket.io.min.js"></script>
  28. </head>
  29. <body>
  30. <h1>SocketIO Test</h1>
  31. <script>
  32. var socket = io('ws://192.168.100.159:8091/ws/cs-im');
  33. socket.on('response', function(msg) {
  34. alert(msg);
  35. });
  36. socket.on('login', function(msg) {
  37. alert('Received from server: ' + msg);
  38. });
  39. socket.emit('login', {'appCode':'1111','userId':'1111','token':'1111'});
  40. </script>
  41. </body>
  42. </html>""")
  43. @app.route('/open/agent/get-cdn-url', methods=['POST'])
  44. def get_cdn_url():
  45. """获取cdn地址"""
  46. return 'Hello World!'
  47. @app.route('/open/agent/get-init-config', methods=['POST'])
  48. def get_init_config():
  49. """获取初始化配置"""
  50. try:
  51. data = request.get_json()
  52. param = AgentActionRequest.from_json(data)
  53. res = agent_service.get_and_check(param)
  54. return success_response(res)
  55. except Exception as e:
  56. print("Exception occurred: %s", str(e))
  57. return error_response(e)
  58. @app.route('/open/agent/check-in', methods=['POST'])
  59. def check_in():
  60. """坐席签入"""
  61. try:
  62. data = request.get_json()
  63. param = AgentActionRequest.from_json(data)
  64. res = agent_oper_service.checkin(param)
  65. return success_response(res)
  66. except Exception as e:
  67. print("Exception occurred: %s", str(e))
  68. return error_response(e)
  69. @app.route('/open/agent/check-out', methods=['POST'])
  70. def check_out():
  71. """坐席签出"""
  72. try:
  73. data = request.get_json()
  74. param = AgentActionRequest.from_json(data)
  75. res= agent_oper_service.checkout(param)
  76. return success_response(res)
  77. except Exception as e:
  78. print("Exception occurred: %s", str(e))
  79. return error_response(e)
  80. @app.route('/open/agent/busy', methods=['POST'])
  81. def busy():
  82. """坐席置忙"""
  83. try:
  84. data = request.get_json()
  85. param = AgentActionRequest.from_json(data)
  86. res= agent_oper_service.busy(param)
  87. return success_response(res)
  88. except Exception as e:
  89. print("Exception occurred: %s", str(e))
  90. return error_response(e)
  91. @app.route('/open/agent/idle', methods=['POST'])
  92. def idle():
  93. """坐席置闲"""
  94. try:
  95. data = request.get_json()
  96. param = AgentActionRequest.from_json(data)
  97. res = agent_oper_service.idle(param)
  98. return success_response(res)
  99. except Exception as e:
  100. print("Exception occurred: %s", str(e))
  101. return {"error": "An error occurred", "details": str(e)}, 500
  102. @app.route('/open/agent/turn-on', methods=['POST'])
  103. def turn_on():
  104. """接通"""
  105. try:
  106. data = request.get_json()
  107. param = AgentActionRequest.from_json(data)
  108. return agent_oper_service.checkin(param)
  109. except Exception as e:
  110. print("Exception occurred: %s", str(e))
  111. return {"error": "An error occurred", "details": str(e)}, 500
  112. @app.route('/open/agent/hang-up', methods=['POST'])
  113. def hang_up():
  114. """挂断"""
  115. try:
  116. data = request.get_json()
  117. param = AgentActionRequest.from_json(data)
  118. res = call_service.hangup(param)
  119. return success_response(res)
  120. except Exception as e:
  121. print("Exception occurred: %s", str(e))
  122. return {"error": "An error occurred", "details": str(e)}, 500
  123. @app.route('/open/agent/agent-state', methods=['POST'])
  124. def agent_state():
  125. """获取坐席状态"""
  126. try:
  127. data = request.get_json()
  128. param = HumanServiceQueryRequest.from_json(data)
  129. res = agent_service.watch_agent_state(param)
  130. return success_response(res)
  131. except Exception as e:
  132. print("Exception occurred: %s", str(e))
  133. return {"error": "An error occurred", "details": str(e)}, 500
  134. @app.route('/open/agent/manual-call', methods=['POST'])
  135. def manual_call():
  136. """外呼"""
  137. # agentId: string
  138. # vccId: string
  139. # password: string
  140. # scene: string
  141. # ctiFlowId?: string
  142. # monitorScene?: string
  143. # called: string
  144. # circuitUid: string
  145. # ext?: object
  146. # callId: string
  147. data = request.get_json()
  148. req = AgentCallRequest(saas_id=data.get('saas_id'), call_type=CallType.OUTBOUND_CALL, caller=data.get('caller'),
  149. agent_id=data.get('agent_id'), called=data.get('called'), cti_flow_id=data.get('ctiFlowId'))
  150. res = call_service.call(req)
  151. return success_response(res)
  152. @app.route('/open/agent/manual-hang', methods=['POST'])
  153. def manual_hang():
  154. """挂断"""
  155. data = request.get_json()
  156. agent = Cache.get_agent_info(data.get('saas_id'), data.get('agent_id'))
  157. req = HangupCallRequest(saas_id=data.get('saas_id'), call_id=data.get('call_id'), agent_number=agent.agent_number)
  158. call_service.hangup(req)
  159. return success_response()
  160. @app.route('/open/agent/listen', methods=['POST'])
  161. def listen():
  162. """发起监听"""
  163. return 'Hello World!'
  164. @app.route('/open/agent/reload-phone', methods=['POST'])
  165. def reload_phone():
  166. """重新获取分机信息"""
  167. return 'Hello World!'
  168. @app.route('/open/monitor/load-agent-group-data', methods=['POST'])
  169. def load_agent_group_data():
  170. """获取监控组成员信息"""
  171. return 'Hello World!'
  172. @app.route('/open/human-service/member-active', methods=['POST'])
  173. def member_active():
  174. """机器人外呼-签入人工组"""
  175. return 'Hello World!'
  176. @app.route('/open/num/generate', methods=['POST'])
  177. def num_generate():
  178. """获取 cti 流程 ID"""
  179. flow_id = call_service.snowflake.next_id()
  180. return success_response(flow_id)