From 7a486e1158d321aee40f5aa112db5ab90b4b26c1 Mon Sep 17 00:00:00 2001 From: Dineshkumar Date: Thu, 7 Jul 2022 16:40:29 +0530 Subject: [PATCH 1/6] Added Msg91 Flow Adapter --- app/workers/messaging.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/workers/messaging.php b/app/workers/messaging.php index 409304c595..79d99e2292 100644 --- a/app/workers/messaging.php +++ b/app/workers/messaging.php @@ -36,6 +36,7 @@ class MessagingV1 extends Worker 'twilio' => new Twilio($user, $secret), 'text-magic' => new TextMagic($user, $secret), 'telesign' => new Telesign($user, $secret), + 'msg91-flow' => new Msg91Flow($user, $secret), default => null }; From d2bf2f8f5aaaa656576d99161096ba1e3a243d4c Mon Sep 17 00:00:00 2001 From: Dineshkumar Date: Thu, 7 Jul 2022 16:41:50 +0530 Subject: [PATCH 2/6] Added Msg91 Adaptor Using Flow --- src/Appwrite/Auth/Phone/Msg91Flow.php | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/Appwrite/Auth/Phone/Msg91Flow.php diff --git a/src/Appwrite/Auth/Phone/Msg91Flow.php b/src/Appwrite/Auth/Phone/Msg91Flow.php new file mode 100644 index 0000000000..2ada52c406 --- /dev/null +++ b/src/Appwrite/Auth/Phone/Msg91Flow.php @@ -0,0 +1,46 @@ + utilized from for flow id + * @param string $to + * @param string $message + * @return void + */ + public function send(string $from, string $to, string $message): void + { + $to = ltrim($to, '+'); + $this->request( + method: 'POST', + url: $this->endpoint . '/messages', + payload: \http_build_query([ + 'sender' => $this->user, + 'otp' => $message, + 'flow_id' => $from, + 'mobiles' => $to + ]), + headers: [ + "content-type: application/JSON", + "authkey: {$this->secret}", + ] + ); + } +} From 5eab0d47e4a879ab4f482f5fa31f8fa1761bc16b Mon Sep 17 00:00:00 2001 From: Dineshkumar Date: Thu, 7 Jul 2022 20:57:48 +0530 Subject: [PATCH 3/6] renamed msg91-flow as msg91 --- app/workers/messaging.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/workers/messaging.php b/app/workers/messaging.php index 79d99e2292..d5e1b8a311 100644 --- a/app/workers/messaging.php +++ b/app/workers/messaging.php @@ -36,7 +36,7 @@ class MessagingV1 extends Worker 'twilio' => new Twilio($user, $secret), 'text-magic' => new TextMagic($user, $secret), 'telesign' => new Telesign($user, $secret), - 'msg91-flow' => new Msg91Flow($user, $secret), + 'msg91' => new Msg91Flow($user, $secret), default => null }; From b5b5abdc820dccb656c4a75d1de37c09e417ef0f Mon Sep 17 00:00:00 2001 From: Dineshkumar Date: Thu, 7 Jul 2022 20:59:34 +0530 Subject: [PATCH 4/6] Updated Functional Document Provider name as msg91 --- src/Appwrite/Auth/Phone/Msg91Flow.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Auth/Phone/Msg91Flow.php b/src/Appwrite/Auth/Phone/Msg91Flow.php index 2ada52c406..a3dac21b51 100644 --- a/src/Appwrite/Auth/Phone/Msg91Flow.php +++ b/src/Appwrite/Auth/Phone/Msg91Flow.php @@ -16,9 +16,9 @@ class Msg91Flow extends Phone /** * For Flow based sending SMS sender ID should not be set in flow - * In environment _APP_PHONE_PROVIDER format is 'phone://[senderID]:[authKey]@msg91-flow'. + * In environment _APP_PHONE_PROVIDER format is 'phone://[senderID]:[authKey]@msg91'. * _APP_PHONE_FROM value is flow ID created in Msg91 - * Eg. _APP_PHONE_PROVIDER = phone://DINESH:5e1e93cad6fc054d8e759a5b@msg91-flow + * Eg. _APP_PHONE_PROVIDER = phone://DINESH:5e1e93cad6fc054d8e759a5b@msg91 * _APP_PHONE_FROM = 3968636f704b303135323339 * @param string $from-> utilized from for flow id * @param string $to From 817524de4bcbcae2c2311e5ef7a4adb2f94ffd4f Mon Sep 17 00:00:00 2001 From: Dineshkumar Date: Sat, 9 Jul 2022 19:34:57 +0530 Subject: [PATCH 5/6] Renamed Msg91Flow to Msg91 --- app/init.php | 2 ++ app/workers/messaging.php | 3 ++- src/Appwrite/Auth/Phone/{Msg91Flow.php => Msg91.php} | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) rename src/Appwrite/Auth/Phone/{Msg91Flow.php => Msg91.php} (94%) diff --git a/app/init.php b/app/init.php index f2d8d63298..0861f67e7a 100644 --- a/app/init.php +++ b/app/init.php @@ -27,6 +27,7 @@ use Appwrite\Auth\Phone\Mock; use Appwrite\Auth\Phone\Telesign; use Appwrite\Auth\Phone\TextMagic; use Appwrite\Auth\Phone\Twilio; +use Appwrite\Auth\Phone\Msg91; use Appwrite\DSN\DSN; use Appwrite\Event\Audit; use Appwrite\Event\Database as EventDatabase; @@ -990,6 +991,7 @@ App::setResource('phone', function () { 'twilio' => new Twilio($user, $secret), 'text-magic' => new TextMagic($user, $secret), 'telesign' => new Telesign($user, $secret), + 'msg91' => new Msg91($user, $secret), default => null }; }); diff --git a/app/workers/messaging.php b/app/workers/messaging.php index d5e1b8a311..c83eaa2d7b 100644 --- a/app/workers/messaging.php +++ b/app/workers/messaging.php @@ -5,6 +5,7 @@ use Appwrite\Auth\Phone\Mock; use Appwrite\Auth\Phone\Telesign; use Appwrite\Auth\Phone\TextMagic; use Appwrite\Auth\Phone\Twilio; +use Appwrite\Auth\Phone\Msg91; use Appwrite\DSN\DSN; use Appwrite\Resque\Worker; use Utopia\App; @@ -36,7 +37,7 @@ class MessagingV1 extends Worker 'twilio' => new Twilio($user, $secret), 'text-magic' => new TextMagic($user, $secret), 'telesign' => new Telesign($user, $secret), - 'msg91' => new Msg91Flow($user, $secret), + 'msg91' => new Msg91($user, $secret), default => null }; diff --git a/src/Appwrite/Auth/Phone/Msg91Flow.php b/src/Appwrite/Auth/Phone/Msg91.php similarity index 94% rename from src/Appwrite/Auth/Phone/Msg91Flow.php rename to src/Appwrite/Auth/Phone/Msg91.php index a3dac21b51..8ae7c44665 100644 --- a/src/Appwrite/Auth/Phone/Msg91Flow.php +++ b/src/Appwrite/Auth/Phone/Msg91.php @@ -7,7 +7,7 @@ use Appwrite\Auth\Phone; // Reference Material // https://docs.msg91.com/p/tf9GTextN/e/Irz7-x1PK/MSG91 -class Msg91Flow extends Phone +class Msg91 extends Phone { /** * @var string @@ -30,7 +30,7 @@ class Msg91Flow extends Phone $to = ltrim($to, '+'); $this->request( method: 'POST', - url: $this->endpoint . '/messages', + url: $this->endpoint, payload: \http_build_query([ 'sender' => $this->user, 'otp' => $message, From 020bb160b9fe2cccac29874ca29d9a3566ad8691 Mon Sep 17 00:00:00 2001 From: Dineshkumar Date: Sat, 9 Jul 2022 20:12:48 +0530 Subject: [PATCH 6/6] changed payload encodings --- src/Appwrite/Auth/Phone/Msg91.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Auth/Phone/Msg91.php b/src/Appwrite/Auth/Phone/Msg91.php index 8ae7c44665..64e5973597 100644 --- a/src/Appwrite/Auth/Phone/Msg91.php +++ b/src/Appwrite/Auth/Phone/Msg91.php @@ -31,7 +31,7 @@ class Msg91 extends Phone $this->request( method: 'POST', url: $this->endpoint, - payload: \http_build_query([ + payload: json_encode([ 'sender' => $this->user, 'otp' => $message, 'flow_id' => $from,