views.py 6.6 KB

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