From 1551de729b8e0a23020788b4941d3467cae58d90 Mon Sep 17 00:00:00 2001 From: shimon Date: Tue, 1 Oct 2024 18:56:59 +0300 Subject: [PATCH 1/5] messaging adapter default values --- src/Appwrite/Platform/Workers/Messaging.php | 40 ++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index b0f05522fa..cf6a26cfea 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -489,11 +489,11 @@ class Messaging extends Action return match ($provider->getAttribute('provider')) { 'mock' => new Mock('username', 'password'), - 'twilio' => new Twilio($credentials['accountSid'], $credentials['authToken'], null, isset($credentials['messagingServiceSid']) ? $credentials['messagingServiceSid'] : null), - 'textmagic' => new TextMagic($credentials['username'], $credentials['apiKey']), - 'telesign' => new Telesign($credentials['customerId'], $credentials['apiKey']), - 'msg91' => new Msg91($credentials['senderId'], $credentials['authKey'], $credentials['templateId']), - 'vonage' => new Vonage($credentials['apiKey'], $credentials['apiSecret']), + 'twilio' => new Twilio($credentials['accountSid'] ?? 'accountSid' , $credentials['authToken'] ?? 'authToken', null, $credentials['messagingServiceSid'] ?? null), + 'textmagic' => new TextMagic($credentials['username'] ?? 'username', $credentials['apiKey'] ?? 'apiKey'), + 'telesign' => new Telesign($credentials['customerId'] ?? 'customerId', $credentials['apiKey'] ?? 'apiKey'), + 'msg91' => new Msg91($credentials['senderId'] ?? 'senderId', $credentials['authKey'] ?? 'authKey', $credentials['templateId'] ?? 'templateId'), + 'vonage' => new Vonage($credentials['apiKey'] ?? 'apiKey', $credentials['apiSecret'] ?? 'apiSecret'), default => null }; } @@ -506,11 +506,11 @@ class Messaging extends Action return match ($provider->getAttribute('provider')) { 'mock' => new Mock('username', 'password'), 'apns' => new APNS( - $credentials['authKey'], - $credentials['authKeyId'], - $credentials['teamId'], - $credentials['bundleId'], - $options['sandbox'] + $credentials['authKey'] ?? 'authKey', + $credentials['authKeyId'] ?? 'authKeyId', + $credentials['teamId'] ?? 'teamId', + $credentials['bundleId'] ?? 'bundleId', + $options['sandbox'] ?? false ), 'fcm' => new FCM(\json_encode($credentials['serviceAccountJSON'])), default => null @@ -525,18 +525,18 @@ class Messaging extends Action return match ($provider->getAttribute('provider')) { 'mock' => new Mock('username', 'password'), 'smtp' => new SMTP( - $credentials['host'], - $credentials['port'], - $credentials['username'], - $credentials['password'], - $options['encryption'], - $options['autoTLS'], - $options['mailer'], + $credentials['host'] ?? 'host', + $credentials['port'] ?? 25 , + $credentials['username'] ?? 'username', + $credentials['password'] ?? 'password', + $options['encryption'] ?? 'encryption', + $options['autoTLS'] ?? false, + $options['mailer'] ?? 'mailer', ), 'mailgun' => new Mailgun( - $credentials['apiKey'], - $credentials['domain'], - $credentials['isEuRegion'] + $credentials['apiKey'] ?? 'apiKey', + $credentials['domain'] ?? 'domain', + $credentials['isEuRegion'] ?? false ), 'sendgrid' => new Sendgrid($credentials['apiKey']), default => null From 2af4ef705d6e79c8561b796e8d4a5080932c7362 Mon Sep 17 00:00:00 2001 From: shimon Date: Tue, 1 Oct 2024 19:09:43 +0300 Subject: [PATCH 2/5] composer --- src/Appwrite/Platform/Workers/Messaging.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index cf6a26cfea..10f7142fd9 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -489,7 +489,7 @@ class Messaging extends Action return match ($provider->getAttribute('provider')) { 'mock' => new Mock('username', 'password'), - 'twilio' => new Twilio($credentials['accountSid'] ?? 'accountSid' , $credentials['authToken'] ?? 'authToken', null, $credentials['messagingServiceSid'] ?? null), + 'twilio' => new Twilio($credentials['accountSid'] ?? 'accountSid', $credentials['authToken'] ?? 'authToken', null, $credentials['messagingServiceSid'] ?? null), 'textmagic' => new TextMagic($credentials['username'] ?? 'username', $credentials['apiKey'] ?? 'apiKey'), 'telesign' => new Telesign($credentials['customerId'] ?? 'customerId', $credentials['apiKey'] ?? 'apiKey'), 'msg91' => new Msg91($credentials['senderId'] ?? 'senderId', $credentials['authKey'] ?? 'authKey', $credentials['templateId'] ?? 'templateId'), @@ -526,7 +526,7 @@ class Messaging extends Action 'mock' => new Mock('username', 'password'), 'smtp' => new SMTP( $credentials['host'] ?? 'host', - $credentials['port'] ?? 25 , + $credentials['port'] ?? 25, $credentials['username'] ?? 'username', $credentials['password'] ?? 'password', $options['encryption'] ?? 'encryption', From 3cb27d7b2ca66fbbfed6aff14d601929ef2becfb Mon Sep 17 00:00:00 2001 From: shimon Date: Tue, 1 Oct 2024 21:01:48 +0300 Subject: [PATCH 3/5] update validation --- src/Appwrite/Platform/Workers/Messaging.php | 51 ++++++++++++++------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index 10f7142fd9..aad3c2fd21 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -489,11 +489,29 @@ class Messaging extends Action return match ($provider->getAttribute('provider')) { 'mock' => new Mock('username', 'password'), - 'twilio' => new Twilio($credentials['accountSid'] ?? 'accountSid', $credentials['authToken'] ?? 'authToken', null, $credentials['messagingServiceSid'] ?? null), - 'textmagic' => new TextMagic($credentials['username'] ?? 'username', $credentials['apiKey'] ?? 'apiKey'), - 'telesign' => new Telesign($credentials['customerId'] ?? 'customerId', $credentials['apiKey'] ?? 'apiKey'), - 'msg91' => new Msg91($credentials['senderId'] ?? 'senderId', $credentials['authKey'] ?? 'authKey', $credentials['templateId'] ?? 'templateId'), - 'vonage' => new Vonage($credentials['apiKey'] ?? 'apiKey', $credentials['apiSecret'] ?? 'apiSecret'), + 'twilio' => new Twilio( + !empty($credentials['accountSid']) ? $credentials['accountSid'] : 'accountSid', + !empty($credentials['authToken']) ? $credentials['authToken'] : 'authToken', + null, + !empty($credentials['messagingServiceSid']) ? $credentials['messagingServiceSid'] : null + ), + 'textmagic' => new TextMagic( + !empty($credentials['username']) ? $credentials['username'] : 'username', + !empty($credentials['apiKey']) ? $credentials['apiKey'] : 'apiKey' + ), + 'telesign' => new Telesign( + !empty($credentials['customerId']) ? $credentials['customerId'] : 'customerId', + !empty($credentials['apiKey']) ? $credentials['apiKey'] : 'apiKey' + ), + 'msg91' => new Msg91( + !empty($credentials['senderId']) ? $credentials['senderId'] : 'senderId', + !empty($credentials['authKey']) ? $credentials['authKey'] : 'authKey', + !empty($credentials['templateId']) ? $credentials['templateId'] : 'templateId' + ), + 'vonage' => new Vonage( + !empty($credentials['apiKey']) ? $credentials['apiKey'] : 'apiKey', + !empty($credentials['apiSecret']) ? $credentials['apiSecret'] : 'apiSecret' + ), default => null }; } @@ -521,24 +539,25 @@ class Messaging extends Action { $credentials = $provider->getAttribute('credentials', []); $options = $provider->getAttribute('options', []); + $apiKey = !empty($credentials['apiKey']) ? $credentials['apiKey'] : 'apiKey'; return match ($provider->getAttribute('provider')) { 'mock' => new Mock('username', 'password'), 'smtp' => new SMTP( - $credentials['host'] ?? 'host', - $credentials['port'] ?? 25, - $credentials['username'] ?? 'username', - $credentials['password'] ?? 'password', - $options['encryption'] ?? 'encryption', - $options['autoTLS'] ?? false, - $options['mailer'] ?? 'mailer', + !empty($credentials['host']) ? $credentials['host'] : 'host', + !empty($credentials['port']) ? $credentials['port'] : 25, + !empty($credentials['username']) ? $credentials['username'] : 'username', + !empty($credentials['password']) ? $credentials['password'] : 'password', + !empty($options['encryption']) ? $options['encryption'] : 'encryption', + !empty($options['autoTLS']) ? $options['autoTLS'] : false, + !empty($options['mailer']) ? $options['mailer'] : 'mailer', ), 'mailgun' => new Mailgun( - $credentials['apiKey'] ?? 'apiKey', - $credentials['domain'] ?? 'domain', - $credentials['isEuRegion'] ?? false + $apiKey, + !empty($credentials['domain']) ? $credentials['domain'] : 'domain', + !empty($credentials['isEuRegion']) ?? false ), - 'sendgrid' => new Sendgrid($credentials['apiKey']), + 'sendgrid' => new Sendgrid($apiKey), default => null }; } From 32dbafa353f2f5fbd8ac0c5e2a4b4f04d8de2633 Mon Sep 17 00:00:00 2001 From: shimon Date: Tue, 1 Oct 2024 22:00:45 +0300 Subject: [PATCH 4/5] update validation --- src/Appwrite/Platform/Workers/Messaging.php | 50 ++++++++++----------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index aad3c2fd21..1f90c355b5 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -490,27 +490,27 @@ class Messaging extends Action return match ($provider->getAttribute('provider')) { 'mock' => new Mock('username', 'password'), 'twilio' => new Twilio( - !empty($credentials['accountSid']) ? $credentials['accountSid'] : 'accountSid', - !empty($credentials['authToken']) ? $credentials['authToken'] : 'authToken', + $credentials['accountSid'] ?? '', + $credentials['authToken'] ?? '', null, !empty($credentials['messagingServiceSid']) ? $credentials['messagingServiceSid'] : null ), 'textmagic' => new TextMagic( - !empty($credentials['username']) ? $credentials['username'] : 'username', - !empty($credentials['apiKey']) ? $credentials['apiKey'] : 'apiKey' + $credentials['username'] ?? '', + $credentials['apiKey'] ?? '' ), 'telesign' => new Telesign( - !empty($credentials['customerId']) ? $credentials['customerId'] : 'customerId', - !empty($credentials['apiKey']) ? $credentials['apiKey'] : 'apiKey' + $credentials['customerId'] ?? '', + $credentials['apiKey'] ?? '' ), 'msg91' => new Msg91( - !empty($credentials['senderId']) ? $credentials['senderId'] : 'senderId', - !empty($credentials['authKey']) ? $credentials['authKey'] : 'authKey', - !empty($credentials['templateId']) ? $credentials['templateId'] : 'templateId' + $credentials['senderId'] ?? '', + $credentials['authKey'] ?? '', + $credentials['templateId'] ?? '' ), 'vonage' => new Vonage( - !empty($credentials['apiKey']) ? $credentials['apiKey'] : 'apiKey', - !empty($credentials['apiSecret']) ? $credentials['apiSecret'] : 'apiSecret' + $credentials['apiKey'] ?? '', + $credentials['apiSecret'] ?? '' ), default => null }; @@ -524,10 +524,10 @@ class Messaging extends Action return match ($provider->getAttribute('provider')) { 'mock' => new Mock('username', 'password'), 'apns' => new APNS( - $credentials['authKey'] ?? 'authKey', - $credentials['authKeyId'] ?? 'authKeyId', - $credentials['teamId'] ?? 'teamId', - $credentials['bundleId'] ?? 'bundleId', + $credentials['authKey'] ?? '', + $credentials['authKeyId'] ?? '', + $credentials['teamId'] ?? '', + $credentials['bundleId'] ?? '', $options['sandbox'] ?? false ), 'fcm' => new FCM(\json_encode($credentials['serviceAccountJSON'])), @@ -539,23 +539,23 @@ class Messaging extends Action { $credentials = $provider->getAttribute('credentials', []); $options = $provider->getAttribute('options', []); - $apiKey = !empty($credentials['apiKey']) ? $credentials['apiKey'] : 'apiKey'; + $apiKey = $credentials['apiKey'] ?? ''; return match ($provider->getAttribute('provider')) { 'mock' => new Mock('username', 'password'), 'smtp' => new SMTP( - !empty($credentials['host']) ? $credentials['host'] : 'host', - !empty($credentials['port']) ? $credentials['port'] : 25, - !empty($credentials['username']) ? $credentials['username'] : 'username', - !empty($credentials['password']) ? $credentials['password'] : 'password', - !empty($options['encryption']) ? $options['encryption'] : 'encryption', - !empty($options['autoTLS']) ? $options['autoTLS'] : false, - !empty($options['mailer']) ? $options['mailer'] : 'mailer', + $credentials['host'] ?? '', + $credentials['port'] ?? 25, + $credentials['username'] ?? '', + $credentials['password'] ?? '', + $options['encryption'] ?? '', + $options['autoTLS'] ?? false, + $options['mailer'] ?? '', ), 'mailgun' => new Mailgun( $apiKey, - !empty($credentials['domain']) ? $credentials['domain'] : 'domain', - !empty($credentials['isEuRegion']) ?? false + $credentials['domain'] ?? '', + $credentials['isEuRegion'] ?? false ), 'sendgrid' => new Sendgrid($apiKey), default => null From 7e2fde3a0a8d41291c40e7499d57bd558f85e4ce Mon Sep 17 00:00:00 2001 From: shimon Date: Tue, 1 Oct 2024 22:53:08 +0300 Subject: [PATCH 5/5] update validation --- src/Appwrite/Platform/Workers/Messaging.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index 1f90c355b5..510fec0431 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -493,7 +493,7 @@ class Messaging extends Action $credentials['accountSid'] ?? '', $credentials['authToken'] ?? '', null, - !empty($credentials['messagingServiceSid']) ? $credentials['messagingServiceSid'] : null + $credentials['messagingServiceSid'] ?? null ), 'textmagic' => new TextMagic( $credentials['username'] ?? '',