views.py 5.5 KB

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