NexmoWebHookController.php 1.49 KB
<?php

namespace NexmoBundle\Controller;

use AppBundle\Controller\SpokeControllerTrait;
use AppBundle\Entity\VoiceCall;
use CobrandBundle\CobrandInstance;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class NexmoWebHookController extends Controller
{
    use SpokeControllerTrait;

    /**
     * @param $s
     * @return string
     */
    protected function logString($s)
    {
        return "[nexmo_web_hook] => {$s}";
    }

    /**
     * @return string
     */
    protected function getCurrentAppName()
    {
        try {
            $appName = $this->getCurrentCobrand()->getApp()->getName();
        } catch (\Exception $exception) {
            $appName = "Spoke Health";
        }

        return $appName;
    }


    /**
     * @param $uuid
     * @return VoiceCall
     */
    protected function getVoiceCallByUUID($uuid)
    {

        return $this->getDoctrine()->getRepository("AppBundle:VoiceCall")->findOneBy(["uuid" => $uuid]);
    }

    /**
     * @param $uuid
     * @return VoiceCall
     * @throws \Exception
     */
    protected function findOrCreateVoiceCallByUuid($uuid)
    {
        $voiceCall = $this->getVoiceCallByUUID($uuid);
        if (!$voiceCall instanceof VoiceCall) {
            $this->get("logger")->info($this->logString("Creating new VoiceCall - UUID: {$uuid}"));
            // create voice call for this inbound call
            $voiceCall = new VoiceCall();
            $voiceCall->setCreatedAt(new \DateTime("now"));
        }

        return $voiceCall;
    }
}