#!/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("""
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():
"""获取初始化配置"""
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!'