Skip to content

Commit 394213c

Browse files
authored
Added ability to add a fallback URL on application (#519)
* Added ability to add a fallback URL * move to correct location
1 parent f912e98 commit 394213c

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<testsuite name="verify">
2424
<directory>test/Verify</directory>
2525
</testsuite>
26+
<testsuite name="application">
27+
<directory>test/Application</directory>
28+
</testsuite>
2629
<testsuite name="verify2">
2730
<directory>test/Verify2</directory>
2831
</testsuite>

src/Application/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public function toArray(): array
230230
{
231231
// Build up capabilities that are set
232232
$availableCapabilities = [
233-
'voice' => [VoiceConfig::ANSWER, VoiceConfig::EVENT],
233+
'voice' => [VoiceConfig::ANSWER, VoiceConfig::EVENT, VoiceConfig::FALLBACK_ANSWER_URL],
234234
'messages' => [MessagesConfig::INBOUND, MessagesConfig::STATUS],
235235
'rtc' => [RtcConfig::EVENT]
236236
];

src/Application/VoiceConfig.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class VoiceConfig
1010
{
1111
public const EVENT = 'event_url';
1212
public const ANSWER = 'answer_url';
13+
public const FALLBACK_ANSWER_URL = 'fallback_answer_url';
14+
1315
protected ?bool $signedCallbacks = null;
1416
protected ?int $conversationsTtl = null;
1517
protected ?string $region = null;

src/Application/Webhook.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ class Webhook implements \Stringable
88
{
99
public const METHOD_POST = 'POST';
1010
public const METHOD_GET = 'GET';
11-
1211
public ?string $socketTimeout = null;
13-
1412
public ?string $connectionTimeout = null;
1513

1614
public function __construct(protected ?string $url, protected ?string $method = self::METHOD_POST)

test/Application/ApplicationTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Vonage\Application\MessagesConfig;
1010
use Vonage\Application\RtcConfig;
1111
use Vonage\Application\VoiceConfig;
12+
use Vonage\Application\Webhook;
1213
use Vonage\Client\Exception\Exception as ClientException;
1314
use VonageTest\Traits\HTTPTestTrait;
1415
use VonageTest\VonageTestCase;
@@ -164,4 +165,17 @@ public function testConfigCanBeCopied(): void
164165
$webhook = $otherapp->getVoiceConfig()->getWebhook(VoiceConfig::ANSWER);
165166
$this->assertEquals('https://example.com/webhooks/answer', $webhook);
166167
}
168+
169+
public function testCanSetFallbackUrlWebhook(): void
170+
{
171+
$application = new Application();
172+
$application->setName('my application');
173+
$application->getVoiceConfig()->setRegion('eu-west');
174+
175+
$webhook = new Webhook('https://example.com/fallbackUrl', 'GET');
176+
$application->getVoiceConfig()->setWebhook(\Vonage\Application\VoiceConfig::FALLBACK_ANSWER_URL, $webhook);
177+
178+
$output = $application->toArray();
179+
$this->assertEquals('https://example.com/fallbackUrl', $output['capabilities']['voice']['webhooks']['fallback_answer_url']['address']);
180+
}
167181
}

0 commit comments

Comments
 (0)