123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #!/usr/bin/env python3
- # encoding:utf-8
- import threading
- import src.core.callcenter.esl.utils.esl_event_util as EslEventUtil
- from src.core.callcenter.agent import AgentEventService
- from src.core.callcenter.cache import Cache
- from src.core.callcenter.enumeration import CallType
- from src.core.callcenter.esl.constant.event_names import CUSTOM, DETECTED_TONE
- class Callback(object):
- def __init__(self, app):
- self.app = app
- self.logger = app.logger
- self.cache = Cache(app)
- self.agent_event_service = AgentEventService(app)
- def callback_event(self, event):
- event_name = EslEventUtil.getEventName(event)
- # CUSTOM == event_name or
- if not (event_name.startswith('CHANNEL_') or event_name.startswith('PLAYBACK_') or event_name == DETECTED_TONE):
- return
- call_id = EslEventUtil.getCallId(event)
- device_id = EslEventUtil.getDeviceId(event)
- if not call_id and device_id:
- call_id = self.cache.get_call_id_by_device_id(device_id)
- call_info = self.cache.get_call_info(call_id)
- if not call_info:
- # self.logger.info("liuwei::debugger::callback:return::event_name=%s, call_id=%s, device_id=%s", event_name, call_id, device_id)
- return
- call_type = CallType.get_by_code(call_info.call_type) if call_info else None
- device_info = call_info.device_info_map.get(device_id) if call_info and call_info.device_info_map else None
- # 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)
- if CallType.BOT_CALL == call_type:
- threading.Thread(target=self.agent_event_service.bot_event_channel, args=(event, call_info, device_info)).start()
- # self.agent_event_service.bot_event_channel(event, call_info, device_info)
- else:
- threading.Thread(target=self.agent_event_service.agent_event_channel, args=(event, call_info, device_info)).start()
- # self.agent_event_service.agent_event_channel(event, call_info, device_info)
|