-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Notifier] Add SmsBiuras notifier bridge #40691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test option should be optional in the DSN.
The argument in the Transport should not be optional:
bool $test
src/Symfony/Component/Notifier/Bridge/SmsBiuras/SmsBiurasTransport.php
Outdated
Show resolved
Hide resolved
$from = $dsn->getRequiredOption('from'); | ||
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost(); | ||
$port = $dsn->getPort(); | ||
$test = $dsn->getRequiredOption('test'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move below the from and make it optional by using:
$test = $dsn->getOption('test', false)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/Symfony/Component/Notifier/Bridge/SmsBiuras/SmsBiurasTransport.php
Outdated
Show resolved
Hide resolved
'message' => $message->getSubject(), | ||
'from' => $this->from, | ||
'to' => $message->getPhone(), | ||
'test' => $this->test, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$test ? 0 : 1;
If Test is a bool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/Symfony/Component/Notifier/Bridge/SmsBiuras/Tests/SmsBiurasTransportFactoryTest.php
Outdated
Show resolved
Hide resolved
TODO: #40696 |
src/Symfony/Component/Notifier/Bridge/SmsBiuras/SmsBiurasTransport.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/SmsBiuras/SmsBiurasTransport.php
Outdated
Show resolved
Hide resolved
|
||
where: | ||
- `UID` is your client code | ||
- `TOKEN` is your SmsBiuras token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message); | ||
} | ||
|
||
$endpoint = 'https://'.$this->getEndpoint().'/api?'.http_build_query([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use $response = $this->client->request('GET', $endpoint, ['query' => [....]])
instead of building the URL
|
||
$matches = []; | ||
if (preg_match('/^ERROR: (\d+)$/', $response->getContent(), $matches)) { | ||
throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg(2 == \count($matches) ? $matches[1] : 999), $response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
===
everywhere
|
||
$matches = []; | ||
if (preg_match('/^ERROR: (\d+)$/', $response->getContent(), $matches)) { | ||
throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg(2 == \count($matches) ? $matches[1] : 999), $response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-2 == \count($matches) ? $matches[1] : 999
+$matches[1] ?? 999
return $sentMessage; | ||
} | ||
|
||
throw new TransportException('Unable to send the SMS: Service Unavailable.', $response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Service Unavailable
You don't know it. I'd use Unable to send the SMS.
There has been some recent changes in the CI flow that will be good for this PR. Could I ask you to rebase this PR please? |
@Nyholm made rebase, but see now too much commits. |
<<<<<<< HEAD | ||
MicrosoftTeamsTransport::class, | ||
======= | ||
SmsBiurasTransportFactory::class, | ||
>>>>>>> faebf2ce75... * Transport.php - smsbiuras |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the conflict
@@ -132,6 +132,10 @@ class UnsupportedSchemeException extends LogicException | |||
'class' => Bridge\MicrosoftTeams\MicrosoftTeamsTransportFactory::class, | |||
'package' => 'symfony/microsoft-teams-notifier', | |||
], | |||
'smsbiuras' => [ | |||
'class' => Bridge\SmsBiuras\SmsBiurasTransportFactory::class, | |||
'package' => 'symfony/smsbiuras-notifier', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'package' => 'symfony/smsbiuras-notifier', | |
'package' => 'symfony/sms-biuras-notifier', |
please rename the package name like this, thanks
Finally return "home" to the good branch 👍 Do I need to make something with license headers? :) |
*/ | ||
public function createTransport(?HttpClientInterface $client = null): TransportInterface | ||
{ | ||
return new SmsBiurasTransport('uid', 'api_key', 'from', 1, $client ?: $this->createMock(HttpClientInterface::class)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return new SmsBiurasTransport('uid', 'api_key', 'from', 1, $client ?: $this->createMock(HttpClientInterface::class)); | |
return new SmsBiurasTransport('uid', 'api_key', 'from', 1, $client ?? $this->createMock(HttpClientInterface::class)); |
CHANGELOG file is missing |
|
||
$matches = []; | ||
if (preg_match('/^ERROR: (\d+)$/', $response->getContent(), $matches)) { | ||
throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg(2 === $matches[1] ?? 999), $response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg(2 === $matches[1] ?? 999), $response); | |
throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg($matches[1] ?? 999), $response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UP
$uid = $this->getUser($dsn); | ||
$apiKey = $this->getPassword($dsn); | ||
$from = $dsn->getRequiredOption('from'); | ||
$test = $dsn->getOption('test', false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the option is provided by DSN, you'll get a string.
You should explicitly convert it to boolean with something like
filter_var($dsn->getOption('test', false), \FILTER_VALIDATE_BOOLEAN)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not quite happy how we activate the test mode via DSN. Any other idea @jderusse ?
Anyway I would propose to rename it to "test_mode"
Any maybe use "on" and "off" for toggeling instead of magic/Boolean numbers?
$matches = []; | ||
if (preg_match('/^OK: (\d+)$/', $response->getContent(), $matches)) { | ||
$sentMessage = new SentMessage($message, (string) $this); | ||
$sentMessage->setMessageId(2 === \count($matches) ? $matches[1] : 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$sentMessage->setMessageId(2 === \count($matches) ? $matches[1] : 0); | |
$sentMessage->setMessageId($matches[1] ?? 0); |
Tried to solve weird commit :) |
private $uid; | ||
private $apiKey; | ||
private $from; | ||
private $test; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename $test
to testMode
and test
to test_mode
in the DSN
src/Symfony/Component/Notifier/Bridge/SmsBiuras/SmsBiurasTransport.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/SmsBiuras/Tests/SmsBiurasTransportTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/SmsBiuras/Tests/SmsBiurasTransportFactoryTest.php
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except the 2 === $matches[1] ?? 999
@jderusse fixed. Thanks ;) |
It took time, but here we go, this is in now. Thank you very much Vasilij. |
Sms Biuras notifier bridge