Skip to content
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

Add Notifier SentMessage #36611

Merged
merged 1 commit into from
Jun 23, 2020
Merged

Conversation

jeremyFreeAgent
Copy link
Contributor

@jeremyFreeAgent jeremyFreeAgent commented Apr 28, 2020

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets
License MIT
Doc PR symfony/symfony-docs#13624

Like Mailer, Notifier returns now a SentMessage that contains the messageId (returned by the provider in the response). It contains also the body of the response as array to have more info about price, number of sms sent, status and so on.

  • apply to bridges

@fabpot
Copy link
Member

fabpot commented May 3, 2020

Sounds good to me. @jeremyFreeAgent Can you finish the PR?

@jeremyFreeAgent
Copy link
Contributor Author

I have set uniqid() for transports that do not give back an identifier.

@@ -75,5 +76,9 @@ protected function doSend(MessageInterface $message): void

throw new TransportException(sprintf('Unable to send the SMS: error %d: ', $response->getStatusCode()).($errors[$response->getStatusCode()] ?? ''), $response);
}

$message = new SentMessage($message, uniqid());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would allow the id to be null instead of generating a random one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it from __construct then.

@@ -79,10 +80,18 @@ protected function doSend(MessageInterface $message): void
if (200 !== $response->getStatusCode()) {
$errorMessage = $jsonContents ? $jsonContents['results']['error'] : $response->getContent(false);

throw new TransportException(sprintf('Unable to post the Firebase message: %s.', $errorMessage), $response);
throw new TransportException(sprintf('Unable to post the Firebase message: "%s".', $errorMessage), $response);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes should be reverted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! (That was asked by fabbot.io)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


$message = new SentMessage($message);

return $message;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the $message object and return it directly.


$message = new SentMessage($message);
$message->setMessageId($success['messages'][0]['message-id']);
$message->setTransportResponseData($success);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing the returned result as is means that it is not standardized.
I would instead make it a bit more useful by defining a format with things that are common (including the transport name so that one can know how to parse the extra information) and add an entry with the original message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right.

The only real common thing is the message-id. The other data parts depend on :

  • the kind of message (chat or SMS)
  • the service (some returns cost for SMS, number of SMS sent for the message)

I think we can start with:

  • original message (in the construct)
  • transport __toString() (in the construct)
  • message-id (with setter if returned)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's not add anything "special" at first. For 5.1, let's be very generic. And I suppose that with me message-id and the transport, you have all the information you need to get more if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes exactly. Most of the services have webhook or API to get the other information parts.

Thanks.

@jeremyFreeAgent
Copy link
Contributor Author

jeremyFreeAgent commented May 6, 2020

Is it still relevant for 5.1?

@fabpot
Copy link
Member

fabpot commented May 6, 2020

Still relevant, but not for 5.1, I think we need more time to validate what we want.

@fabpot
Copy link
Member

fabpot commented Jun 9, 2020

@jeremyFreeAgent Can you update this PR with the latest discussion from the comments?

@jeremyFreeAgent jeremyFreeAgent force-pushed the notifier-sent-message branch 2 times, most recently from b6bd5bf to 048994c Compare June 13, 2020 09:00
@jeremyFreeAgent
Copy link
Contributor Author

rebased!

5.2.0
-----

* [BC BREAK] The `TransportExceptionInterface::send()` and `AbstractTransport::doSend()` methods changed to return a `SentMessage` instance instead of `void`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* [BC BREAK] The `TransportExceptionInterface::send()` and `AbstractTransport::doSend()` methods changed to return a `SentMessage` instance instead of `void`.
* [BC BREAK] The `TransportInterface::send()` and `AbstractTransport::doSend()` methods changed to return a `SentMessage` instance instead of `void`.

I guess that was a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @apfelbox ! Sorry I pushed the fix because in the GitHub iOS app I didn't saw that you use the suggestion feature.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha thx, don't worry 😄

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, minor comments to be fixed before merge. Thank you.

*
* @experimental in 5.2
*/
class SentMessage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be final.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad 🤦
Fixed.

{
private $original;
private $transport;
private $messageId = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= null is the default, so it can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -71,8 +69,8 @@ public function send(MessageInterface $message): void

if (!$this->transports[$transport]->supports($message)) {
throw new LogicException(sprintf('The "%s" transport does not support the given message.', $transport));
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's a wrong change here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is strange. It is a tab (I may have changed the file with another editor). I fix it. Good catch!

@fabpot
Copy link
Member

fabpot commented Jun 17, 2020

@jeremyFreeAgent Next step would be to fix the tests :)

@jeremyFreeAgent
Copy link
Contributor Author

Sorry I was working on something else at the same time. :trollface:

@fabpot
Copy link
Member

fabpot commented Jun 23, 2020

@jeremyFreeAgent Do you have time to have a look for the failing tests?

@jeremyFreeAgent
Copy link
Contributor Author

The tests are failing because the bridges require the 5.2 version of notifier which is not yet merged. What is the solution to make them pass?

@fabpot
Copy link
Member

fabpot commented Jun 23, 2020

The deps=low should pass. It looks like you forgot to update the composer.json file for FreeMobile.

@jeremyFreeAgent
Copy link
Contributor Author

OMG thanks @fabpot ♥️

@fabpot
Copy link
Member

fabpot commented Jun 23, 2020

Thank you @jeremyFreeAgent.

@fabpot fabpot merged commit ce8f8a5 into symfony:master Jun 23, 2020
@mbabker
Copy link
Contributor

mbabker commented Jun 23, 2020

Can the Messenger handler be made to return the SentMessage, similar to the Mailer's handler (#36424)?

@fabpot
Copy link
Member

fabpot commented Jun 24, 2020

@mbabker Sure, see #37403

fabpot added a commit that referenced this pull request Jun 24, 2020
…e handler (fabpot)

This PR was merged into the 5.2-dev branch.

Discussion
----------

[Notifier] Return SentMessage from the Notifier message handler

| Q             | A
| ------------- | ---
| Branch?       | master <!-- see below -->
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | see #36611 (comment) <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT
| Doc PR        |

Commits
-------

5855d11 [Notifier] Return SentMessage from the Notifier message handler
@mbabker
Copy link
Contributor

mbabker commented Jun 24, 2020

Thank you!

nicolas-grekas added a commit that referenced this pull request Jun 28, 2020
… (derrabus)

This PR was merged into the 5.1 branch.

Discussion
----------

[Notifier] Notifier 5.2 is incompatible with 5.1 bridges

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | N/A
| License       | MIT
| Doc PR        | N/A

#36611 introduced a breaking change that made the Notifier 5.2 incompatible with all Notifier bridges 5.0-5.1. Because of this, the tests are currently failing on Travis. This PR attempts to fix this.

Commits
-------

1b6bbc2 [Notifier] Notifier 5.2 is incompatible with 5.1 bridges.
fabpot added a commit that referenced this pull request Aug 6, 2020
This PR was merged into the 5.2-dev branch.

Discussion
----------

[Notifier] Fix SentMessage implementation

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | n/a <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
| Doc PR        | n/a

#36611 broke the Notifier when used with Messenger.

/cc @jeremyFreeAgent

Commits
-------

92c28de [Notifier] Fix SentMessage implementation
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.2 Oct 5, 2020
@fabpot fabpot mentioned this pull request Oct 5, 2020
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.

None yet

7 participants