Skip to content

Commit

Permalink
Added ability to add a fallback URL on application (#519)
Browse files Browse the repository at this point in the history
* Added ability to add a fallback URL

* move to correct location
  • Loading branch information
SecondeJK authored Oct 28, 2024
1 parent f912e98 commit 394213c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<testsuite name="verify">
<directory>test/Verify</directory>
</testsuite>
<testsuite name="application">
<directory>test/Application</directory>
</testsuite>
<testsuite name="verify2">
<directory>test/Verify2</directory>
</testsuite>
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
];
Expand Down
2 changes: 2 additions & 0 deletions src/Application/VoiceConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/Application/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions test/Application/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
}
}

0 comments on commit 394213c

Please sign in to comment.