#!/usr/bin/env python3 # encoding:utf-8 from src.core.callcenter.enumeration import AgentScene, AgentServiceState, WorkStatus, DownEvent from src.core.callcenter.dao import * from src.core.datasource import RedisHandler class PushHandler: def __init__(self, logger): self.logger = logger def push_to_socket_service(self,user_id, data, event='common_down_data'): # 创建发布的消息 message = json.dumps({ 'event': event, 'user_id': user_id, 'data': data }) # 获取 RedisHandler 实例并发布消息到 Redis 频道 redis_handler = RedisHandler() redis_handler.publish('socket_channel', message) def push_on_agent_work_report(self, saas_id, flow_id, user_id, call_id, scene: AgentScene, work_status: WorkStatus, description=None, phone=None): data = { 'eventName': DownEvent.ON_AGENT_WORK_REPORT.code, 'ext': {'workStatus': work_status.code, 'description': description or work_status.description, 'callId': call_id, 'ctiFlowId': flow_id, 'scene': scene.code, 'phone':phone } } self.logger.info("flowId:[%s] push_on_agent_work_report push:[%s].", flow_id, json.dumps(data)) new_data = {'data': json.dumps(data)} self.push_to_socket_service(user_id, json.dumps(new_data)) def push_on_agent_report(self, saas_id, out_id, scene: AgentScene, service_state: AgentServiceState): pass def do_push_on_agent_report(self, saas_id, user_id, scene: AgentScene, service_state: AgentServiceState): data = { 'eventName': DownEvent.ON_AGENT_REPORT.code, 'ext': { 'scene': scene.code, '_shortagentid': user_id, '_astate': service_state.code, '_atime': datetime.now().strftime("%Y-%m-%d %H:%M:%S") } } self.logger.info("OnAgentReport event triger:", json.dumps(data)) new_data = {'data': json.dumps(data)} self.push_to_socket_service(user_id, json.dumps(new_data)) def push_on_call_ring(self, saas_id, flow_id, user_id,scene:AgentScene, call_id, service_direct, calling_no=None, called_no=None, human_service_id=None): data = { 'eventName': DownEvent.ON_CALLRING.code, 'ext': { 'callId':call_id, 'ctiFlowId':flow_id, 'scene': scene.code, 'callingNo': calling_no, 'calledNo': called_no, 'serviceDirect': service_direct, 'serviceTaskId': human_service_id } } self.logger.info("flowId:[%s] push_on_call_ring push:[%s].", flow_id, json.dumps(data)) new_data = {'data': json.dumps(data)} self.push_to_socket_service(user_id, json.dumps(new_data)) def push_on_call_end(self, saas_id, flow_id, user_id, scene: AgentScene, service_direct=None, disconnect_type=0): data = { 'eventName': DownEvent.ON_CALL_END.code, 'ext': { 'ctiFlowId': flow_id, 'scene': scene.code, 'disconnectType': disconnect_type, 'serviceDirect': service_direct } } self.logger.info("flowId:[%s] push_on_call_end push:[%s].", flow_id, json.dumps(data)) new_data = {'data': json.dumps(data)} self.push_to_socket_service(user_id, json.dumps(new_data)) def push_on_ring_start(self, saas_id, flow_id, user_id, scene: AgentScene, call_id=None): data = { 'eventName': DownEvent.ON_RING_Start.code, 'ext': { 'ctiFlowId': flow_id, 'scene': scene.code, 'callId': call_id } } self.logger.info("flowId:[%s] push_on_ring_start push:[%s].", flow_id, json.dumps(data)) new_data = {'data': json.dumps(data)} self.push_to_socket_service(user_id, json.dumps(new_data)) def push_on_ring_end(self, saas_id, flow_id, user_id, scene: AgentScene, call_id): data = { 'eventName': DownEvent.ON_RING_END.code, 'ext': { 'ctiFlowId': flow_id, 'scene': scene.code, 'callId': call_id, } } self.logger.info("flowId:[%s] push_on_ring_end push:[%s].", flow_id, json.dumps(data)) new_data = {'data': json.dumps(data)} self.push_to_socket_service(user_id, json.dumps(new_data)) def push_answer_call(self, saas_id,flow_id, user_id, call_id, scene: AgentScene, service_direct,work_status): data = { 'eventName': DownEvent.ANSWER_CALL.code, 'ext': { 'ctiFlowId': flow_id, 'scene': scene.code, 'callId': call_id, 'serviceDirect':service_direct, 'workStatus':work_status.code } } self.logger.info("flowId:[%s] push_answer_call push:[%s].", flow_id, json.dumps(data)) new_data = {'data': json.dumps(data)} self.push_to_socket_service(user_id, json.dumps(new_data)) def push_on_detected_tone(self, saas_id, flow_id, user_id, scene: AgentScene, call_id): data = { 'eventName': DownEvent.ON_DETECTED_TONE.code, 'ext': { 'ctiFlowId': flow_id, 'scene': scene.code, 'callId': call_id, } } self.logger.info("flowId:[%s] push_on_detected_tone push:[%s].", flow_id, json.dumps(data)) new_data = {'data': json.dumps(data)} self.push_to_socket_service(user_id, json.dumps(new_data))