views.py 5.8 KB

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