#!/usr/bin/env python3 # encoding:utf-8 from . import app import src.core.callcenter.cache as Cache from src.core.callcenter.agent import AgentService, AgentOperService from src.core.callcenter.constant import success_response, error_response 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.api import AgentCallRequest, AgentActionRequest, HangupCallRequest, \ HumanServiceQueryRequest from src.core.voip.bot import BotAgent 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(""" 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(): """获取初始化配置""" try: data = request.get_json() param = AgentActionRequest.from_json(data) res = agent_service.get_and_check(param) return success_response(res) except Exception as e: print("Exception occurred: %s", str(e)) return error_response(e) @app.route('/open/agent/check-in', methods=['POST']) def check_in(): """坐席签入""" try: data = request.get_json() param = AgentActionRequest.from_json(data) res = agent_oper_service.checkin(param) return success_response(res) except Exception as e: print("Exception occurred: %s", str(e)) return error_response(e) @app.route('/open/agent/check-out', methods=['POST']) def check_out(): """坐席签出""" try: data = request.get_json() param = AgentActionRequest.from_json(data) res= agent_oper_service.checkout(param) return success_response(res) except Exception as e: print("Exception occurred: %s", str(e)) return error_response(e) @app.route('/open/agent/busy', methods=['POST']) def busy(): """坐席置忙""" try: data = request.get_json() param = AgentActionRequest.from_json(data) res= agent_oper_service.busy(param) return success_response(res) except Exception as e: print("Exception occurred: %s", str(e)) return error_response(e) @app.route('/open/agent/idle', methods=['POST']) def idle(): """坐席置闲""" try: data = request.get_json() param = AgentActionRequest.from_json(data) res = agent_oper_service.idle(param) return success_response(res) except Exception as e: print("Exception occurred: %s", str(e)) return {"error": "An error occurred", "details": str(e)}, 500 @app.route('/open/agent/turn-on', methods=['POST']) def turn_on(): """接通""" try: data = request.get_json() param = AgentActionRequest.from_json(data) return agent_oper_service.checkin(param) except Exception as e: print("Exception occurred: %s", str(e)) return {"error": "An error occurred", "details": str(e)}, 500 @app.route('/open/agent/hang-up', methods=['POST']) def hang_up(): """挂断""" try: data = request.get_json() param = AgentActionRequest.from_json(data) res = call_service.hangup(param) return success_response(res) except Exception as e: print("Exception occurred: %s", str(e)) return {"error": "An error occurred", "details": str(e)}, 500 @app.route('/open/agent/agent-state', methods=['POST']) def agent_state(): """获取坐席状态""" try: data = request.get_json() param = HumanServiceQueryRequest.from_json(data) res = agent_service.watch_agent_state(param) return success_response(res) except Exception as e: print("Exception occurred: %s", str(e)) return {"error": "An error occurred", "details": str(e)}, 500 @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.OUTBOUND_CALL, 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'), call_id=data.get('call_id'), agent_number=agent.agent_number) call_service.hangup(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)