#!/usr/bin/env python3 # encoding:utf-8 from flask import request, render_template_string from src.core.callcenter.agent import AgentService, AgentOperService from src.core.callcenter.api import AgentCallRequest, AgentActionRequest, HangupCallRequest from src.core.callcenter.call import CallService from src.core.callcenter.constant import success_response from src.core.callcenter.enumeration import CallType from src.core.callcenter.esl.client import InboundClient, OutboundClient from src.core.voip.bot import BotAgent from . import app from .acd import AcdService agent = BotAgent(app) inbound_client = InboundClient(agent,app) outbound_client = OutboundClient(agent,app) call_service = CallService(inbound_client, app) agent_service = AgentService(app) agent_oper_service = AgentOperService(app) acd_service = AcdService(inbound_client, app) agent.acd_service = acd_service @app.route('/') def index(): return render_template_string(""" SocketIO Example

SocketIO Test

""") @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(): """获取初始化配置""" data = request.get_json() param = AgentActionRequest.from_json(data) res = agent_service.get_and_check(param) return success_response(res) @app.route('/open/agent/check-in', methods=['POST']) def check_in(): """坐席签入""" data = request.get_json() param = AgentActionRequest.from_json(data) res = agent_oper_service.checkin(param) return success_response(res) @app.route('/open/agent/check-out', methods=['POST']) def check_out(): """坐席签出""" data = request.get_json() param = AgentActionRequest.from_json(data) res = agent_oper_service.checkout(param) return success_response(res) @app.route('/open/agent/busy', methods=['POST']) def busy(): """坐席置忙""" data = request.get_json() param = AgentActionRequest.from_json(data) res = agent_oper_service.busy(param) return success_response(res) @app.route('/open/agent/idle', methods=['POST']) def idle(): """坐席置闲""" data = request.get_json() param = AgentActionRequest.from_json(data) res = agent_oper_service.idle(param) return success_response(res) @app.route('/open/agent/turn-on', methods=['POST']) def turn_on(): """接通""" data = request.get_json() param = AgentActionRequest.from_json(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) res = call_service.hangup(param) return success_response(res) @app.route('/open/agent/agent-state', methods=['POST']) def agent_state(): """获取坐席状态""" data = request.get_json() # param = HumanServiceQueryRequest.from_json(data) # res = agent_service.watch_agent_state(param) param = AgentActionRequest.from_json(data) res = agent_oper_service.agent_state(param) return success_response(res) @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.get_json() req = AgentCallRequest(saas_id=data.get('saas_id'), call_type=CallType.AGENT_CALL.code, caller=data.get('caller'), agent_id=data.get('agent_id'), called=data.get('called'), cti_flow_id=data.get('ctiFlowId')) res = call_service.call(req) return success_response(res) @app.route('/open/agent/manual-hang', methods=['POST']) def manual_hang(): """挂断""" data = request.get_json() # agent = Cache.get_agent_info(data.get('saas_id'), data.get('agent_id')) 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')) call_service.hangup_by_scene(req) return success_response() @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""" flow_id = call_service.snowflake.next_id() return success_response(flow_id)