123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- #!/usr/bin/env python3
- # encoding:utf-8
- import json
- import threading
- from logging.config import dictConfig
- import src.core.callcenter.cache as Cache
- from src.core.callcenter.agent import AgentService
- from src.core.callcenter.constant import success
- from src.core.callcenter.enumeration import CallType
- from src.core.callcenter.esl.client import InboundClient
- 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
- dictConfig({
- "version": 1,
- "disable_existing_loggers": False, # 不覆盖默认配置
- "formatters": { # 日志输出样式
- "default": {
- "format": "%(asctime)s - %(module)s.%(lineno)d - %(levelname)s - %(threadName)s: %(message)s"
- }
- },
- "handlers": {
- "console": {
- "class": "logging.StreamHandler", # 控制台输出
- "level": "DEBUG",
- "formatter": "default",
- },
- "log_file": {
- "class": "logging.handlers.RotatingFileHandler",
- "level": "INFO",
- "formatter": "default", # 日志输出样式对应formatters
- "filename": "./logs/flask.log", # 指定log文件目录
- "maxBytes": 20*1024*1024, # 文件最大20M
- "backupCount": 10, # 最多10个文件
- "encoding": "utf8", # 文件编码
- },
- },
- "root": {
- "level": "INFO", # # handler中的level会覆盖掉这里的level
- "handlers": ["console", "log_file"],
- },
- }
- )
- app = Flask(__name__)
- app.config['SECRET_KEY'] = ''
- client = InboundClient(app.logger)
- call_service = CallService(client, app.logger)
- agent_service = AgentService(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():
- """坐席签入"""
- param = AgentActionRequest.from_json(json_object=request.json())
- return agent_service.checkin(param)
- @app.route('/open/agent/check-out', methods=['POST'])
- def check_out():
- """坐席签出"""
- param = AgentActionRequest.from_json(json_object=request.json())
- return agent_service.checkin(param)
- return 'Hello World!'
- @app.route('/open/agent/busy', methods=['POST'])
- def busy():
- """坐席置忙"""
- param = AgentActionRequest.from_json(json_object=request.json())
- return agent_service.checkin(param)
- return 'Hello World!'
- @app.route('/open/agent/idle', methods=['POST'])
- def idle():
- """坐席置闲"""
- param = AgentActionRequest.from_json(json_object=request.json())
- return agent_service.checkin(param)
- return 'Hello World!'
- @app.route('/open/agent/turn-on', methods=['POST'])
- def turn_on():
- """接通"""
- param = AgentActionRequest.from_json(json_object=request.json())
- return agent_service.checkin(param)
- return 'Hello World!'
- @app.route('/open/agent/hang-up', methods=['POST'])
- def hang_up():
- """挂断"""
- param = AgentActionRequest.from_json(json_object=request.json())
- return agent_service.checkin(param)
- return 'Hello World!'
- @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!'
|