123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- #!/usr/bin/env python3
- # encoding:utf-8
- import os
- import json
- import threading
- import src.core.callcenter.cache as Cache
- from src.core.callcenter import create_app
- from src.core.callcenter.agent import AgentService, AgentOperService
- from src.core.callcenter.constant import success
- from src.core.callcenter.enumeration import CallType
- from src.core.callcenter.esl.client import InboundClient, OutboundClient
- from flask import Flask, request, render_template_string
- from src.core.callcenter.call import CallService
- from src.core.callcenter.model import MakeCallRequest, AgentInfo, AgentActionRequest, HangupCallRequest
- from src.core.voip.bot import BotAgent
- app = create_app()
- agent = BotAgent(app.logger)
- inbound_client = InboundClient(agent, app.logger)
- outbound_client = OutboundClient(agent, app.logger)
- call_service = CallService(inbound_client, app.logger)
- agent_service = AgentService(inbound_client, app.logger)
- agent_oper_service = AgentOperService(inbound_client, app.logger)
- @app.route('/')
- def index():
- return render_template_string("""<!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>SocketIO Example</title>
- <script src="https://cdn.socket.io/4.0.0/socket.io.min.js"></script>
- </head>
- <body>
- <h1>SocketIO Test</h1>
- <script>
- var socket = io('/ws/cs-im');
- socket.on('response', function(msg) {
- alert(msg);
- });
- socket.on('login', function(msg) {
- alert('Received from server: ' + msg);
- });
- socket.emit('login', {'appCode':'1111','userId':'1111','token':'1111'});
- </script>
- </body>
- </html>""")
- @app.route('/open/agent/get-cdn-url', methods=['POST'])
- def get_cdn_url():
- """获取cdn地址"""
- return 'Hello World!'
- @app.route('/open/agent/get-init-config', methods=['POST'])
- def get_init_config():
- """获取初始化配置"""
- return 'Hello World!'
- @app.route('/open/agent/check-in', methods=['POST'])
- def check_in():
- """坐席签入"""
- data = request.get_json()
- param = AgentActionRequest.from_json(data=data)
- res = agent_oper_service.checkin(param)
- return success(res)
- @app.route('/open/agent/check-out', methods=['POST'])
- def check_out():
- """坐席签出"""
- data = request.get_json()
- param = AgentActionRequest.from_json(data=data)
- return agent_oper_service.checkout(param)
- @app.route('/open/agent/busy', methods=['POST'])
- def busy():
- """坐席置忙"""
- data = request.get_json()
- param = AgentActionRequest.from_json(data=data)
- return agent_oper_service.checkin(param)
- @app.route('/open/agent/idle', methods=['POST'])
- def idle():
- """坐席置闲"""
- data = request.get_json()
- param = AgentActionRequest.from_json(data=data)
- return agent_oper_service.checkin(param)
- @app.route('/open/agent/turn-on', methods=['POST'])
- def turn_on():
- """接通"""
- data = request.get_json()
- param = AgentActionRequest.from_json(data=data)
- return agent_oper_service.checkin(param)
- @app.route('/open/agent/hang-up', methods=['POST'])
- def hang_up():
- """挂断"""
- data = request.get_json()
- param = AgentActionRequest.from_json(data=data)
- return call_service.hangup(param)
- @app.route('/open/agent/agent-state', methods=['POST'])
- def agent_state():
- """获取坐席状态"""
- return 'Hello World!'
- @app.route('/open/agent/manual-call', methods=['POST'])
- def manual_call():
- """外呼"""
- # agentId: string
- # vccId: string
- # password: string
- # scene: string
- # ctiFlowId?: string
- # monitorScene?: string
- # called: string
- # circuitUid: string
- # ext?: object
- # callId: string
- data = request.json()
- agent = Cache.get_agent_info(data.get('agentId'))
- 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'))
- res = call_service.call(req, agent)
- return success(res)
- @app.route('/open/agent/manual-hang', methods=['POST'])
- def manual_hang():
- """挂断"""
- data = request.json()
- agent = Cache.get_agent_info(data.get('agentId'))
- req = HangupCallRequest(saas_id=data.get('vccId'), call_id=data.get('callId'), agent_number=agent.agent_number)
- call_service.hangup(req)
- return success()
- @app.route('/open/agent/listen', methods=['POST'])
- def listen():
- """发起监听"""
- return 'Hello World!'
- @app.route('/open/agent/reload-phone', methods=['POST'])
- def reload_phone():
- """重新获取分机信息"""
- return 'Hello World!'
- @app.route('/open/monitor/load-agent-group-data', methods=['POST'])
- def load_agent_group_data():
- """获取监控组成员信息"""
- return 'Hello World!'
- @app.route('/open/human-service/member-active', methods=['POST'])
- def member_active():
- """机器人外呼-签入人工组"""
- return 'Hello World!'
- @app.route('/open/num/generate', methods=['POST'])
- def num_generate():
- """获取 cti 流程 ID"""
- return 'Hello World!'
|