From f63c1c95fe0148ccebeca5755c77d32d669a7c3c Mon Sep 17 00:00:00 2001 From: Aditya Oberai Date: Tue, 12 Jul 2022 15:45:22 +0000 Subject: [PATCH 1/2] Create Vonage phone auth adapter --- app/init.php | 2 ++ app/workers/messaging.php | 2 ++ src/Appwrite/Auth/Phone/Vonage.php | 42 ++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 src/Appwrite/Auth/Phone/Vonage.php diff --git a/app/init.php b/app/init.php index 0861f67e7a..71407699b8 100644 --- a/app/init.php +++ b/app/init.php @@ -28,6 +28,7 @@ use Appwrite\Auth\Phone\Telesign; use Appwrite\Auth\Phone\TextMagic; use Appwrite\Auth\Phone\Twilio; use Appwrite\Auth\Phone\Msg91; +use Appwrite\Auth\Phone\Vonage; use Appwrite\DSN\DSN; use Appwrite\Event\Audit; use Appwrite\Event\Database as EventDatabase; @@ -992,6 +993,7 @@ App::setResource('phone', function () { 'text-magic' => new TextMagic($user, $secret), 'telesign' => new Telesign($user, $secret), 'msg91' => new Msg91($user, $secret), + 'vonage' => new Vonage($user, $secret), default => null }; }); diff --git a/app/workers/messaging.php b/app/workers/messaging.php index c83eaa2d7b..fd6eed6c22 100644 --- a/app/workers/messaging.php +++ b/app/workers/messaging.php @@ -6,6 +6,7 @@ use Appwrite\Auth\Phone\Telesign; use Appwrite\Auth\Phone\TextMagic; use Appwrite\Auth\Phone\Twilio; use Appwrite\Auth\Phone\Msg91; +use Appwrite\Auth\Phone\Vonage; use Appwrite\DSN\DSN; use Appwrite\Resque\Worker; use Utopia\App; @@ -38,6 +39,7 @@ class MessagingV1 extends Worker 'text-magic' => new TextMagic($user, $secret), 'telesign' => new Telesign($user, $secret), 'msg91' => new Msg91($user, $secret), + 'vonage' => new Vonage($user, $secret), default => null }; diff --git a/src/Appwrite/Auth/Phone/Vonage.php b/src/Appwrite/Auth/Phone/Vonage.php new file mode 100644 index 0000000000..bf95360b22 --- /dev/null +++ b/src/Appwrite/Auth/Phone/Vonage.php @@ -0,0 +1,42 @@ +request( + method: 'POST', + url: $this->endpoint, + headers: $headers, + payload: \http_build_query([ + 'text' => $message, + 'from' => $from, + 'to' => $to, + 'api_key' => $this->user, + 'api_secret' => $this->secret + ]) + ); + } +} From 313fd5582ae4c4fcba6a30f24e9a04d373a53aea Mon Sep 17 00:00:00 2001 From: Aditya Oberai <31401437+adityaoberai@users.noreply.github.com> Date: Tue, 12 Jul 2022 22:03:54 +0530 Subject: [PATCH 2/2] Set $from to use env variable + update ref link --- src/Appwrite/Auth/Phone/Vonage.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Appwrite/Auth/Phone/Vonage.php b/src/Appwrite/Auth/Phone/Vonage.php index bf95360b22..0a2c6dcbaa 100644 --- a/src/Appwrite/Auth/Phone/Vonage.php +++ b/src/Appwrite/Auth/Phone/Vonage.php @@ -5,7 +5,7 @@ namespace Appwrite\Auth\Phone; use Appwrite\Auth\Phone; // Reference Material -// https://dashboard.nexmo.com/getting-started/sms +// https://developer.vonage.com/api/sms class Vonage extends Phone { @@ -23,7 +23,6 @@ class Vonage extends Phone public function send(string $from, string $to, string $message): void { $to = ltrim($to, '+'); - $from = "Appwrite"; $headers = ['Content-Type: application/x-www-form-urlencoded']; $this->request(