public function onFirstCall(CallbackEvent $event) { $callEvent = $event->getCallEvent(); /** @var Call $call */ $call = $callEvent->getCall(); $callerSystem = $this->callManager->getCallerSystem($callEvent); $activity = $this->activityManager->create(); $activity->setType('call'); $this->activityManager->update($activity, false); $call->setActivity($activity); unset($activity); $call->setAccount($this->accountManager->getCurrentAccount()); $user = $callerSystem->searchSourceUser($callEvent); if ($user instanceof UserInterface) { $call->setDirection(CallInterface::DIRECTION_OUTBOUND); $call->setUser($user); // Dispatch PerficoSipuniEvents::CALL when using SIP system for outbound call if ($callerSystem instanceof SipManager) { $e = new CallbackEvent(); $e->setCallEvent($callEvent); $this->dispatcher->dispatch(PerficoSipuniEvents::CALL, $e); } } else { $call->setDirection(CallInterface::DIRECTION_INCOMING); $client = $callerSystem->searchSourceClient($callEvent); if ($client instanceof ClientInterface) { $call->setClient($client); } else { if ($callerSystem instanceof PhoneManager) { // TODO need remove this condition since clients can call from Skype or Sip $client = $this->clientManager->create(); $this->clientManager->update($client, false); $callerSystem->prepareNewClient($client, $callEvent->getSrcNumber()); $call->setClient($client); $e = new CallbackEvent(); $e->setCallEvent($callEvent); $this->dispatcher->dispatch(PerficoCRMEvents::NEW_THE_CALLER, $e); } } } }
/** * @param CallEventInterface $callEvent * @return CallbackEvent */ protected function createEvent(CallEventInterface $callEvent) { $event = new CallbackEvent(); $event->setCallEvent($callEvent); return $event; }