From 8d51ff1a071fb8b98c7087217b239b7fad76915f Mon Sep 17 00:00:00 2001 From: Yechiel Date: Mon, 25 Nov 2024 15:19:13 -0500 Subject: [PATCH] webhook verification token --- .env.example | 2 ++ .github/workflows/run-tests.yml | 1 + README.md | 1 + config/ringcentral.php | 1 + src/RingCentral.php | 14 +++++++------- tests/Feature/RingCentralTest.php | 3 ++- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index 856e414..07e0196 100644 --- a/.env.example +++ b/.env.example @@ -2,6 +2,8 @@ RINGCENTRAL_CLIENT_ID= RINGCENTRAL_CLIENT_SECRET= RINGCENTRAL_SERVER_URL= RINGCENTRAL_JWT= +RINGCENTRAL_VERIFICATION_TOKEN= + #The below are only used for the test suite RINGCENTRAL_SENDER= RINGCENTRAL_RECEIVER= diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index b6d9e00..a195bec 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -60,6 +60,7 @@ jobs: RINGCENTRAL_CLIENT_SECRET: ${{ secrets.RINGCENTRAL_CLIENT_SECRET }} RINGCENTRAL_SERVER_URL: ${{ secrets.RINGCENTRAL_SERVER_URL }} RINGCENTRAL_JWT: ${{ secrets.RINGCENTRAL_JWT }} + RINGCENTRAL_VERIFICATION_TOKEN: ${{ secrets.RINGCENTRAL_VERIFICATION_TOKEN }} RINGCENTRAL_SENDER: ${{ secrets.RINGCENTRAL_SENDER }} RINGCENTRAL_RECEIVER: ${{ secrets.RINGCENTRAL_RECEIVER }} RINGCENTRAL_DELAY_REQUEST_SECONDS: ${{ secrets.RINGCENTRAL_DELAY_REQUEST_SECONDS }} diff --git a/README.md b/README.md index 6cafa38..6f0e0c2 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ RINGCENTRAL_CLIENT_ID=my_client_id RINGCENTRAL_CLIENT_SECRET=my_client_secret RINGCENTRAL_SERVER_URL=my_server_url RINGCENTRAL_JWT=my_jwt +RINGCENTRAL_VERIFICATION_TOKEN=my_verification_token ``` This package uses the JWT autentication method. You can learn more about setting up JWT for your RingCentral account [here](https://developers.ringcentral.com/guide/authentication/jwt/quick-start). diff --git a/config/ringcentral.php b/config/ringcentral.php index 925bba3..5e42d28 100644 --- a/config/ringcentral.php +++ b/config/ringcentral.php @@ -14,4 +14,5 @@ 'client_secret' => function_exists('env') ? env('RINGCENTRAL_CLIENT_SECRET', '') : '', 'server_url' => function_exists('env') ? env('RINGCENTRAL_SERVER_URL', '') : '', 'jwt' => function_exists('env') ? env('RINGCENTRAL_JWT', '') : '', + 'verification_token' => function_exists('env') ? env('RINGCENTRAL_VERIFICATION_TOKEN', '') : '', ]; diff --git a/src/RingCentral.php b/src/RingCentral.php index 88e2381..3823925 100644 --- a/src/RingCentral.php +++ b/src/RingCentral.php @@ -21,30 +21,32 @@ class RingCentral { protected string $clientId; protected string $clientSecret; protected string $jwt; + protected string $verification_token; protected string $loggedInExtension; protected string $loggedInExtensionId; public function setClientId(string $clientId): static { $this->clientId = $clientId; - return $this; } public function setClientSecret(string $clientSecret): static { $this->clientSecret = $clientSecret; - return $this; } public function setServerUrl(string $serverUrl): static { $this->serverUrl = $serverUrl; - return $this; } public function setjWT(string $jwt): static { $this->jwt = $jwt; + return $this; + } + public function setVerificationToken(string $verification_token): static { + $this->verification_token = $verification_token; return $this; } @@ -252,18 +254,16 @@ public function listWebhooks(): Collection { return $this->get('/subscription')->collect('records'); } - public function createWebhook(array $filters, int $expiresIn, string $address, ?string $verificationToken = null): Response { + public function createWebhook(array $filters, int $expiresIn, string $address): Response { $data = [ 'eventFilters' => $filters, 'expiresIn' => $expiresIn, 'deliveryMode' => [ 'transportType' => 'WebHook', 'address' => $address, + 'verificationToken' => $this->verification_token, ], ]; - if ($verificationToken) { - $data['deliveryMode']['verificationToken'] = $verificationToken; - } return $this->post('/subscription', $data); } diff --git a/tests/Feature/RingCentralTest.php b/tests/Feature/RingCentralTest.php index 698c187..0ba2bc3 100644 --- a/tests/Feature/RingCentralTest.php +++ b/tests/Feature/RingCentralTest.php @@ -22,7 +22,8 @@ protected function setUp(): void { ->setClientId(env('RINGCENTRAL_CLIENT_ID')) ->setClientSecret(env('RINGCENTRAL_CLIENT_SECRET')) ->setServerUrl(env('RINGCENTRAL_SERVER_URL')) - ->setJwt(env('RINGCENTRAL_JWT')); + ->setJwt(env('RINGCENTRAL_JWT')) + ->setVerificationToken(env('RINGCENTRAL_VERIFICATION_TOKEN')); $this->delay(); }