views.py 5.8 KB

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