Create Vonage phone auth adapter
This commit is contained in:
parent
648b6f2038
commit
f63c1c95fe
3 changed files with 46 additions and 0 deletions
|
@ -28,6 +28,7 @@ use Appwrite\Auth\Phone\Telesign;
|
||||||
use Appwrite\Auth\Phone\TextMagic;
|
use Appwrite\Auth\Phone\TextMagic;
|
||||||
use Appwrite\Auth\Phone\Twilio;
|
use Appwrite\Auth\Phone\Twilio;
|
||||||
use Appwrite\Auth\Phone\Msg91;
|
use Appwrite\Auth\Phone\Msg91;
|
||||||
|
use Appwrite\Auth\Phone\Vonage;
|
||||||
use Appwrite\DSN\DSN;
|
use Appwrite\DSN\DSN;
|
||||||
use Appwrite\Event\Audit;
|
use Appwrite\Event\Audit;
|
||||||
use Appwrite\Event\Database as EventDatabase;
|
use Appwrite\Event\Database as EventDatabase;
|
||||||
|
@ -992,6 +993,7 @@ App::setResource('phone', function () {
|
||||||
'text-magic' => new TextMagic($user, $secret),
|
'text-magic' => new TextMagic($user, $secret),
|
||||||
'telesign' => new Telesign($user, $secret),
|
'telesign' => new Telesign($user, $secret),
|
||||||
'msg91' => new Msg91($user, $secret),
|
'msg91' => new Msg91($user, $secret),
|
||||||
|
'vonage' => new Vonage($user, $secret),
|
||||||
default => null
|
default => null
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,6 +6,7 @@ use Appwrite\Auth\Phone\Telesign;
|
||||||
use Appwrite\Auth\Phone\TextMagic;
|
use Appwrite\Auth\Phone\TextMagic;
|
||||||
use Appwrite\Auth\Phone\Twilio;
|
use Appwrite\Auth\Phone\Twilio;
|
||||||
use Appwrite\Auth\Phone\Msg91;
|
use Appwrite\Auth\Phone\Msg91;
|
||||||
|
use Appwrite\Auth\Phone\Vonage;
|
||||||
use Appwrite\DSN\DSN;
|
use Appwrite\DSN\DSN;
|
||||||
use Appwrite\Resque\Worker;
|
use Appwrite\Resque\Worker;
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
|
@ -38,6 +39,7 @@ class MessagingV1 extends Worker
|
||||||
'text-magic' => new TextMagic($user, $secret),
|
'text-magic' => new TextMagic($user, $secret),
|
||||||
'telesign' => new Telesign($user, $secret),
|
'telesign' => new Telesign($user, $secret),
|
||||||
'msg91' => new Msg91($user, $secret),
|
'msg91' => new Msg91($user, $secret),
|
||||||
|
'vonage' => new Vonage($user, $secret),
|
||||||
default => null
|
default => null
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
42
src/Appwrite/Auth/Phone/Vonage.php
Normal file
42
src/Appwrite/Auth/Phone/Vonage.php
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\Auth\Phone;
|
||||||
|
|
||||||
|
use Appwrite\Auth\Phone;
|
||||||
|
|
||||||
|
// Reference Material
|
||||||
|
// https://dashboard.nexmo.com/getting-started/sms
|
||||||
|
|
||||||
|
class Vonage extends Phone
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private string $endpoint = 'https://rest.nexmo.com/sms/json';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $from
|
||||||
|
* @param string $to
|
||||||
|
* @param string $message
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
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(
|
||||||
|
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
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue