Ejemplo n.º 1
0
 public function onCall(CallbackEvent $event)
 {
     $callEvent = $event->getCallEvent();
     /** @var Call $call */
     $call = $callEvent->getCall();
     $account = $call->getAccount();
     if ($call->getDirection() != CallInterface::DIRECTION_INCOMING) {
         return;
     }
     $converter = new ObjectScalarConverter();
     if ($callEvent instanceof CallEventInterface) {
         if (!$call->getClient() instanceof ClientInterface) {
             return;
         }
         $client = $call->getClient();
         $managerIds = [];
         if ($call->getCalledUsers()->count()) {
             $managerIds = $converter->reverseConvertCollection($call->getCalledUsers());
         }
         $company = null;
         if ($client->getCompany() instanceof CompanyInterface) {
             $company = $client->getCompany()->getName();
         }
         $message = ['managerIds' => $managerIds, 'event' => 'incoming-call', 'data' => ['clientId' => $client->getId(), 'name' => $client->getFirstName() . ' ' . $client->getLastName(), 'company' => $company, 'position' => $client->getPosition()]];
         $this->redis->publish('events.' . $account->getDomain(), json_encode($message));
     }
 }
Ejemplo n.º 2
0
 public function onNewCaller(CallbackEvent $event)
 {
     $callEvent = $event->getCallEvent();
     /** @var Call $call */
     $call = $callEvent->getCall();
     // Prepare new client information
     $client = $call->getClient();
     $client->setFirstName('from call center');
     if ($callEvent->getTreeName() || $callEvent->getTreeNumber()) {
         $condition = new ChannelCondition();
         $condition->setAccount($this->accountManager->getCurrentAccount());
         $condition->setTreeName($callEvent->getTreeName())->setTreeNumber($callEvent->getTreeNumber());
         $channel = $this->channelManager->searchOne($condition);
         if ($channel instanceof Channel) {
             $call->getClient()->setChannel($channel);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * @param CallEventInterface $callEvent
  * @return CallbackEvent
  */
 protected function createEvent(CallEventInterface $callEvent)
 {
     $event = new CallbackEvent();
     $event->setCallEvent($callEvent);
     return $event;
 }
Ejemplo n.º 4
0
 public function onHangup(CallbackEvent $event)
 {
     $callEvent = $event->getCallEvent();
     /** @var Call $call */
     $call = $callEvent->getCall();
     if ($call->getDirection() == CallInterface::DIRECTION_INCOMING) {
         if ($call->getUser() instanceof UserInterface && $call->getAnswerEvent() instanceof AnswerEvent) {
             $this->callManager->calcTalkDuration($call);
             $call->setNumber($call->getAnswerEvent()->getDstNumber());
             $this->activityManager->prepareIncomingCallNote($call);
         }
     } else {
         if ($call->getDirection() == CallInterface::DIRECTION_OUTBOUND) {
             if ($call->getAnswerEvent() instanceof AnswerEvent) {
                 $this->callManager->calcTalkDuration($call);
             }
         } else {
             throw new CallDirectionException($callEvent);
         }
     }
 }