|
@@ -1,17 +1,23 @@
|
|
|
#!/usr/bin/env python3
|
|
|
# encoding:utf-8
|
|
|
-import json
|
|
|
-from src.core.callcenter.enumeration import AgentScene, AgentServiceState, WorkStatus, DownEvent
|
|
|
-from src.core.callcenter.ws import common_down_data, common_down_cmd
|
|
|
|
|
|
+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_on_agent_report(self, saas_id, out_id, scene: AgentScene, service_state: AgentServiceState):
|
|
|
- # pass
|
|
|
-
|
|
|
+ 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=""):
|
|
|
data = {
|
|
|
'eventName': DownEvent.ON_AGENT_WORK_REPORT.code,
|
|
@@ -23,23 +29,24 @@ class PushHandler:
|
|
|
}
|
|
|
}
|
|
|
self.logger.info("flowId:[%s] OnAgentWorkReport push:[%s].", flow_id, json.dumps(data))
|
|
|
- new_data = {'data':json.dumps(data)}
|
|
|
- common_down_data(user_id, json.dumps(new_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, out_id, scene: AgentScene, service_state: AgentServiceState):
|
|
|
+ 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': out_id,
|
|
|
+ '_shortagentid': user_id,
|
|
|
'_astate': service_state.code,
|
|
|
'_atime': datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
}
|
|
|
}
|
|
|
self.logger.info("OnAgentReport event triger:", json.dumps(data))
|
|
|
- common_down_data(out_id, 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, call_id, file_name, calling_no, called_no, human_service_id):
|
|
|
data = {
|
|
@@ -57,7 +64,7 @@ class PushHandler:
|
|
|
}
|
|
|
self.logger.info("flowId:[%s] OnAgentWorkReport push:[%s].", flow_id, json.dumps(data))
|
|
|
new_data = {'data': json.dumps(data)}
|
|
|
- common_down_data(user_id, json.dumps(new_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, service_direct=None, disconnect_type=0):
|
|
|
data = {
|
|
@@ -71,7 +78,7 @@ class PushHandler:
|
|
|
}
|
|
|
self.logger.info("flowId:[%s] OnAgentWorkReport push:[%s].", flow_id, json.dumps(data))
|
|
|
new_data = {'data': json.dumps(data)}
|
|
|
- common_down_data(user_id, json.dumps(new_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, call_id=None):
|
|
|
data = {
|
|
@@ -84,7 +91,7 @@ class PushHandler:
|
|
|
}
|
|
|
self.logger.info("flowId:[%s] push_on_ring_start push:[%s].", flow_id, json.dumps(data))
|
|
|
new_data = {'data': json.dumps(data)}
|
|
|
- common_down_data(user_id, json.dumps(new_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, call_id):
|
|
|
data = {
|
|
@@ -97,7 +104,7 @@ class PushHandler:
|
|
|
}
|
|
|
self.logger.info("flowId:[%s] push_on_ring_end push:[%s].", flow_id, json.dumps(data))
|
|
|
new_data = {'data': json.dumps(data)}
|
|
|
- common_down_data(user_id, json.dumps(new_data))
|
|
|
+ self.push_to_socket_service(user_id, json.dumps(new_data))
|
|
|
|
|
|
def push_answer_call(self, saas_id,flow_id, out_id, call_id, scene, service_direct,work_status,user_id ):
|
|
|
data = {
|
|
@@ -112,4 +119,4 @@ class PushHandler:
|
|
|
}
|
|
|
self.logger.info("flowId:[%s] push_on_ring_end push:[%s].", flow_id, json.dumps(data))
|
|
|
new_data = {'data': json.dumps(data)}
|
|
|
- common_down_data(user_id, json.dumps(new_data))
|
|
|
+ self.push_to_socket_service(user_id, json.dumps(new_data))
|