push.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/usr/bin/env python3
  2. # encoding:utf-8
  3. from src.core.callcenter.enumeration import AgentScene, AgentServiceState, WorkStatus, DownEvent
  4. from src.core.callcenter.dao import *
  5. from src.core.datasource import RedisHandler
  6. class PushHandler:
  7. def __init__(self, logger):
  8. self.logger = logger
  9. def push_to_socket_service(self,user_id, data, event='common_down_data'):
  10. # 创建发布的消息
  11. message = json.dumps({
  12. 'event': event,
  13. 'user_id': user_id,
  14. 'data': data
  15. })
  16. # 获取 RedisHandler 实例并发布消息到 Redis 频道
  17. redis_handler = RedisHandler()
  18. redis_handler.publish('socket_channel', message)
  19. def push_on_agent_work_report(self, saas_id, flow_id, user_id, call_id, scene: AgentScene, work_status: WorkStatus, description=None, phone=None):
  20. data = {
  21. 'eventName': DownEvent.ON_AGENT_WORK_REPORT.code,
  22. 'ext': {'workStatus': work_status.code,
  23. 'description': description or work_status.description,
  24. 'callId': call_id,
  25. 'ctiFlowId': flow_id,
  26. 'scene': scene.code,
  27. 'phone':phone
  28. }
  29. }
  30. self.logger.info("flowId:[%s] push_on_agent_work_report push:[%s].", flow_id, json.dumps(data))
  31. new_data = {'data': json.dumps(data)}
  32. self.push_to_socket_service(user_id, json.dumps(new_data))
  33. def push_on_agent_report(self, saas_id, out_id, scene: AgentScene, service_state: AgentServiceState):
  34. pass
  35. def do_push_on_agent_report(self, saas_id, user_id, scene: AgentScene, service_state: AgentServiceState):
  36. data = {
  37. 'eventName': DownEvent.ON_AGENT_REPORT.code,
  38. 'ext': {
  39. 'scene': scene.code,
  40. '_shortagentid': user_id,
  41. '_astate': service_state.code,
  42. '_atime': datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  43. }
  44. }
  45. self.logger.info("OnAgentReport event triger:", json.dumps(data))
  46. new_data = {'data': json.dumps(data)}
  47. self.push_to_socket_service(user_id, json.dumps(new_data))
  48. 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):
  49. data = {
  50. 'eventName': DownEvent.ON_CALLRING.code,
  51. 'ext': {
  52. 'callId':call_id,
  53. 'ctiFlowId':flow_id,
  54. 'scene': scene.code,
  55. 'callingNo': calling_no,
  56. 'calledNo': called_no,
  57. 'serviceDirect': service_direct,
  58. 'serviceTaskId': human_service_id
  59. }
  60. }
  61. self.logger.info("flowId:[%s] push_on_call_ring push:[%s].", flow_id, json.dumps(data))
  62. new_data = {'data': json.dumps(data)}
  63. self.push_to_socket_service(user_id, json.dumps(new_data))
  64. def push_on_call_end(self, saas_id, flow_id, user_id, scene: AgentScene, service_direct=None, disconnect_type=0):
  65. data = {
  66. 'eventName': DownEvent.ON_CALL_END.code,
  67. 'ext': {
  68. 'ctiFlowId': flow_id,
  69. 'scene': scene.code,
  70. 'disconnectType': disconnect_type,
  71. 'serviceDirect': service_direct
  72. }
  73. }
  74. self.logger.info("flowId:[%s] push_on_call_end push:[%s].", flow_id, json.dumps(data))
  75. new_data = {'data': json.dumps(data)}
  76. self.push_to_socket_service(user_id, json.dumps(new_data))
  77. def push_on_ring_start(self, saas_id, flow_id, user_id, scene: AgentScene, call_id=None):
  78. data = {
  79. 'eventName': DownEvent.ON_RING_Start.code,
  80. 'ext': {
  81. 'ctiFlowId': flow_id,
  82. 'scene': scene.code,
  83. 'callId': call_id
  84. }
  85. }
  86. self.logger.info("flowId:[%s] push_on_ring_start push:[%s].", flow_id, json.dumps(data))
  87. new_data = {'data': json.dumps(data)}
  88. self.push_to_socket_service(user_id, json.dumps(new_data))
  89. def push_on_ring_end(self, saas_id, flow_id, user_id, scene: AgentScene, call_id):
  90. data = {
  91. 'eventName': DownEvent.ON_RING_END.code,
  92. 'ext': {
  93. 'ctiFlowId': flow_id,
  94. 'scene': scene.code,
  95. 'callId': call_id,
  96. }
  97. }
  98. self.logger.info("flowId:[%s] push_on_ring_end push:[%s].", flow_id, json.dumps(data))
  99. new_data = {'data': json.dumps(data)}
  100. self.push_to_socket_service(user_id, json.dumps(new_data))
  101. def push_answer_call(self, saas_id,flow_id, user_id, call_id, scene: AgentScene, service_direct,work_status):
  102. data = {
  103. 'eventName': DownEvent.ANSWER_CALL.code,
  104. 'ext': {
  105. 'ctiFlowId': flow_id,
  106. 'scene': scene.code,
  107. 'callId': call_id,
  108. 'serviceDirect':service_direct,
  109. 'workStatus':work_status.code
  110. }
  111. }
  112. self.logger.info("flowId:[%s] push_answer_call push:[%s].", flow_id, json.dumps(data))
  113. new_data = {'data': json.dumps(data)}
  114. self.push_to_socket_service(user_id, json.dumps(new_data))
  115. def push_on_detected_tone(self, saas_id, flow_id, user_id, scene: AgentScene, call_id):
  116. data = {
  117. 'eventName': DownEvent.ON_DETECTED_TONE.code,
  118. 'ext': {
  119. 'ctiFlowId': flow_id,
  120. 'scene': scene.code,
  121. 'callId': call_id,
  122. }
  123. }
  124. self.logger.info("flowId:[%s] push_on_detected_tone push:[%s].", flow_id, json.dumps(data))
  125. new_data = {'data': json.dumps(data)}
  126. self.push_to_socket_service(user_id, json.dumps(new_data))