Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed
wants to merge 21 commits into from
Closed

[Notifier] Add Orange SMS bridge #44884

wants to merge 21 commits into from

Conversation

enigma972
Copy link
Contributor

Q A
Branch? 5.4
Bug fix? no
New feature? yes
Deprecations? no
License MIT

Add Orange SMS bridge

@carsonbot
Copy link

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:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.1 branch.

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!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@OskarStark
Copy link
Contributor

Please target 6.1 branch


public function toStringProvider(): iterable
{
yield ['orangesms://default?from=FROM&sender_name=SENDER_NAME', $this->createTransport()];
Copy link
Contributor

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

Comment on lines 28 to 41
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);
}
Copy link
Member

@Kocal Kocal Jan 2, 2022

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?

Suggested change
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);
}

Copy link
Contributor

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

Copy link
Member

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.

Copy link
Member

@GromNaN GromNaN left a 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.


$url = 'https://'.$this->getEndpoint().'/smsmessaging/v1/outbound/'.urlencode('tel:'.$this->from).'/requests';
$headers = [
'Authorization' => 'Bearer '.$this->getAccessToken(),
Copy link
Member

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),
Copy link
Member

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

private string $clientID;
private string $clientSecret;
private string $from;
private string $senderName;
Copy link
Member

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);
Copy link
Member

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.

@stof
Copy link
Member

stof commented Jan 4, 2022

please also check the CI failures

@enigma972 enigma972 requested review from stof and OskarStark January 4, 2022 16:57
@OskarStark
Copy link
Contributor

Please rebase on 6.1 branch and target 6.1 afterwards, thanks

@enigma972
Copy link
Contributor Author

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
At #44913

@GromNaN GromNaN closed this Jan 5, 2022
fabpot added a commit that referenced this pull request Jan 17, 2022
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
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this pull request Jan 17, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants