From c1b2a9fd1e269424344907f599935c8e19c834ec Mon Sep 17 00:00:00 2001 From: Jim Seconde Date: Mon, 28 Oct 2024 13:00:00 +0000 Subject: [PATCH 1/2] Added ability to add a fallback URL --- phpunit.xml.dist | 3 +++ src/Application/Application.php | 2 +- src/Application/VoiceConfig.php | 2 ++ src/Application/Webhook.php | 2 -- test/Application/ClientTest.php | 13 +++++++++++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3365ff0e..ff6973bd 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -23,6 +23,9 @@ test/Verify + + test/Application + test/Verify2 diff --git a/src/Application/Application.php b/src/Application/Application.php index 3f3eed30..ee12922a 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -230,7 +230,7 @@ public function toArray(): array { // Build up capabilities that are set $availableCapabilities = [ - 'voice' => [VoiceConfig::ANSWER, VoiceConfig::EVENT], + 'voice' => [VoiceConfig::ANSWER, VoiceConfig::EVENT, VoiceConfig::FALLBACK_ANSWER_URL], 'messages' => [MessagesConfig::INBOUND, MessagesConfig::STATUS], 'rtc' => [RtcConfig::EVENT] ]; diff --git a/src/Application/VoiceConfig.php b/src/Application/VoiceConfig.php index b957b317..47a83a46 100644 --- a/src/Application/VoiceConfig.php +++ b/src/Application/VoiceConfig.php @@ -10,6 +10,8 @@ class VoiceConfig { public const EVENT = 'event_url'; public const ANSWER = 'answer_url'; + public const FALLBACK_ANSWER_URL = 'fallback_answer_url'; + protected ?bool $signedCallbacks = null; protected ?int $conversationsTtl = null; protected ?string $region = null; diff --git a/src/Application/Webhook.php b/src/Application/Webhook.php index 88ab3457..e8f488e2 100644 --- a/src/Application/Webhook.php +++ b/src/Application/Webhook.php @@ -8,9 +8,7 @@ class Webhook implements \Stringable { public const METHOD_POST = 'POST'; public const METHOD_GET = 'GET'; - public ?string $socketTimeout = null; - public ?string $connectionTimeout = null; public function __construct(protected ?string $url, protected ?string $method = self::METHOD_POST) diff --git a/test/Application/ClientTest.php b/test/Application/ClientTest.php index 29be21b3..bfc6979d 100644 --- a/test/Application/ClientTest.php +++ b/test/Application/ClientTest.php @@ -556,4 +556,17 @@ public function testCannotSetUnknownRegion(): void $application->setName('my application'); $application->getVoiceConfig()->setRegion('eu-west-1'); } + + public function testCanSetFallbackUrlWebhook(): void + { + $application = new Application(); + $application->setName('my application'); + $application->getVoiceConfig()->setRegion('eu-west'); + + $webhook = new Webhook('https://example.com/fallbackUrl', 'GET'); + $application->getVoiceConfig()->setWebhook(\Vonage\Application\VoiceConfig::FALLBACK_ANSWER_URL, $webhook); + + $output = $application->toArray(); + $this->assertEquals('https://example.com/fallbackUrl', $output['capabilities']['voice']['webhooks']['fallback_answer_url']['address']); + } } From 539e32f50fb46b475ca8e520aed5ab0f416bb46d Mon Sep 17 00:00:00 2001 From: Jim Seconde Date: Mon, 28 Oct 2024 13:38:19 +0000 Subject: [PATCH 2/2] move to correct location --- test/Application/ApplicationTest.php | 14 ++++++++++++++ test/Application/ClientTest.php | 13 ------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/test/Application/ApplicationTest.php b/test/Application/ApplicationTest.php index 7ad7b39d..d840886e 100644 --- a/test/Application/ApplicationTest.php +++ b/test/Application/ApplicationTest.php @@ -9,6 +9,7 @@ use Vonage\Application\MessagesConfig; use Vonage\Application\RtcConfig; use Vonage\Application\VoiceConfig; +use Vonage\Application\Webhook; use Vonage\Client\Exception\Exception as ClientException; use VonageTest\Traits\HTTPTestTrait; use VonageTest\VonageTestCase; @@ -164,4 +165,17 @@ public function testConfigCanBeCopied(): void $webhook = $otherapp->getVoiceConfig()->getWebhook(VoiceConfig::ANSWER); $this->assertEquals('https://example.com/webhooks/answer', $webhook); } + + public function testCanSetFallbackUrlWebhook(): void + { + $application = new Application(); + $application->setName('my application'); + $application->getVoiceConfig()->setRegion('eu-west'); + + $webhook = new Webhook('https://example.com/fallbackUrl', 'GET'); + $application->getVoiceConfig()->setWebhook(\Vonage\Application\VoiceConfig::FALLBACK_ANSWER_URL, $webhook); + + $output = $application->toArray(); + $this->assertEquals('https://example.com/fallbackUrl', $output['capabilities']['voice']['webhooks']['fallback_answer_url']['address']); + } } diff --git a/test/Application/ClientTest.php b/test/Application/ClientTest.php index bfc6979d..29be21b3 100644 --- a/test/Application/ClientTest.php +++ b/test/Application/ClientTest.php @@ -556,17 +556,4 @@ public function testCannotSetUnknownRegion(): void $application->setName('my application'); $application->getVoiceConfig()->setRegion('eu-west-1'); } - - public function testCanSetFallbackUrlWebhook(): void - { - $application = new Application(); - $application->setName('my application'); - $application->getVoiceConfig()->setRegion('eu-west'); - - $webhook = new Webhook('https://example.com/fallbackUrl', 'GET'); - $application->getVoiceConfig()->setWebhook(\Vonage\Application\VoiceConfig::FALLBACK_ANSWER_URL, $webhook); - - $output = $application->toArray(); - $this->assertEquals('https://example.com/fallbackUrl', $output['capabilities']['voice']['webhooks']['fallback_answer_url']['address']); - } }