Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to add a fallback URL on application #519

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']);
}
}
Loading