-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Notifier] Add Orange SMS bridge #44884
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
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
Please target 6.1 branch |
src/Symfony/Component/Notifier/Bridge/OrangeSms/OrangeSmsTransport.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/OrangeSms/OrangeSmsTransportFactory.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/OrangeSms/OrangeSmsTransportFactory.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/OrangeSms/OrangeSmsTransport.php
Outdated
Show resolved
Hide resolved
|
||
public function toStringProvider(): iterable | ||
{ | ||
yield ['orangesms://default?from=FROM&sender_name=SENDER_NAME', $this->createTransport()]; |
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 missing, where Sender name is not set
private $clientID; | ||
private $clientSecret; | ||
private $from; | ||
private $senderName; | ||
|
||
public function __construct(string $clientID, string $clientSecret, string $from, ?string $senderName, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null) | ||
{ | ||
$this->clientID = $clientID; | ||
$this->clientSecret = $clientSecret; | ||
$this->from = $from; | ||
$this->senderName = $senderName; | ||
|
||
parent::__construct($client, $dispatcher); | ||
} |
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.
Since 6.1 is PHP 8 only, why not just use constructor property promotion?
private $clientID; | |
private $clientSecret; | |
private $from; | |
private $senderName; | |
public function __construct(string $clientID, string $clientSecret, string $from, ?string $senderName, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null) | |
{ | |
$this->clientID = $clientID; | |
$this->clientSecret = $clientSecret; | |
$this->from = $from; | |
$this->senderName = $senderName; | |
parent::__construct($client, $dispatcher); | |
} | |
public function __construct(private string $clientID, private string $clientSecret, private string $from, private ?string $senderName, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null) | |
{ | |
parent::__construct($client, $dispatcher); | |
} |
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.
Not sure Symfony uses it
Cc @symfony/mergers
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 don't see any reason not to use it in new code. But before, we have to be sure that PHP-CS-Fixer/fabbot is compatible.
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.
Nice addition.
After a rebase on branch 6.1, you can update the target of this PR.
src/Symfony/Component/Notifier/Bridge/OrangeSms/OrangeSmsTransport.php
Outdated
Show resolved
Hide resolved
|
||
$url = 'https://'.$this->getEndpoint().'/smsmessaging/v1/outbound/'.urlencode('tel:'.$this->from).'/requests'; | ||
$headers = [ | ||
'Authorization' => 'Bearer '.$this->getAccessToken(), |
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.
The access token should be cached and reused if several messages are sent. But that would require some expiration management for long running processes.
This is not blocking and could be handled in a future PR.
$url = 'https://'.$this->getEndpoint().'/oauth/v3/token'; | ||
$credentials = $this->clientID.':'.$this->clientSecret; | ||
$headers = [ | ||
'Authorization' => 'Basic '.base64_encode($credentials), |
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.
The HTTP client has the auth_basic
option for that.
https://symfony.com/doc/current/http_client.html#authentication
src/Symfony/Component/Notifier/Bridge/OrangeSms/OrangeSmsTransport.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/OrangeSms/OrangeSmsTransport.php
Outdated
Show resolved
Hide resolved
private string $clientID; | ||
private string $clientSecret; | ||
private string $from; | ||
private string $senderName; |
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.
this is wrong. The constructor will assign string|null
in this property
$errorMessage = $content['requestError']['serviceException']['messageId'] ?? ''; | ||
$errorInfo = $content['requestError']['serviceException']['text'] ?? ''; | ||
|
||
throw new TransportException(sprintf('Unable to send the SMS: '.$errorMessage.' (%s).', $errorInfo), $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.
concatenating the error message into the format string of sprintf
is a no-go, as it would require escaping %
in the error message to avoid breaking it.
please also check the CI failures |
Please rebase on 6.1 branch and target 6.1 afterwards, thanks |
By bad handling I deleted the fork, so I had to open another pull request |
This PR was squashed before being merged into the 6.1 branch. Discussion ---------- [Notifier] Add Orange SMS bridge | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | License | MIT Add Orange SMS bridge Previously [#44884](#44884) Commits ------- 1aebeaf [Notifier] Add Orange SMS bridge
This PR was squashed before being merged into the 6.1 branch. Discussion ---------- [Notifier] Add Orange SMS bridge | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | License | MIT Add Orange SMS bridge Previously [#44884](symfony/symfony#44884) Commits ------- 1aebeaf77c [Notifier] Add Orange SMS bridge
Add Orange SMS bridge