web.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #!/usr/bin/env python3
  2. # encoding:utf-8
  3. import os
  4. import json
  5. import threading
  6. import src.core.callcenter.cache as Cache
  7. from src.core.callcenter import create_app
  8. from src.core.callcenter.agent import AgentService, AgentOperService
  9. from src.core.callcenter.constant import success
  10. from src.core.callcenter.enumeration import CallType
  11. from src.core.callcenter.esl.client import InboundClient, OutboundClient
  12. from flask import Flask, request, render_template_string
  13. from src.core.callcenter.call import CallService
  14. from src.core.callcenter.model import MakeCallRequest, AgentInfo, AgentActionRequest, HangupCallRequest
  15. from src.core.voip.bot import BotAgent
  16. app = create_app()
  17. agent = BotAgent(app.logger)
  18. inbound_client = InboundClient(agent, app.logger)
  19. outbound_client = OutboundClient(agent, app.logger)
  20. call_service = CallService(inbound_client, app.logger)
  21. agent_service = AgentService(inbound_client, app.logger)
  22. agent_oper_service = AgentOperService(inbound_client, app.logger)
  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/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. return 'Hello World!'
  54. @app.route('/open/agent/check-in', methods=['POST'])
  55. def check_in():
  56. """坐席签入"""
  57. data = request.get_json()
  58. param = AgentActionRequest.from_json(data=data)
  59. res = agent_oper_service.checkin(param)
  60. return success(res)
  61. @app.route('/open/agent/check-out', methods=['POST'])
  62. def check_out():
  63. """坐席签出"""
  64. data = request.get_json()
  65. param = AgentActionRequest.from_json(data=data)
  66. return agent_oper_service.checkout(param)
  67. @app.route('/open/agent/busy', methods=['POST'])
  68. def busy():
  69. """坐席置忙"""
  70. data = request.get_json()
  71. param = AgentActionRequest.from_json(data=data)
  72. return agent_oper_service.checkin(param)
  73. @app.route('/open/agent/idle', methods=['POST'])
  74. def idle():
  75. """坐席置闲"""
  76. data = request.get_json()
  77. param = AgentActionRequest.from_json(data=data)
  78. return agent_oper_service.checkin(param)
  79. @app.route('/open/agent/turn-on', methods=['POST'])
  80. def turn_on():
  81. """接通"""
  82. data = request.get_json()
  83. param = AgentActionRequest.from_json(data=data)
  84. return agent_oper_service.checkin(param)
  85. @app.route('/open/agent/hang-up', methods=['POST'])
  86. def hang_up():
  87. """挂断"""
  88. data = request.get_json()
  89. param = AgentActionRequest.from_json(data=data)
  90. return call_service.hangup(param)
  91. @app.route('/open/agent/agent-state', methods=['POST'])
  92. def agent_state():
  93. """获取坐席状态"""
  94. return 'Hello World!'
  95. @app.route('/open/agent/manual-call', methods=['POST'])
  96. def manual_call():
  97. """外呼"""
  98. # agentId: string
  99. # vccId: string
  100. # password: string
  101. # scene: string
  102. # ctiFlowId?: string
  103. # monitorScene?: string
  104. # called: string
  105. # circuitUid: string
  106. # ext?: object
  107. # callId: string
  108. data = request.json()
  109. agent = Cache.get_agent_info(data.get('agentId'))
  110. req = MakeCallRequest(saas_id=data.get('vccId'), call_type=CallType.OUTBOUND_CALL, caller=agent.agent_number, called=data.get('called'), follow_data=data.get('ext'))
  111. res = call_service.call(req, agent)
  112. return success(res)
  113. @app.route('/open/agent/manual-hang', methods=['POST'])
  114. def manual_hang():
  115. """挂断"""
  116. data = request.json()
  117. agent = Cache.get_agent_info(data.get('agentId'))
  118. req = HangupCallRequest(saas_id=data.get('vccId'), call_id=data.get('callId'), agent_number=agent.agent_number)
  119. call_service.hangup(req)
  120. return success()
  121. @app.route('/open/agent/listen', methods=['POST'])
  122. def listen():
  123. """发起监听"""
  124. return 'Hello World!'
  125. @app.route('/open/agent/reload-phone', methods=['POST'])
  126. def reload_phone():
  127. """重新获取分机信息"""
  128. return 'Hello World!'
  129. @app.route('/open/monitor/load-agent-group-data', methods=['POST'])
  130. def load_agent_group_data():
  131. """获取监控组成员信息"""
  132. return 'Hello World!'
  133. @app.route('/open/human-service/member-active', methods=['POST'])
  134. def member_active():
  135. """机器人外呼-签入人工组"""
  136. return 'Hello World!'
  137. @app.route('/open/num/generate', methods=['POST'])
  138. def num_generate():
  139. """获取 cti 流程 ID"""
  140. return 'Hello World!'