callback.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python3
  2. # encoding:utf-8
  3. import threading
  4. import src.core.callcenter.esl.utils.esl_event_util as EslEventUtil
  5. from src.core.callcenter.agent import AgentEventService
  6. from src.core.callcenter.cache import Cache
  7. from src.core.callcenter.enumeration import CallType
  8. from src.core.callcenter.esl.constant.event_names import CUSTOM, DETECTED_TONE
  9. class Callback(object):
  10. def __init__(self, app):
  11. self.app = app
  12. self.logger = app.logger
  13. self.cache = Cache(app)
  14. self.agent_event_service = AgentEventService(app)
  15. def callback_event(self, event):
  16. event_name = EslEventUtil.getEventName(event)
  17. # CUSTOM == event_name or
  18. if not (event_name.startswith('CHANNEL_') or event_name.startswith('PLAYBACK_') or event_name == DETECTED_TONE):
  19. return
  20. call_id = EslEventUtil.getCallId(event)
  21. device_id = EslEventUtil.getDeviceId(event)
  22. if not call_id and device_id:
  23. call_id = self.cache.get_call_id_by_device_id(device_id)
  24. call_info = self.cache.get_call_info(call_id)
  25. if not call_info:
  26. # self.logger.info("liuwei::debugger::callback:return::event_name=%s, call_id=%s, device_id=%s", event_name, call_id, device_id)
  27. return
  28. call_type = CallType.get_by_code(call_info.call_type) if call_info else None
  29. device_info = call_info.device_info_map.get(device_id) if call_info and call_info.device_info_map else None
  30. # self.logger.info("liuwei::debugger::callback::event_name=%s, call_type=%s, call_id=%s, device_id=%s, call_info=%s", event_name, call_type, call_id, device_id, call_info)
  31. if CallType.BOT_CALL == call_type:
  32. threading.Thread(target=self.agent_event_service.bot_event_channel, args=(event, call_info, device_info)).start()
  33. # self.agent_event_service.bot_event_channel(event, call_info, device_info)
  34. else:
  35. threading.Thread(target=self.agent_event_service.agent_event_channel, args=(event, call_info, device_info)).start()
  36. # self.agent_event_service.agent_event_channel(event, call_info, device_info)