One Hat Cyber Team
Your IP:
216.73.216.102
Server IP:
198.54.114.155
Server:
Linux server71.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64
Server Software:
LiteSpeed
PHP Version:
5.6.40
Create File
|
Create Folder
Execute
Dir :
~
/
home
/
fluxyjvi
/
public_html
/
assets
/
images
/
Edit File:
Voice.tar
CallAction.php 0000644 00000001043 15107326345 0007272 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice; /** * Collection of actions that can be used to modify a call */ class CallAction { public const EARMUFF = 'earmuff'; public const HANGUP = 'hangup'; public const MUTE = 'mute'; public const UNEARMUFF = 'unearmuff'; public const UNMUTE = 'unmute'; } NCCO/NCCOFactory.php 0000644 00000003442 15107326345 0010062 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\NCCO; use InvalidArgumentException; use Vonage\Voice\Endpoint\EndpointFactory; use Vonage\Voice\NCCO\Action\ActionInterface; use Vonage\Voice\NCCO\Action\Connect; use Vonage\Voice\NCCO\Action\Conversation; use Vonage\Voice\NCCO\Action\Input; use Vonage\Voice\NCCO\Action\Notify; use Vonage\Voice\NCCO\Action\Record; use Vonage\Voice\NCCO\Action\Stream; use Vonage\Voice\NCCO\Action\Talk; class NCCOFactory { /** * @param $data */ public function build($data): ActionInterface { switch ($data['action']) { case 'connect': $factory = new EndpointFactory(); $endpoint = $factory->create($data['endpoint'][0]); if (null !== $endpoint) { return Connect::factory($endpoint); } throw new InvalidArgumentException("Malformed NCCO Action " . $data['endpoint'][0]); case 'conversation': return Conversation::factory($data['name'], $data); case 'input': return Input::factory($data); case 'notify': return Notify::factory($data['payload'], $data); case 'record': return Record::factory($data); case 'stream': return Stream::factory($data['streamUrl'], $data); case 'talk': return Talk::factory($data['text'], $data); default: throw new InvalidArgumentException("Unknown NCCO Action " . $data['action']); } } } NCCO/NCCO.php 0000644 00000002514 15107326345 0006531 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\NCCO; use JsonSerializable; use Vonage\Entity\Hydrator\ArrayHydrateInterface; use Vonage\Voice\NCCO\Action\ActionInterface; class NCCO implements ArrayHydrateInterface, JsonSerializable { /** * @var array<ActionInterface> */ protected $actions = []; /** * @return $this */ public function addAction(ActionInterface $action): self { $this->actions[] = $action; return $this; } public function fromArray(array $data): void { $factory = new NCCOFactory(); foreach ($data as $rawNCCO) { $action = $factory->build($rawNCCO); $this->addAction($action); } } /** * @return array<array<string, string>> */ public function jsonSerialize(): array { return $this->toArray(); } /** * @return array<array<string, string>> */ public function toArray(): array { $data = []; foreach ($this->actions as $action) { $data[] = $action->toNCCOArray(); } return $data; } } NCCO/Action/Conversation.php 0000644 00000014747 15107326345 0011711 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\NCCO\Action; use Vonage\Voice\Webhook; use function array_key_exists; use function filter_var; use function is_array; use function is_null; class Conversation implements ActionInterface { /** * @var ?string */ protected $musicOnHoldUrl; /** * @var bool */ protected $startOnEnter; /** * @var bool */ protected $endOnExit; /** * @var bool */ protected $record; /** * @var ?array<string> */ protected $canSpeak; /** * @var ?array<string> */ protected $canHear; /** * @var Webhook */ protected $eventWebhook; public function __construct(protected string $name) { } public function getName(): string { return $this->name; } public function getMusicOnHoldUrl(): ?string { return $this->musicOnHoldUrl; } /** * @return $this */ public function setMusicOnHoldUrl(string $musicOnHoldUrl): self { $this->musicOnHoldUrl = $musicOnHoldUrl; return $this; } public function getStartOnEnter(): ?bool { return $this->startOnEnter; } /** * @return $this */ public function setStartOnEnter(bool $startOnEnter): self { $this->startOnEnter = $startOnEnter; return $this; } public function getEndOnExit(): ?bool { return $this->endOnExit; } /** * @return $this */ public function setEndOnExit(bool $endOnExit): self { $this->endOnExit = $endOnExit; return $this; } public function getRecord(): ?bool { return $this->record; } /** * @return $this */ public function setRecord(bool $record): self { $this->record = $record; return $this; } /** * @return ?array<string> */ public function getCanSpeak(): ?array { return $this->canSpeak; } /** * @param array<string> $canSpeak * * @return Conversation */ public function setCanSpeak(array $canSpeak): self { $this->canSpeak = $canSpeak; return $this; } /** * @return $this */ public function addCanSpeak(string $uuid): self { $this->canSpeak[] = $uuid; return $this; } /** * @return ?array<string> */ public function getCanHear(): ?array { return $this->canHear; } /** * @param array<string> $canHear * * @return Conversation */ public function setCanHear(array $canHear): self { $this->canHear = $canHear; return $this; } /** * @return $this */ public function addCanHear(string $uuid): self { $this->canHear[] = $uuid; return $this; } /** * @param array{ * musicOnHoldUrl?: string, * startOnEnter?: bool, * endOnExit?: bool, * record?: bool, * canSpeak?: array, * canHear?: array * } $data */ public static function factory(string $name, array $data): Conversation { $talk = new Conversation($name); if (array_key_exists('musicOnHoldUrl', $data)) { $talk->setMusicOnHoldUrl($data['musicOnHoldUrl']); } if (array_key_exists('startOnEnter', $data)) { $talk->setStartOnEnter( filter_var($data['startOnEnter'], FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE]) ); } if (array_key_exists('endOnExit', $data)) { $talk->setEndOnExit( filter_var($data['endOnExit'], FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE]) ); } if (array_key_exists('record', $data)) { $talk->setRecord( filter_var($data['record'], FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE]) ); } if (array_key_exists('canSpeak', $data)) { $talk->setCanSpeak($data['canSpeak']); } if (array_key_exists('canHear', $data)) { $talk->setCanHear($data['canHear']); } if (array_key_exists('eventUrl', $data)) { if (is_array($data['eventUrl'])) { $data['eventUrl'] = $data['eventUrl'][0]; } if (array_key_exists('eventMethod', $data)) { $webhook = new Webhook($data['eventUrl'], $data['eventMethod']); } else { $webhook = new Webhook($data['eventUrl']); } $talk->setEventWebhook($webhook); } return $talk; } /** * @return array<string, mixed> */ public function jsonSerialize(): array { return $this->toNCCOArray(); } /** * @return array<string, mixed> */ public function toNCCOArray(): array { $data = [ 'action' => 'conversation', 'name' => $this->getName(), ]; if (!is_null($this->getStartOnEnter())) { $data['startOnEnter'] = $this->getStartOnEnter() ? 'true' : 'false'; } if (!is_null($this->getEndOnExit())) { $data['endOnExit'] = $this->getEndOnExit() ? 'true' : 'false'; } if (!is_null($this->getRecord())) { $data['record'] = $this->getRecord() ? 'true' : 'false'; } $music = $this->getMusicOnHoldUrl(); if ($music) { $data['musicOnHoldUrl'] = [$music]; } $canSpeak = $this->getCanSpeak(); if ($canSpeak) { $data['canSpeak'] = $canSpeak; } $canHear = $this->getCanHear(); if ($canHear) { $data['canHear'] = $canHear; } if ($this->getEventWebhook()) { $data['eventUrl'] = [$this->getEventWebhook()->getUrl()]; $data['eventMethod'] = $this->getEventWebhook()->getMethod(); } return $data; } public function getEventWebhook(): ?Webhook { return $this->eventWebhook; } /** * @return $this */ public function setEventWebhook(Webhook $eventWebhook): Conversation { $this->eventWebhook = $eventWebhook; return $this; } } NCCO/Action/Talk.php 0000644 00000011312 15107326345 0010113 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\NCCO\Action; use function array_key_exists; use function filter_var; use function is_null; class Talk implements ActionInterface { protected bool $bargeIn = false; protected string $language = ''; protected int $languageStyle = 0; protected ?float $level = 0; protected int $loop = 1; protected bool $premium = false; public function __construct(protected ?string $text = null) { } /** * @param array{text: string, bargeIn?: bool, level?: float, style? : string, language?: string, premium?: bool, loop?: int} $data */ public static function factory(string $text, array $data): Talk { $talk = new Talk($text); if (array_key_exists('voiceName', $data)) { trigger_error( 'voiceName is deprecated and will not be added to the NCCO', E_USER_DEPRECATED ); } if (array_key_exists('bargeIn', $data)) { $talk->setBargeIn( filter_var($data['bargeIn'], FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE]) ); } if (array_key_exists('premium', $data)) { $talk->setPremium( filter_var($data['premium'], FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE]) ); } if (array_key_exists('level', $data)) { $talk->setLevel( filter_var($data['level'], FILTER_VALIDATE_FLOAT, ['flags' => FILTER_NULL_ON_FAILURE]) ); } if (array_key_exists('loop', $data)) { $talk->setLoop( filter_var($data['loop'], FILTER_VALIDATE_INT, ['flags' => FILTER_NULL_ON_FAILURE]) ); } if (array_key_exists('language', $data)) { if (array_key_exists('style', $data)) { $talk->setLanguage($data['language'], (int) $data['style']); } else { $talk->setLanguage($data['language']); } } return $talk; } public function getBargeIn(): ?bool { return $this->bargeIn; } public function getLevel(): ?float { return $this->level; } public function getLoop(): ?int { return $this->loop; } public function getText(): string { return $this->text; } /** * @return array{action: string, bargeIn: bool, level: float, loop: int, text: string} */ public function jsonSerialize(): array { return $this->toNCCOArray(); } public function setBargeIn(bool $value): self { $this->bargeIn = $value; return $this; } /** * @return $this */ public function setLevel(float $level): self { $this->level = $level; return $this; } public function setLoop(int $times): self { $this->loop = $times; return $this; } /** * @return $this */ public function setPremium(bool $premium): self { $this->premium = $premium; return $this; } public function getPremium(): bool { return $this->premium; } /** * @return array{action: string, bargeIn: bool, level: string, loop: string, text: string, premium: string, language: string, style: string} */ public function toNCCOArray(): array { $data = [ 'action' => 'talk', 'text' => $this->getText(), ]; if (!is_null($this->getBargeIn())) { $data['bargeIn'] = $this->getBargeIn() ? 'true' : 'false'; } if (!is_null($this->getLevel())) { $data['level'] = (string)$this->getLevel(); } if (!is_null($this->getLoop())) { $data['loop'] = (string)$this->getLoop(); } if ($this->getLanguage()) { $data['language'] = $this->getLanguage(); $data['style'] = (string) $this->getLanguageStyle(); } if (!is_null($this->getPremium())) { $data['premium'] = $this->getPremium() ? 'true' : 'false'; } return $data; } public function setLanguage(string $language, int $style = 0): self { $this->language = $language; $this->languageStyle = $style; return $this; } public function getLanguage(): ?string { return $this->language; } public function getLanguageStyle(): int { return $this->languageStyle; } } NCCO/Action/Record.php 0000644 00000015354 15107326345 0010450 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\NCCO\Action; use InvalidArgumentException; use Vonage\Voice\Webhook; use function array_key_exists; use function filter_var; use function preg_match; class Record implements ActionInterface { public const FORMAT_MP3 = "mp3"; public const FORMAT_WAV = "wav"; public const FORMAT_OGG = "ogg"; public const SPLIT = 'conversation'; /** * @var string Record::FORMAT_* */ protected $format = 'mp3'; /** * @var string Record::SPLIT */ protected $split; /** * @var int */ protected $channels; /** * @var int */ protected $endOnSilence; /** * @var string '*'|'#'|1'|2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'|'0' */ protected $endOnKey; /** * @var int */ protected $timeOut = 7200; /** * @var bool */ protected $beepStart = false; /** * @var Webhook */ protected $eventWebhook; /** * @return static */ public static function factory(array $data): self { $action = new self(); if (array_key_exists('format', $data)) { $action->setFormat($data['format']); } if (array_key_exists('split', $data)) { $action->setSplit($data['split']); } if (array_key_exists('channels', $data)) { $action->setChannels($data['channels']); } if (array_key_exists('endOnSilence', $data)) { $action->setEndOnSilence( filter_var($data['endOnSilence'], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE) ); } if (array_key_exists('endOnKey', $data)) { $action->setEndOnKey($data['endOnKey']); } if (array_key_exists('timeOut', $data)) { $action->setTimeout($data['timeOut']); } if (array_key_exists('beepStart', $data)) { $action->setBeepStart( filter_var($data['beepStart'], FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE]) ); } if (array_key_exists('eventUrl', $data)) { if (array_key_exists('eventMethod', $data)) { $webhook = new Webhook($data['eventUrl'], $data['eventMethod']); } else { $webhook = new Webhook($data['eventUrl']); } $action->setEventWebhook($webhook); } return $action; } /** * @return array<string, mixed> */ public function jsonSerialize(): array { return $this->toNCCOArray(); } /** * @return array<string, mixed> */ public function toNCCOArray(): array { $data = [ 'action' => 'record', 'format' => $this->getFormat(), 'timeOut' => (string)$this->getTimeout(), 'beepStart' => $this->getBeepStart() ? 'true' : 'false', ]; if ($this->getEndOnSilence()) { $data['endOnSilence'] = (string)$this->getEndOnSilence(); } if ($this->getEndOnKey()) { $data['endOnKey'] = $this->getEndOnKey(); } if ($this->getChannels()) { $data['channels'] = (string)$this->getChannels(); } if ($this->getSplit()) { $data['split'] = $this->getSplit(); } if ($this->getEventWebhook()) { $data['eventUrl'] = [$this->getEventWebhook()->getUrl()]; $data['eventMethod'] = $this->getEventWebhook()->getMethod(); } return $data; } public function getFormat(): string { return $this->format; } /** * @return $this */ public function setFormat(string $format): self { $this->format = $format; return $this; } public function getSplit(): ?string { return $this->split; } /** * @return $this */ public function setSplit(string $split): self { if ($split !== 'conversation') { throw new InvalidArgumentException('Split value must be "conversation" if enabling'); } $this->split = $split; return $this; } public function getEndOnKey(): ?string { return $this->endOnKey; } /** * @return $this */ public function setEndOnKey(string $endOnKey): self { $match = preg_match('/^[*#0-9]$/', $endOnKey); if ($match === 0 || $match === false) { throw new InvalidArgumentException('Invalid End on Key character'); } $this->endOnKey = $endOnKey; return $this; } public function getEventWebhook(): ?Webhook { return $this->eventWebhook; } /** * @return $this */ public function setEventWebhook(Webhook $eventWebhook): self { $this->eventWebhook = $eventWebhook; return $this; } public function getEndOnSilence(): ?int { return $this->endOnSilence; } /** * @return $this */ public function setEndOnSilence(int $endOnSilence): self { if ($endOnSilence > 10 || $endOnSilence < 3) { throw new InvalidArgumentException('End On Silence value must be between 3 and 10 seconds, inclusive'); } $this->endOnSilence = $endOnSilence; return $this; } public function getTimeout(): int { return $this->timeOut; } /** * @return $this */ public function setTimeout(int $timeOut): self { if ($timeOut > 7200 || $timeOut < 3) { throw new InvalidArgumentException('TimeOut value must be between 3 and 7200 seconds, inclusive'); } $this->timeOut = $timeOut; return $this; } public function getBeepStart(): bool { return $this->beepStart; } /** * @return $this */ public function setBeepStart(bool $beepStart): self { $this->beepStart = $beepStart; return $this; } public function getChannels(): ?int { return $this->channels; } /** * @return $this */ public function setChannels(int $channels): self { if ($channels > 32) { throw new InvalidArgumentException('Number of channels must be 32 or less'); } if ($channels > 1) { $this->channels = $channels; $this->setSplit(self::SPLIT); $this->format = self::FORMAT_WAV; } else { $this->channels = null; $this->split = null; } return $this; } } NCCO/Action/Stream.php 0000644 00000006200 15107326345 0010453 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\NCCO\Action; use function array_key_exists; use function filter_var; use function is_null; class Stream implements ActionInterface { /** * @var bool */ protected $bargeIn; /** * @var float */ protected $level; /** * @var int */ protected $loop; public function __construct(protected string $streamUrl) { } /** * @param array{streamUrl: string, bargeIn?: bool, level?: float, loop?: int, voiceName?: string} $data */ public static function factory(string $streamUrl, array $data): Stream { $stream = new Stream($streamUrl); if (array_key_exists('bargeIn', $data)) { $stream->setBargeIn( filter_var($data['bargeIn'], FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE]) ); } if (array_key_exists('level', $data)) { $stream->setLevel( filter_var($data['level'], FILTER_VALIDATE_FLOAT, ['flags' => FILTER_NULL_ON_FAILURE]) ); } if (array_key_exists('loop', $data)) { $stream->setLoop( filter_var($data['loop'], FILTER_VALIDATE_INT, ['flags' => FILTER_NULL_ON_FAILURE]) ); } return $stream; } public function getBargeIn(): ?bool { return $this->bargeIn; } public function getLevel(): ?float { return $this->level; } public function getLoop(): ?int { return $this->loop; } public function getStreamUrl(): string { return $this->streamUrl; } /** * @return array{action: string, bargeIn: bool, level: float, loop: int, streamUrl: string} */ public function jsonSerialize(): array { return $this->toNCCOArray(); } /** * @return $this */ public function setBargeIn(bool $value): self { $this->bargeIn = $value; return $this; } /** * @return $this */ public function setLevel(float $level): self { $this->level = $level; return $this; } /** * @return $this */ public function setLoop(int $times): self { $this->loop = $times; return $this; } /** * @return array{action: string, bargeIn: bool, level: float, loop: int, streamUrl: string} */ public function toNCCOArray(): array { $data = [ 'action' => 'stream', 'streamUrl' => [$this->getStreamUrl()], ]; if (!is_null($this->getBargeIn())) { $data['bargeIn'] = $this->getBargeIn() ? 'true' : 'false'; } if (!is_null($this->getLevel())) { $data['level'] = (string)$this->getLevel(); } if (!is_null($this->getLoop())) { $data['loop'] = (string)$this->getLoop(); } return $data; } } NCCO/Action/Input.php 0000644 00000022711 15107326345 0010324 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\NCCO\Action; use RuntimeException; use Vonage\Voice\Webhook; use function array_key_exists; use function filter_var; use function is_array; use function is_null; class Input implements ActionInterface { /** * @var int */ protected $dtmfTimeout; /** * @var int */ protected $dtmfMaxDigits; /** * @var bool */ protected $dtmfSubmitOnHash; /** * @var ?string */ protected $speechUUID; /** * @var int */ protected $speechEndOnSilence; /** * @var string */ protected $speechLanguage; /** * @var array<string> */ protected $speechContext; /** * @var ?int */ protected $speechStartTimeout; /** * @var int */ protected $speechMaxDuration; /** * @var ?Webhook */ protected $eventWebhook; /** * @var bool */ protected $enableSpeech = false; /** * @var bool */ protected $enableDtmf = false; /** * @param array<array, mixed> $data */ public static function factory(array $data): Input { $action = new self(); if (array_key_exists('dtmf', $data)) { $dtmf = $data['dtmf']; $action->setEnableDtmf(true); if (array_key_exists('timeOut', $dtmf)) { $action->setDtmfTimeout((int)$dtmf['timeOut']); } if (array_key_exists('maxDigits', $dtmf)) { $action->setDtmfMaxDigits((int)$dtmf['maxDigits']); } if (array_key_exists('submitOnHash', $dtmf)) { $action->setDtmfSubmitOnHash( filter_var($dtmf['submitOnHash'], FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE]) ); } } if (array_key_exists('speech', $data)) { $speech = $data['speech']; $action->setEnableSpeech(true); if (array_key_exists('uuid', $speech)) { $action->setSpeechUUID($speech['uuid'][0]); } if (array_key_exists('endOnSilence', $speech)) { $action->setSpeechEndOnSilence((int)$speech['endOnSilence']); } if (array_key_exists('language', $speech)) { $action->setSpeechLanguage($speech['language']); } if (array_key_exists('context', $speech)) { $action->setSpeechContext($speech['context']); } if (array_key_exists('startTimeout', $speech)) { $action->setSpeechStartTimeout((int)$speech['startTimeout']); } if (array_key_exists('maxDuration', $speech)) { $action->setSpeechMaxDuration((int)$speech['maxDuration']); } } if (array_key_exists('eventUrl', $data)) { if (is_array($data['eventUrl'])) { $data['eventUrl'] = $data['eventUrl'][0]; } if (array_key_exists('eventMethod', $data)) { $webhook = new Webhook($data['eventUrl'], $data['eventMethod']); } else { $webhook = new Webhook($data['eventUrl']); } $action->setEventWebhook($webhook); } return $action; } /** * @return array<string, mixed> */ public function jsonSerialize(): array { return $this->toNCCOArray(); } /** * @return array<string, mixed> */ public function toNCCOArray(): array { $data = [ 'action' => 'input', ]; if ($this->getEnableDtmf() === false && $this->getEnableSpeech() === false) { throw new RuntimeException('Input NCCO action must have either speech or DTMF enabled'); } if ($this->getEnableDtmf()) { $dtmf = []; if ($this->getDtmfTimeout()) { $dtmf['timeOut'] = $this->getDtmfTimeout(); } if ($this->getDtmfMaxDigits()) { $dtmf['maxDigits'] = $this->getDtmfMaxDigits(); } if (!is_null($this->getDtmfSubmitOnHash())) { $dtmf['submitOnHash'] = $this->getDtmfSubmitOnHash() ? 'true' : 'false'; } $data['dtmf'] = (object)$dtmf; } if ($this->getEnableSpeech()) { $speech = []; if ($this->getSpeechUUID()) { $speech['uuid'] = [$this->getSpeechUUID()]; } if ($this->getSpeechEndOnSilence()) { $speech['endOnSilence'] = $this->getSpeechEndOnSilence(); } if ($this->getSpeechLanguage()) { $speech['language'] = $this->getSpeechLanguage(); } if ($this->getSpeechMaxDuration()) { $speech['maxDuration'] = $this->getSpeechMaxDuration(); } $context = $this->getSpeechContext(); if (!empty($context)) { $speech['context'] = $context; } $startTimeout = $this->getSpeechStartTimeout(); if ($startTimeout) { $speech['startTimeout'] = $startTimeout; } $data['speech'] = (object)$speech; } $eventWebhook = $this->getEventWebhook(); if ($eventWebhook) { $data['eventUrl'] = [$eventWebhook->getUrl()]; $data['eventMethod'] = $eventWebhook->getMethod(); } return $data; } public function getDtmfTimeout(): ?int { return $this->dtmfTimeout; } /** * @return $this */ public function setDtmfTimeout(int $dtmfTimeout): self { $this->setEnableDtmf(true); $this->dtmfTimeout = $dtmfTimeout; return $this; } public function getDtmfMaxDigits(): ?int { return $this->dtmfMaxDigits; } /** * @return $this */ public function setDtmfMaxDigits(int $dtmfMaxDigits): self { $this->setEnableDtmf(true); $this->dtmfMaxDigits = $dtmfMaxDigits; return $this; } public function getDtmfSubmitOnHash(): ?bool { return $this->dtmfSubmitOnHash; } /** * @return $this */ public function setDtmfSubmitOnHash(bool $dtmfSubmitOnHash): self { $this->setEnableDtmf(true); $this->dtmfSubmitOnHash = $dtmfSubmitOnHash; return $this; } public function getSpeechUUID(): ?string { return $this->speechUUID; } /** * @return $this */ public function setSpeechUUID(string $speechUUID): self { $this->setEnableSpeech(true); $this->speechUUID = $speechUUID; return $this; } public function getSpeechEndOnSilence(): ?int { return $this->speechEndOnSilence; } /** * @return $this */ public function setSpeechEndOnSilence(int $speechEndOnSilence): self { $this->setEnableSpeech(true); $this->speechEndOnSilence = $speechEndOnSilence; return $this; } public function getSpeechLanguage(): ?string { return $this->speechLanguage; } /** * @return $this */ public function setSpeechLanguage(string $speechLanguage): self { $this->setEnableSpeech(true); $this->speechLanguage = $speechLanguage; return $this; } /** * @return array<string> */ public function getSpeechContext(): ?array { return $this->speechContext; } /** * @param array<string> $speechContext Array of words to help with speech recognition * * @return Input */ public function setSpeechContext(array $speechContext): self { $this->setEnableSpeech(true); $this->speechContext = $speechContext; return $this; } public function getSpeechStartTimeout(): ?int { return $this->speechStartTimeout; } /** * @return $this */ public function setSpeechStartTimeout(int $speechStartTimeout): self { $this->setEnableSpeech(true); $this->speechStartTimeout = $speechStartTimeout; return $this; } public function getSpeechMaxDuration(): ?int { return $this->speechMaxDuration; } public function setSpeechMaxDuration(int $speechMaxDuration): self { $this->setEnableSpeech(true); $this->speechMaxDuration = $speechMaxDuration; return $this; } public function getEventWebhook(): ?Webhook { return $this->eventWebhook; } /** * @return $this */ public function setEventWebhook(Webhook $eventWebhook): self { $this->eventWebhook = $eventWebhook; return $this; } public function getEnableSpeech(): bool { return $this->enableSpeech; } /** * @return $this */ public function setEnableSpeech(bool $enableSpeech): Input { $this->enableSpeech = $enableSpeech; return $this; } public function getEnableDtmf(): bool { return $this->enableDtmf; } /** * @return $this */ public function setEnableDtmf(bool $enableDtmf): Input { $this->enableDtmf = $enableDtmf; return $this; } } NCCO/Action/ActionInterface.php 0000644 00000000714 15107326345 0012262 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\NCCO\Action; use JsonSerializable; interface ActionInterface extends JsonSerializable { /** * @return array<string, string> */ public function toNCCOArray(): array; } NCCO/Action/Pay.php 0000644 00000011523 15107326345 0007755 0 ustar 00 <?php declare(strict_types=1); namespace Vonage\Voice\NCCO\Action; use InvalidArgumentException; /** * @deprecated This will be removed in the next major version as it is being removed from the API */ class Pay implements ActionInterface { protected const PERMITTED_VOICE_KEYS = ['language', 'style']; protected const PERMITTED_ERROR_KEYS = [ 'CardNumber' => [ 'InvalidCardType', 'InvalidCardNumber', 'Timeout' ], 'ExpirationDate' => [ 'InvalidExpirationDate', 'Timeout' ], 'SecurityCode' => [ 'InvalidSecurityCode', 'Timeout' ] ]; /** * @var float */ protected float $amount; /** * @var string */ protected string $currency; /** * @var string */ protected string $eventUrl; /** * @var array */ protected array $prompts; /** * @var array */ protected array $voice; /** * @return float */ public function getAmount(): float { return $this->amount; } public function setAmount(float $amount): void { $this->amount = $amount; } public function getCurrency(): ?string { return $this->currency; } public function setCurrency(?string $currency): void { $this->currency = $currency; } public function getEventUrl(): ?string { return $this->eventUrl; } public function setEventUrl(string $eventUrl): void { $this->eventUrl = $eventUrl; } /** * @return array */ public function getPrompts(): array { return $this->prompts; } public function setPrompts(array $prompts): void { if (!array_key_exists('type', $prompts)) { throw new InvalidArgumentException('type is required when setting a text prompt.'); } if (!array_key_exists($prompts['type'], self::PERMITTED_ERROR_KEYS)) { throw new InvalidArgumentException('invalid prompt type.'); } if (!array_key_exists('text', $prompts)) { throw new InvalidArgumentException('text is required when setting error text prompts..'); } if (!array_key_exists('errors', $prompts)) { throw new InvalidArgumentException('error settings are required when setting am error text prompt.'); } foreach ($prompts['errors'] as $errorPromptKey => $errorPromptData) { if (!array_key_exists('text', $errorPromptData)) { throw new InvalidArgumentException('text is required when setting error text prompts.'); } $permittedErrors = self::PERMITTED_ERROR_KEYS[$prompts['type']]; if (!in_array($errorPromptKey, $permittedErrors, true)) { throw new InvalidArgumentException('incorrect error type for prompt.'); } } $this->prompts = $prompts; } /** * @return ?array */ public function getVoice(): array { return $this->voice; } public function setVoice(array $settings): void { foreach (array_keys($settings) as $settingKey) { if (!in_array($settingKey, self::PERMITTED_VOICE_KEYS, true)) { throw new InvalidArgumentException($settingKey . ' did not fall under permitted voice settings'); } } $this->voice = $settings; } public function toNCCOArray(): array { $data = [ 'action' => 'pay', 'amount' => $this->getAmount() ]; if (isset($this->currency)) { $data['currency'] = $this->getCurrency(); } if (isset($this->eventUrl)) { $data['eventUrl'] = $this->getEventUrl(); } if (isset($this->prompts)) { $data['prompts'] = $this->getPrompts(); } if (isset($this->voice)) { $data['voice'] = $this->getVoice(); } return $data; } public function jsonSerialize(): array { return $this->toNCCOArray(); } public static function factory(array $data): Pay { $pay = new self(); if (array_key_exists('amount', $data)) { $pay->setAmount($data['amount']); } else { throw new InvalidArgumentException('Amount is required for this action.'); } if (array_key_exists('currency', $data)) { $pay->setCurrency($data['currency']); } if (array_key_exists('eventUrl', $data)) { $pay->setEventUrl($data['eventUrl']); } if (array_key_exists('prompts', $data)) { $pay->setPrompts($data['prompts']); } if (array_key_exists('voice', $data)) { $pay->setVoice($data['voice']); } return $pay; } } NCCO/Action/Connect.php 0000644 00000012056 15107326345 0010617 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\NCCO\Action; use InvalidArgumentException; use Vonage\Voice\Endpoint\EndpointInterface; use Vonage\Voice\VoiceObjects\AdvancedMachineDetection; use Vonage\Voice\Webhook; class Connect implements ActionInterface { public const EVENT_TYPE_SYNCHRONOUS = 'synchronous'; public const MACHINE_CONTINUE = 'continue'; public const MACHINE_HANGUP = 'hangup'; protected ?string $from = ''; protected ?string $eventType = ''; protected int $timeout = 0; protected int $limit = 0; protected $machineDetection = ''; protected ?Webhook $eventWebhook = null; protected ?string $ringbackTone = ''; protected ?AdvancedMachineDetection $advancedMachineDetection = null; public function __construct(protected EndpointInterface $endpoint) { } public static function factory(EndpointInterface $endpoint): Connect { return new Connect($endpoint); } /** * @return array|mixed */ #[\ReturnTypeWillChange] public function jsonSerialize() { return $this->toNCCOArray(); } public function toNCCOArray(): array { $data = [ 'action' => 'connect', 'endpoint' => [$this->endpoint->toArray()], ]; if ($this->getTimeout()) { $data['timeout'] = $this->getTimeout(); } if ($this->getLimit()) { $data['limit'] = $this->getLimit(); } if ($this->getMachineDetection()) { $data['machineDetection'] = $this->getMachineDetection(); } if ($this->getAdvancedMachineDetection()) { $data['advancedMachineDetection'] = $this->getAdvancedMachineDetection()->toArray(); } $from = $this->getFrom(); if ($from) { $data['from'] = $from; } $eventType = $this->getEventType(); if ($eventType) { $data['eventType'] = $eventType; } $eventWebhook = $this->getEventWebhook(); if ($eventWebhook) { $data['eventUrl'] = [$eventWebhook->getUrl()]; $data['eventMethod'] = $eventWebhook->getMethod(); } $ringbackTone = $this->getRingbackTone(); if ($ringbackTone) { $data['ringbackTone'] = $ringbackTone; } return $data; } public function getFrom(): ?string { return $this->from; } /** * @return $this */ public function setFrom(string $from): self { $this->from = $from; return $this; } public function getEventType(): ?string { return $this->eventType; } /** * @return $this */ public function setEventType(string $eventType): self { if ($eventType !== self::EVENT_TYPE_SYNCHRONOUS) { throw new InvalidArgumentException('Unknown event type for Connection action'); } $this->eventType = $eventType; return $this; } public function getTimeout(): ?int { return $this->timeout; } /** * @return $this */ public function setTimeout(int $timeout): self { $this->timeout = $timeout; return $this; } public function getLimit(): ?int { return $this->limit; } /** * @return $this */ public function setLimit(int $limit): self { $this->limit = $limit; return $this; } public function getMachineDetection(): ?string { return $this->machineDetection; } /** * @return $this */ public function setMachineDetection(string $machineDetection): self { if ( $machineDetection !== self::MACHINE_CONTINUE && $machineDetection !== self::MACHINE_HANGUP ) { throw new InvalidArgumentException('Unknown machine detection type'); } $this->machineDetection = $machineDetection; return $this; } public function getEventWebhook(): ?Webhook { return $this->eventWebhook; } /** * @return $this */ public function setEventWebhook(Webhook $eventWebhook): self { $this->eventWebhook = $eventWebhook; return $this; } public function getRingbackTone(): ?string { return $this->ringbackTone; } /** * @return $this */ public function setRingbackTone(string $ringbackTone): self { $this->ringbackTone = $ringbackTone; return $this; } public function getAdvancedMachineDetection(): ?AdvancedMachineDetection { return $this->advancedMachineDetection; } public function setAdvancedMachineDetection(AdvancedMachineDetection $advancedMachineDetection): static { $this->advancedMachineDetection = $advancedMachineDetection; return $this; } } NCCO/Action/Notify.php 0000644 00000004215 15107326345 0010474 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\NCCO\Action; use InvalidArgumentException; use Vonage\Voice\Webhook; use function array_key_exists; class Notify implements ActionInterface { public function __construct(protected array $payload, protected ?\Vonage\Voice\Webhook $eventWebhook) { } /** * @param array<array, mixed> $data */ public static function factory(array $payload, array $data): Notify { if (array_key_exists('eventUrl', $data)) { if (array_key_exists('eventMethod', $data)) { $webhook = new Webhook($data['eventUrl'], $data['eventMethod']); } else { $webhook = new Webhook($data['eventUrl']); } } else { throw new InvalidArgumentException('Must supply at least an eventUrl for Notify NCCO'); } return new Notify($payload, $webhook); } /** * @return array<string, mixed> */ public function jsonSerialize(): array { return $this->toNCCOArray(); } /** * @return array<string, mixed> */ public function toNCCOArray(): array { $eventWebhook = $this->getEventWebhook(); return [ 'action' => 'notify', 'payload' => $this->getPayload(), 'eventUrl' => [null !== $eventWebhook ? $eventWebhook->getUrl() : null], 'eventMethod' => null !== $eventWebhook ? $eventWebhook->getMethod() : null, ]; } public function getEventWebhook(): ?Webhook { return $this->eventWebhook; } public function setEventWebhook(Webhook $eventWebhook): self { $this->eventWebhook = $eventWebhook; return $this; } public function getPayload(): array { return $this->payload; } public function addToPayload(string $key, string $value): self { $this->payload[$key] = $value; return $this; } } Filter/VoiceFilter.php 0000644 00000010407 15107326345 0010725 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Filter; use DateTimeImmutable; use DateTimeZone; use InvalidArgumentException; use Vonage\Entity\Filter\FilterInterface; class VoiceFilter implements FilterInterface { public const STATUS_STARTED = 'started'; public const STATUS_RINGING = 'ringing'; public const STATUS_ANSWERED = 'answered'; public const STATUS_MACHINE = 'machine'; public const STATUS_COMPLETED = 'completed'; public const STATUS_BUSY = 'busy'; public const STATUS_CANCELLED = 'cancelled'; public const STATUS_FAILED = 'failed'; public const STATUS_REJECTED = 'rejected'; public const STATUS_TIMEOUT = 'timeout'; public const STATUS_UNANSWERED = 'unanswered'; public const ORDER_ASC = 'asc'; public const ORDER_DESC = 'desc'; /** * @var string */ protected $status; /** * @var DateTimeImmutable */ protected $dateStart; /** * @var DateTimeImmutable */ protected $dateEnd; /** * @var int */ protected $pageSize = 10; /** * @var int */ protected $recordIndex = 0; /** * @var string */ protected $order = 'asc'; /** * @var string */ protected $conversationUUID; public function getQuery(): array { $data = [ 'page_size' => $this->getPageSize(), 'record_index' => $this->getRecordIndex(), 'order' => $this->getOrder(), ]; if ($this->getStatus()) { $data['status'] = $this->getStatus(); } if ($this->getDateStart()) { $data['date_start'] = $this->getDateStart()->format('Y-m-d\TH:i:s\Z'); } if ($this->getDateEnd()) { $data['date_end'] = $this->getDateEnd()->format('Y-m-d\TH:i:s\Z'); } if ($this->getConversationUUID()) { $data['conversation_uuid'] = $this->getConversationUUID(); } return $data; } public function getStatus(): ?string { return $this->status; } /** * @return $this */ public function setStatus(string $status): self { $this->status = $status; return $this; } public function getDateStart(): ?DateTimeImmutable { return $this->dateStart; } /** * @return $this */ public function setDateStart(DateTimeImmutable $dateStart): self { $dateStart = $dateStart->setTimezone(new DateTimeZone('Z')); $this->dateStart = $dateStart; return $this; } public function getDateEnd(): ?DateTimeImmutable { return $this->dateEnd; } /** * @return $this */ public function setDateEnd(DateTimeImmutable $dateEnd): self { $dateEnd = $dateEnd->setTimezone(new DateTimeZone('Z')); $this->dateEnd = $dateEnd; return $this; } public function getPageSize(): int { return $this->pageSize; } /** * @return $this */ public function setPageSize(int $pageSize): self { $this->pageSize = $pageSize; return $this; } public function getRecordIndex(): int { return $this->recordIndex; } /** * @return $this */ public function setRecordIndex(int $recordIndex): self { $this->recordIndex = $recordIndex; return $this; } public function getOrder(): string { return $this->order; } /** * @return $this */ public function setOrder(string $order): self { if ($order !== self::ORDER_ASC && $order !== self::ORDER_DESC) { throw new InvalidArgumentException('Order must be `asc` or `desc`'); } $this->order = $order; return $this; } public function getConversationUUID(): ?string { return $this->conversationUUID; } /** * @return $this */ public function setConversationUUID(string $conversationUUID): self { $this->conversationUUID = $conversationUUID; return $this; } } ClientFactory.php 0000644 00000001403 15107326345 0010027 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice; use Psr\Container\ContainerInterface; use Vonage\Client\APIResource; use Vonage\Client\Credentials\Handler\KeypairHandler; class ClientFactory { public function __invoke(ContainerInterface $container): Client { /** @var APIResource $api */ $api = $container->make(APIResource::class); $api ->setBaseUri('/v1/calls') ->setAuthHandler(new KeypairHandler()) ->setCollectionName('calls'); return new Client($api); } } Client.php 0000644 00000016777 15107326346 0006524 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice; use DateTimeImmutable; use DateTimeZone; use Exception; use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Message\StreamInterface; use Vonage\Client\APIClient; use Vonage\Client\APIResource; use Vonage\Entity\Filter\FilterInterface; use Vonage\Entity\Hydrator\ArrayHydrator; use Vonage\Entity\IterableAPICollection; use Vonage\Voice\NCCO\Action\Talk; use Vonage\Voice\NCCO\NCCO; use Vonage\Voice\Webhook\Event; use function is_null; class Client implements APIClient { public function __construct(protected APIResource $api) { } public function getAPIResource(): APIResource { return $this->api; } /** * @throws ClientExceptionInterface * @throws \Vonage\Client\Exception\Exception * @throws Exception * @throws Exception * * @return Event {uuid: string, conversation_uuid: string, status: string, direction: string} */ public function createOutboundCall(OutboundCall $call): Event { $json = [ 'to' => [$call->getTo()], ]; if ($call->getFrom()) { $json['from'] = $call->getFrom(); } else { $json['random_from_number'] = true; } if (null !== $call->getAnswerWebhook()) { $json['answer_url'] = [$call->getAnswerWebhook()->getUrl()]; $json['answer_method'] = $call->getAnswerWebhook()->getMethod(); } if (null !== $call->getEventWebhook()) { $json['event_url'] = [$call->getEventWebhook()->getUrl()]; $json['event_method'] = $call->getEventWebhook()->getMethod(); } if (null !== $call->getNCCO()) { $json['ncco'] = $call->getNCCO(); } if ($call->getMachineDetection()) { $json['machine_detection'] = $call->getMachineDetection(); } if (!is_null($call->getLengthTimer())) { $json['length_timer'] = (string)$call->getLengthTimer(); } if (!is_null($call->getRingingTimer())) { $json['ringing_timer'] = (string)$call->getRingingTimer(); } if (!is_null($call->getAdvancedMachineDetection())) { $json['advanced_machine_detection'] = $call->getAdvancedMachineDetection()->toArray(); } $event = $this->api->create($json); $event['to'] = $call->getTo()->getId(); if ($call->getFrom()) { $event['from'] = $call->getFrom()->getId(); } $event['timestamp'] = (new DateTimeImmutable("now", new DateTimeZone("UTC")))->format(DATE_ATOM); return new Event($event); } /** * @throws ClientExceptionInterface * @throws \Vonage\Client\Exception\Exception */ public function earmuffCall(string $callId): void { $this->modifyCall($callId, CallAction::EARMUFF); } /** * @throws ClientExceptionInterface * @throws \Vonage\Client\Exception\Exception * @throws Exception */ public function get(string $callId): Call { return (new CallFactory())->create($this->api->get($callId)); } /** * @throws ClientExceptionInterface * @throws \Vonage\Client\Exception\Exception */ public function hangupCall(string $callId): void { $this->modifyCall($callId, CallAction::HANGUP); } /** * @throws ClientExceptionInterface * @throws \Vonage\Client\Exception\Exception */ public function modifyCall(string $callId, string $action): void { $this->api->update($callId, [ 'action' => $action, ]); } /** * @throws ClientExceptionInterface * @throws \Vonage\Client\Exception\Exception */ public function muteCall(string $callId): void { $this->modifyCall($callId, CallAction::MUTE); } /** * @throws ClientExceptionInterface * @throws \Vonage\Client\Exception\Exception * * @return array{uuid: string, message: string} */ public function playDTMF(string $callId, string $digits): array { return $this->api->update($callId . '/dtmf', [ 'digits' => $digits ]); } /** * @throws ClientExceptionInterface * @throws \Vonage\Client\Exception\Exception * * @return array{uuid: string, message: string} */ public function playTTS(string $callId, Talk $action): array { $payload = $action->toNCCOArray(); unset($payload['action']); return $this->api->update($callId . '/talk', $payload); } public function search(FilterInterface $filter = null): IterableAPICollection { $response = $this->api->search($filter); $response->setApiResource(clone $this->api); $response->setNaiveCount(true); $hydrator = new ArrayHydrator(); $hydrator->setPrototype(new Call()); $response->setHydrator($hydrator); return $response; } /** * @throws ClientExceptionInterface * @throws \Vonage\Client\Exception\Exception * * @return array{uuid: string, message: string} */ public function stopStreamAudio(string $callId): array { return $this->api->delete($callId . '/stream'); } /** * @throws ClientExceptionInterface * @throws \Vonage\Client\Exception\Exception * * @return array{uuid: string, message: string} */ public function stopTTS(string $callId): array { return $this->api->delete($callId . '/talk'); } /** * @throws ClientExceptionInterface * @throws \Vonage\Client\Exception\Exception * * @return array{uuid: string, message: string} */ public function streamAudio(string $callId, string $url, int $loop = 1, float $volumeLevel = 0.0): array { return $this->api->update($callId . '/stream', [ 'stream_url' => [$url], 'loop' => (string)$loop, 'level' => (string)$volumeLevel, ]); } /** * @throws ClientExceptionInterface * @throws \Vonage\Client\Exception\Exception */ public function transferCallWithNCCO(string $callId, NCCO $ncco): void { $this->api->update($callId, [ 'action' => 'transfer', 'destination' => [ 'type' => 'ncco', 'ncco' => $ncco->toArray() ], ]); } /** * @throws ClientExceptionInterface * @throws \Vonage\Client\Exception\Exception */ public function transferCallWithUrl(string $callId, string $url): void { $this->api->update($callId, [ 'action' => 'transfer', 'destination' => [ 'type' => 'ncco', 'url' => [$url] ] ]); } /** * @throws ClientExceptionInterface * @throws \Vonage\Client\Exception\Exception */ public function unearmuffCall(string $callId): void { $this->modifyCall($callId, CallAction::UNEARMUFF); } /** * @throws ClientExceptionInterface * @throws \Vonage\Client\Exception\Exception */ public function unmuteCall(string $callId): void { $this->modifyCall($callId, CallAction::UNMUTE); } public function getRecording(string $url): StreamInterface { return $this->getAPIResource()->get($url, [], [], false, true); } } Webhook.php 0000644 00000001203 15107326346 0006656 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice; class Webhook { public const METHOD_GET = 'GET'; public const METHOD_POST = 'POST'; public function __construct(protected string $url, protected string $method = self::METHOD_POST) { } public function getMethod(): string { return $this->method; } public function getUrl(): string { return $this->url; } } VoiceObjects/AdvancedMachineDetection.php 0000644 00000005655 15107326346 0014507 0 ustar 00 <?php namespace Vonage\Voice\VoiceObjects; use Vonage\Entity\Hydrator\ArrayHydrateInterface; class AdvancedMachineDetection implements ArrayHydrateInterface { public const MACHINE_BEHAVIOUR_CONTINUE = 'continue'; public const MACHINE_BEHAVIOUR_HANGUP = 'hangup'; public const MACHINE_MODE_DETECT = 'detect'; public const MACHINE_MODE_DETECT_BEEP = 'detect_beep'; public const BEEP_TIMEOUT_MIN = 45; public const BEEP_TIMEOUT_MAX = 120; protected array $permittedBehaviour = [self::MACHINE_BEHAVIOUR_CONTINUE, self::MACHINE_BEHAVIOUR_HANGUP]; protected array $permittedModes = [self::MACHINE_MODE_DETECT, self::MACHINE_MODE_DETECT_BEEP]; public function __construct( protected string $behaviour, protected int $beepTimeout, protected string $mode = 'detect' ) { if (!$this->isValidBehaviour($behaviour)) { throw new \InvalidArgumentException($behaviour . ' is not a valid behavior string'); } if (!$this->isValidMode($mode)) { throw new \InvalidArgumentException($mode . ' is not a valid mode string'); } if (!$this->isValidTimeout($beepTimeout)) { throw new \OutOfBoundsException('Timeout ' . $beepTimeout . ' is not valid'); } } protected function isValidBehaviour(string $behaviour): bool { if (in_array($behaviour, $this->permittedBehaviour, true)) { return true; } return false; } protected function isValidMode(string $mode): bool { if (in_array($mode, $this->permittedModes, true)) { return true; } return false; } protected function isValidTimeout(int $beepTimeout): bool { $range = [ 'options' => [ 'min_range' => self::BEEP_TIMEOUT_MIN, 'max_range' => self::BEEP_TIMEOUT_MAX ] ]; if (filter_var($beepTimeout, FILTER_VALIDATE_INT, $range)) { return true; } return false; } public function fromArray(array $data): static { $this->isArrayValid($data); $this->behaviour = $data['behaviour']; $this->mode = $data['mode']; $this->beepTimeout = $data['beep_timeout']; return $this; } public function toArray(): array { return [ 'behavior' => $this->behaviour, 'mode' => $this->mode, 'beep_timeout' => $this->beepTimeout ]; } protected function isArrayValid(array $data): bool { if ( !array_key_exists('behaviour', $data) || !array_key_exists('mode', $data) || !array_key_exists('beep_timeout', $data) ) { return false; } return $this->isValidBehaviour($data['behaviour']) || $this->isValidMode($data['mode']) || $this->isValidTimeout($data['beep_timeout']); } } Endpoint/EndpointInterface.php 0000644 00000000755 15107326346 0012454 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Endpoint; use JsonSerializable; interface EndpointInterface extends JsonSerializable { public function getId(): string; /** * @return array<string, array> */ public function toArray(): array; } Endpoint/SIP.php 0000644 00000003252 15107326346 0007501 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Endpoint; class SIP implements EndpointInterface { /** * @var array<string, string> */ protected $headers = []; public function __construct(protected string $id, array $headers = []) { $this->setHeaders($headers); } public static function factory(string $uri, array $headers = []): SIP { return new SIP($uri, $headers); } /** * @return array{type: string, uri: string, headers?: array<string, string>} */ public function jsonSerialize(): array { return $this->toArray(); } /** * @return array{type: string, uri: string, headers?: array<string, string>} */ public function toArray(): array { $data = [ 'type' => 'sip', 'uri' => $this->id, ]; if (!empty($this->getHeaders())) { $data['headers'] = $this->getHeaders(); } return $data; } public function getId(): string { return $this->id; } public function getHeaders(): array { return $this->headers; } /** * @return $this */ public function addHeader(string $key, string $value): self { $this->headers[$key] = $value; return $this; } /** * @return $this */ public function setHeaders(array $headers): self { $this->headers = $headers; return $this; } } Endpoint/Websocket.php 0000644 00000005114 15107326346 0010773 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Endpoint; use function array_key_exists; class Websocket implements EndpointInterface { public const TYPE_16000 = 'audio/116;rate=16000'; public const TYPE_8000 = 'audio/116;rate=8000'; /** * @var string */ protected $contentType; /** * @var array<string, string> */ protected $headers = []; public function __construct(protected string $id, string $rate = self::TYPE_8000, array $headers = []) { $this->setContentType($rate); $this->setHeaders($headers); } public static function factory(string $uri, array $data = []): Websocket { $endpoint = new Websocket($uri); if (array_key_exists('content-type', $data)) { $endpoint->setContentType($data['content-type']); } if (array_key_exists('headers', $data)) { $endpoint->setHeaders($data['headers']); } return $endpoint; } /** * @return array{type: string, uri: string, content-type?: string, headers?: array<string, string>} */ public function jsonSerialize(): array { return $this->toArray(); } /** * @return array{type: string, uri: string, content-type?: string, headers?: array<string, string>} */ public function toArray(): array { $data = [ 'type' => 'websocket', 'uri' => $this->id, 'content-type' => $this->getContentType(), ]; if (!empty($this->getHeaders())) { $data['headers'] = $this->getHeaders(); } return $data; } public function getId(): string { return $this->id; } public function getContentType(): string { return $this->contentType; } /** * @return $this */ public function setContentType(string $contentType): self { $this->contentType = $contentType; return $this; } public function getHeaders(): array { return $this->headers; } /** * @return $this */ public function addHeader(string $key, string $value): self { $this->headers[$key] = $value; return $this; } /** * @return $this */ public function setHeaders(array $headers): self { $this->headers = $headers; return $this; } } Endpoint/App.php 0000644 00000001635 15107326346 0007571 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Endpoint; class App implements EndpointInterface { public function __construct(protected string $id) { } public static function factory(string $user): App { return new App($user); } /** * @return array{type: string, user: string} */ public function jsonSerialize(): array { return $this->toArray(); } /** * @return array{type: string, user: string} */ public function toArray(): array { return [ 'type' => 'app', 'user' => $this->id, ]; } public function getId(): string { return $this->id; } } Endpoint/EndpointFactory.php 0000644 00000001600 15107326346 0012151 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Endpoint; use RuntimeException; use Vonage\Entity\Factory\FactoryInterface; class EndpointFactory implements FactoryInterface { public function create(array $data): ?EndpointInterface { return match ($data['type']) { 'app' => App::factory($data['user']), 'phone' => Phone::factory($data['number'], $data), 'sip' => SIP::factory($data['uri'], $data), 'vbc' => VBC::factory($data['extension']), 'websocket' => Websocket::factory($data['uri'], $data), default => throw new RuntimeException('Unknown endpoint type'), }; } } Endpoint/VBC.php 0000644 00000001654 15107326346 0007464 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Endpoint; class VBC implements EndpointInterface { public function __construct(protected string $id) { } public static function factory(string $extension): VBC { return new VBC($extension); } /** * @return array{type: string, user: string} */ public function jsonSerialize(): array { return $this->toArray(); } /** * @return array{type: string, user: string} */ public function toArray(): array { return [ 'type' => 'vbc', 'extension' => $this->id, ]; } public function getId(): string { return $this->id; } } Endpoint/Phone.php 0000644 00000005643 15107326346 0010125 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Endpoint; use function array_key_exists; class Phone implements EndpointInterface { /** * @var ?string */ protected $ringbackTone; /** * @var ?string */ protected $url; public function __construct(protected string $id, protected ?string $dtmfAnswer = null) { } public static function factory(string $number, array $data): Phone { $endpoint = new Phone($number); if (array_key_exists('dtmfAnswer', $data)) { $endpoint->setDtmfAnswer($data['dtmfAnswer']); } if (array_key_exists('onAnswer', $data)) { $endpoint->setUrl($data['onAnswer']['url']); if (array_key_exists('ringbackTone', $data['onAnswer'])) { $endpoint->setRingbackTone($data['onAnswer']['ringbackTone']); } // Legacy name for ringbackTone if (array_key_exists('ringback', $data['onAnswer'])) { $endpoint->setRingbackTone($data['onAnswer']['ringback']); } } return $endpoint; } public function getDtmfAnswer(): ?string { return $this->dtmfAnswer; } /** * @return array{type: string, number: string, dtmfAnswer?: string} */ public function jsonSerialize(): array { return $this->toArray(); } /** * @return $this */ public function setDtmfAnswer(string $dtmf): self { $this->dtmfAnswer = $dtmf; return $this; } /** * @return array{type: string, number: string, dtmfAnswer?: string} */ public function toArray(): array { $data = [ 'type' => 'phone', 'number' => $this->id, ]; if (null !== $this->getDtmfAnswer()) { $data['dtmfAnswer'] = $this->getDtmfAnswer(); } if (null !== $this->getUrl()) { $data['onAnswer']['url'] = $this->getUrl(); if (null !== $this->getRingbackTone()) { $data['onAnswer']['ringbackTone'] = $this->getRingbackTone(); } } return $data; } public function getId(): string { return $this->id; } public function getRingbackTone(): ?string { return $this->ringbackTone; } /** * @return $this */ public function setRingbackTone(string $ringbackTone): self { $this->ringbackTone = $ringbackTone; return $this; } public function getUrl(): ?string { return $this->url; } /** * @return $this */ public function setUrl(string $url): self { $this->url = $url; return $this; } } CallFactory.php 0000644 00000001004 15107326346 0007462 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice; use Exception; use Vonage\Entity\Factory\FactoryInterface; class CallFactory implements FactoryInterface { /** * @throws Exception */ public function create(array $data): Call { return new Call($data); } } Call/Inbound.php 0000644 00000000613 15107326346 0007535 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Call; /** * @deprecated This objects are no longer viable and will be removed in a future version */ class Inbound { } Call/Call.php 0000644 00000004672 15107326346 0007023 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Call; use Vonage\Client\Request\AbstractRequest; use function is_null; /** * @deprecated This objects are no longer viable and will be removed in a future version */ class Call extends AbstractRequest { /** * @param $url * @param $to * @param $from */ public function __construct($url, $to, $from = null) { $this->params['answer_url'] = $url; $this->params['to'] = $to; if (!is_null($from)) { $this->params['from'] = $from; } } /** * @param $url * @param $method * * @return $this */ public function setAnswer($url, $method = null): Call { $this->params['answer_url'] = $url; if (!is_null($method)) { $this->params['answer_method'] = $method; } else { unset($this->params['answer_method']); } return $this; } /** * @param $url * @param $method * * @return $this */ public function setError($url, $method = null): Call { $this->params['error_url'] = $url; if (!is_null($method)) { $this->params['error_method'] = $method; } else { unset($this->params['error_method']); } return $this; } /** * @param $url * @param $method * * @return $this */ public function setStatus($url, $method = null): Call { $this->params['status_url'] = $url; if (!is_null($method)) { $this->params['status_method'] = $method; } else { unset($this->params['status_method']); } return $this; } /** * @param bool $hangup * @param $timeout * * @return $this */ public function setMachineDetection($hangup = true, $timeout = null): Call { $this->params['machine_detection'] = ($hangup ? 'hangup' : 'true'); if (!is_null($timeout)) { $this->params['machine_timeout'] = (int)$timeout; } else { unset($this->params['machine_timeout']); } return $this; } public function getURI(): string { return '/call/json'; } } Webhook/Error.php 0000644 00000002114 15107326346 0007751 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Webhook; use DateTimeImmutable; use Exception; class Error { /** * @var string */ protected $conversationUuid; /** * @var string */ protected $reason; /** * @var DateTimeImmutable */ protected $timestamp; /** * @throws Exception */ public function __construct(array $event) { $this->conversationUuid = $event['conversation_uuid']; $this->reason = $event['reason']; $this->timestamp = new DateTimeImmutable($event['timestamp']); } public function getConversationUuid(): string { return $this->conversationUuid; } public function getReason(): string { return $this->reason; } public function getTimestamp(): DateTimeImmutable { return $this->timestamp; } } Webhook/Notification.php 0000644 00000002416 15107326346 0011313 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Webhook; use DateTimeImmutable; use Exception; use function is_string; use function json_decode; class Notification { /** * @var array<string, mixed> */ protected $payload; /** * @var string */ protected $conversationUuid; /** * @var DateTimeImmutable */ protected $timestamp; /** * @throws Exception */ public function __construct(array $data) { if (is_string($data['payload'])) { $data['payload'] = json_decode($data['payload'], true); } $this->payload = $data['payload']; $this->conversationUuid = $data['conversation_uuid']; $this->timestamp = new DateTimeImmutable($data['timestamp']); } public function getPayload(): array { return $this->payload; } public function getConversationUuid(): string { return $this->conversationUuid; } public function getTimestamp(): DateTimeImmutable { return $this->timestamp; } } Webhook/Transfer.php 0000644 00000002520 15107326346 0010445 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Webhook; use DateTimeImmutable; use Exception; class Transfer { /** * @var string */ protected $conversationUuidFrom; /** * @var string */ protected $conversationUuidTo; /** * @var string */ protected $uuid; /** * @var DateTimeImmutable */ protected $timestamp; /** * @throws Exception */ public function __construct(array $event) { $this->conversationUuidFrom = $event['conversation_uuid_from']; $this->conversationUuidTo = $event['conversation_uuid_to']; $this->uuid = $event['uuid']; $this->timestamp = new DateTimeImmutable($event['timestamp']); } public function getConversationUuidFrom(): string { return $this->conversationUuidFrom; } public function getConversationUuidTo(): string { return $this->conversationUuidTo; } public function getUuid(): string { return $this->uuid; } public function getTimestamp(): DateTimeImmutable { return $this->timestamp; } } Webhook/Record.php 0000644 00000003725 15107326346 0010107 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Webhook; use DateTimeImmutable; use Exception; class Record { /** * @var DateTimeImmutable */ protected $startTime; /** * @var string */ protected $recordingUrl; /** * @var int */ protected $size; /** * @var string */ protected $recordingUuid; /** * @var DateTimeImmutable */ protected $endTime; /** * @var string */ protected $conversationUuid; /** * @var DateTimeImmutable */ protected $timestamp; /** * @throws Exception */ public function __construct(array $event) { $this->startTime = new DateTimeImmutable($event['start_time']); $this->endTime = new DateTimeImmutable($event['end_time']); $this->timestamp = new DateTimeImmutable($event['timestamp']); $this->recordingUrl = $event['recording_url']; $this->recordingUuid = $event['recording_uuid']; $this->conversationUuid = $event['conversation_uuid']; $this->size = (int)$event['size']; } public function getStartTime(): DateTimeImmutable { return $this->startTime; } public function getRecordingUrl(): string { return $this->recordingUrl; } public function getSize(): int { return $this->size; } public function getRecordingUuid(): string { return $this->recordingUuid; } public function getEndTime(): DateTimeImmutable { return $this->endTime; } public function getConversationUuid(): string { return $this->conversationUuid; } public function getTimestamp(): DateTimeImmutable { return $this->timestamp; } } Webhook/Answer.php 0000644 00000002150 15107326346 0010117 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Webhook; class Answer { /** * @var string */ protected $conversationUuid; /** * @var string */ protected $from; /** * @var string */ protected $to; /** * @var string */ protected $uuid; public function __construct(array $event) { $this->from = $event['from']; $this->to = $event['to']; $this->uuid = $event['uuid'] ?? $event['call_uuid']; $this->conversationUuid = $event['conversation_uuid']; } public function getConversationUuid(): string { return $this->conversationUuid; } public function getFrom(): string { return $this->from; } public function getTo(): string { return $this->to; } public function getUuid(): string { return $this->uuid; } } Webhook/Input.php 0000644 00000004154 15107326346 0007765 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Webhook; use DateTimeImmutable; use Exception; use function is_string; use function json_decode; class Input { /** * @var array */ protected $speech; /** * @var array */ protected $dtmf; /** * @var string */ protected $from; /** * @var string */ protected $to; /** * @var string */ protected $uuid; /** * @var string */ protected $conversationUuid; /** * @var DateTimeImmutable */ protected $timestamp; /** * @throws Exception */ public function __construct(array $data) { // GET requests push this in as a string if (is_string($data['speech'])) { $data['speech'] = json_decode($data['speech'], true); } $this->speech = $data['speech']; // GET requests push this in as a string if (is_string($data['dtmf'])) { $data['dtmf'] = json_decode($data['dtmf'], true); } $this->dtmf = $data['dtmf']; $this->to = $data['to']; $this->from = $data['from']; $this->uuid = $data['uuid']; $this->conversationUuid = $data['conversation_uuid']; $this->timestamp = new DateTimeImmutable($data['timestamp']); } public function getSpeech(): array { return $this->speech; } public function getDtmf(): array { return $this->dtmf; } public function getFrom(): string { return $this->from; } public function getTo(): string { return $this->to; } public function getUuid(): string { return $this->uuid; } public function getConversationUuid(): string { return $this->conversationUuid; } public function getTimestamp(): DateTimeImmutable { return $this->timestamp; } } Webhook/Factory.php 0000644 00000003251 15107326346 0010272 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Webhook; use Exception; use InvalidArgumentException; use Vonage\Webhook\Factory as WebhookFactory; use function array_diff; use function array_key_exists; use function array_keys; use function count; class Factory extends WebhookFactory { /** * @throws Exception * * @return mixed|Answer|Error|Event|Input|Notification|Record|Transfer */ public static function createFromArray(array $data) { if (array_key_exists('status', $data)) { return new Event($data); } // Answer webhooks have no defining type other than length and keys if (count($data) === 4 && array_diff(array_keys($data), ['to', 'from', 'uuid', 'conversation_uuid']) === []) { return new Answer($data); } if (array_key_exists('type', $data) && $data['type'] === 'transfer') { return new Transfer($data); } if (array_key_exists('recording_url', $data)) { return new Record($data); } if (array_key_exists('reason', $data)) { return new Error($data); } if (array_key_exists('payload', $data)) { return new Notification($data); } if (array_key_exists('speech', $data) || array_key_exists('dtmf', $data)) { return new Input($data); } throw new InvalidArgumentException('Unable to detect incoming webhook type'); } } Webhook/Event.php 0000644 00000010245 15107326346 0007745 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice\Webhook; use DateTimeImmutable; use Exception; use function array_key_exists; use function is_null; class Event { public const STATUS_STARTED = 'started'; public const STATUS_RINGING = 'ringing'; public const STATUS_ANSWERED = 'answered'; public const STATUS_BUSY = 'busy'; public const STATUS_CANCELLED = 'cancelled'; public const STATUS_UNANSWERED = 'unanswered'; public const STATUS_DISCONNECTED = 'disconnected'; public const STATUS_REJECTED = 'rejected'; public const STATUS_FAILED = 'failed'; public const STATUS_HUMAN = 'human'; public const STATUS_MACHINE = 'machine'; public const STATUS_TIMEOUT = 'timeout'; public const STATUS_COMPLETED = 'completed'; /** * @var string */ protected $conversationUuid; /** * @var string */ protected $detail; /** * @var string */ protected $direction; /** * @var ?string */ protected $duration; /** * @var ?DateTimeImmutable */ protected $endTime; /** * @var string */ protected $from; /** * @var ?string */ protected $network; /** * @var ?string */ protected $price; /** * @var ?string */ protected $rate; /** * @var string */ protected $status; /** * @var ?DateTimeImmutable */ protected $startTime; /** * @var DateTimeImmutable */ protected $timestamp; /** * @var string */ protected $to; /** * @var string */ protected $uuid; /** * @throws Exception */ public function __construct(array $event) { $this->from = $event['from'] ?? null; $this->to = $event['to']; $this->uuid = $event['uuid'] ?? $event['call_uuid']; $this->conversationUuid = $event['conversation_uuid']; $this->status = $event['status']; $this->direction = $event['direction']; $this->timestamp = new DateTimeImmutable($event['timestamp']); $this->rate = $event['rate'] ?? null; $this->network = $event['network'] ?? null; $this->duration = $event['duration'] ?? null; $this->price = $event['price'] ?? null; if (array_key_exists('start_time', $event) && !is_null($event['start_time'])) { $this->startTime = new DateTimeImmutable($event['start_time']); } if (array_key_exists('end_time', $event)) { $this->endTime = new DateTimeImmutable($event['end_time']); } $this->detail = $event['detail'] ?? null; } public function getConversationUuid(): string { return $this->conversationUuid; } /** * Returns additional details on the event, if available * Not all events contain this field, so it may be null. */ public function getDetail(): ?string { return $this->detail; } public function getDirection(): string { return $this->direction; } public function getFrom(): ?string { return $this->from; } public function getStatus(): string { return $this->status; } public function getTimestamp(): DateTimeImmutable { return $this->timestamp; } public function getTo(): string { return $this->to; } public function getUuid(): string { return $this->uuid; } public function getNetwork(): ?string { return $this->network; } public function getRate(): ?string { return $this->rate; } public function getStartTime(): ?DateTimeImmutable { return $this->startTime; } public function getEndTime(): ?DateTimeImmutable { return $this->endTime; } public function getDuration(): ?string { return $this->duration; } public function getPrice(): ?string { return $this->price; } } Call.php 0000644 00000010034 15107326346 0006135 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice; use DateTime; use Exception; use Vonage\Entity\Hydrator\ArrayHydrateInterface; use Vonage\Voice\Endpoint\EndpointFactory; use Vonage\Voice\Endpoint\EndpointInterface; use function array_key_exists; class Call implements ArrayHydrateInterface { /** * @var string */ protected $conversationUuid; /** * @var string */ protected $direction; /** * @var string */ protected $duration; /** * @var DateTime */ protected $endTime; /** * @var EndpointInterface */ protected $from; /** * @var string */ protected $network; /** * @var string */ protected $price; /** * @var string */ protected $rate; /** * @var DateTime */ protected $startTime; /** * @var string */ protected $status; /** * @var EndpointInterface */ protected $to; /** * @var string */ protected $uuid; /** * @throws Exception */ public function __construct(array $data = []) { if (!empty($data)) { $this->fromArray($data); } } /** * @throws Exception */ public function fromArray(array $data): void { if (array_key_exists('to', $data)) { $to = $data['to'][0] ?? $data['to']; $this->to = (new EndpointFactory())->create($to); } if (array_key_exists('from', $data)) { $from = $data['from'][0] ?? $data['from']; $this->from = (new EndpointFactory())->create($from); } $this->uuid = $data['uuid']; $this->conversationUuid = $data['conversation_uuid']; $this->status = $data['status']; $this->direction = $data['direction']; $this->rate = $data['rate'] ?? null; $this->duration = $data['duration'] ?? null; $this->price = $data['price'] ?? null; $this->startTime = new DateTime($data['start_time']); $this->endTime = new DateTime($data['end_time']); $this->network = $data['network'] ?? null; } public function getUuid(): string { return $this->uuid; } public function toArray(): array { $data = [ 'uuid' => $this->uuid, 'conversation_uuid' => $this->conversationUuid, 'status' => $this->status, 'direction' => $this->direction, 'rate' => $this->rate, 'duration' => $this->duration, 'price' => $this->price, 'start_time' => $this->startTime->format('Y-m-d H:i:s'), 'end_time' => $this->endTime->format('Y-m-d H:i:s'), 'network' => $this->network, ]; $to = $this->getTo(); $from = $this->getFrom(); if ($to) { $data['to'][] = $to->toArray(); } if ($from) { $data['from'][] = $from->toArray(); } return $data; } public function getTo(): EndpointInterface { return $this->to; } public function getRate(): string { return $this->rate; } public function getFrom(): EndpointInterface { return $this->from; } public function getStatus(): string { return $this->status; } public function getDirection(): string { return $this->direction; } public function getPrice(): string { return $this->price; } public function getDuration(): string { return $this->duration; } public function getStartTime(): DateTime { return $this->startTime; } public function getEndTime(): DateTime { return $this->endTime; } public function getNetwork(): string { return $this->network; } } OutboundCall.php 0000644 00000007465 15107326346 0007673 0 ustar 00 <?php /** * Vonage Client Library for PHP * * @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com) * @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0 */ declare(strict_types=1); namespace Vonage\Voice; use InvalidArgumentException; use Vonage\Voice\Endpoint\EndpointInterface; use Vonage\Voice\Endpoint\Phone; use Vonage\Voice\NCCO\NCCO; use Vonage\Voice\VoiceObjects\AdvancedMachineDetection; class OutboundCall { public const MACHINE_CONTINUE = 'continue'; public const MACHINE_HANGUP = 'hangup'; protected ?Webhook $answerWebhook = null; protected ?Webhook $eventWebhook = null; /** * Length of seconds before Vonage hangs up after going into `in_progress` status */ protected int $lengthTimer = 7200; /** * What to do when Vonage detects an answering machine. */ protected ?string $machineDetection = ''; /** * Overrides machine detection if used for more configuration options */ protected ?AdvancedMachineDetection $advancedMachineDetection = null; protected ?NCCO $ncco = null; /** * Whether to use random numbers linked on the application */ protected bool $randomFrom = false; /** * Length of time Vonage will allow a phone number to ring before hanging up */ protected int $ringingTimer = 60; /** * Creates a new Outbound Call object * If no `$from` parameter is passed, the system will use a random number * that is linked to the application instead. */ public function __construct(protected EndpointInterface $to, protected ?Phone $from = null) { if (!$from) { $this->randomFrom = true; } } public function getAnswerWebhook(): ?Webhook { return $this->answerWebhook; } public function getEventWebhook(): ?Webhook { return $this->eventWebhook; } public function getFrom(): ?Phone { return $this->from; } public function getLengthTimer(): ?int { return $this->lengthTimer; } public function getMachineDetection(): ?string { return $this->machineDetection; } public function getNCCO(): ?NCCO { return $this->ncco; } public function getRingingTimer(): ?int { return $this->ringingTimer; } public function getTo(): EndpointInterface { return $this->to; } public function setAnswerWebhook(Webhook $webhook): self { $this->answerWebhook = $webhook; return $this; } public function setEventWebhook(Webhook $webhook): self { $this->eventWebhook = $webhook; return $this; } public function setLengthTimer(int $timer): self { $this->lengthTimer = $timer; return $this; } public function setMachineDetection(string $action): self { if ($action === self::MACHINE_CONTINUE || $action === self::MACHINE_HANGUP) { $this->machineDetection = $action; return $this; } throw new InvalidArgumentException('Unknown machine detection action'); } public function setNCCO(NCCO $ncco): self { $this->ncco = $ncco; return $this; } public function setRingingTimer(int $timer): self { $this->ringingTimer = $timer; return $this; } public function getRandomFrom(): bool { return $this->randomFrom; } public function getAdvancedMachineDetection(): ?AdvancedMachineDetection { return $this->advancedMachineDetection; } public function setAdvancedMachineDetection(?AdvancedMachineDetection $advancedMachineDetection): static { $this->advancedMachineDetection = $advancedMachineDetection; return $this; } }
Simpan