NexmoWebHookController.php
1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?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;
}
}