Skip to content

[Notifier] [FakeSms] Add the bridge #39949

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

Merged
merged 1 commit into from
Mar 29, 2021

Conversation

JamesHemery
Copy link
Contributor

Q A
Branch? 5.x
Bug fix? no
New feature? yes
Deprecations? no
License MIT
Doc PR symfony/symfony-docs#14870
Recipe PR symfony/recipes#882

@OskarStark Bridge added :)

@carsonbot carsonbot changed the title [Notifier][FakeSms] Add the bridge [Notifier] [FakeSms] Add the bridge Jan 23, 2021
@OskarStark
Copy link
Contributor

OskarStark commented Jan 23, 2021

I really like this bridge but I think we can do better.

I am thinking of using the same approach as in the mercure-notifier and provide a service id for the mailer which should be used.

Another thing which came to my mind: why not change ne name and scheme to "fake" only and support chat and sms?

Please let's discuss this first before changing some code and get some feedback of others about this idea 💡 thanks

@JamesHemery
Copy link
Contributor Author

I am thinking of using the same approach as in the mercure-notifier and provide a service id for the mailer which should be used.

@OskarStark Why using the service id instead of dependency injection from the constructor here ?

Another thing which came to my mind: why not change ne name and scheme to "fake" only and support chat and sms?

It's good idea, yes.

@nicolas-grekas nicolas-grekas added this to the 5.x milestone Jan 23, 2021
@@ -2236,6 +2237,7 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
AllMySmsTransportFactory::class => 'notifier.transport_factory.allmysms',
FirebaseTransportFactory::class => 'notifier.transport_factory.firebase',
FreeMobileTransportFactory::class => 'notifier.transport_factory.freemobile',
FakeSmsTransportFactory::class => 'notifier.transport_factory.fakesms',
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldnt this fake transport only be configured for dev env?

also i really like the idea of having a fake transport, i have a question; why to rely on a mailer mail? why not a monolog log?
they are displayed in console, they are displayed in profiler, they are stored in file and it does not need another software to be installed

could not found the related issue that lead to this PR :)
thank you

Copy link

@ke20 ke20 Jan 26, 2021

Choose a reason for hiding this comment

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

shouldnt this fake transport only be configured for dev env?

I agree with that too.

why to rely on a mailer mail? why not a monolog log?

IMOH, I think it's will great if we can choose the destination.

For example :

  • By email if the content contains a required information for the workflow (otp code)
  • By log if the content is just an information and have no importance
  • In a database or a redis to use that in functionnals testing and we should check or get information in the content message

What do you think ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@ke20 What do you think ?

I do not know the feature request/needs that initiate this PR, as written upper :)
But iiuc, the aim is to fake, in dev, the notifier sms logic to see if it works

I think that relying only on the mailer is overkill, a logger is enough => thus my previous comment :)

maybe yes a configured fake transport with multiple sublogic (log > mailer > database) can be the way, lets wait other reviews

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 agree, it would be interesting to be able to use other distribution channels. The packet was originally developed for the development of an otp system, important in the user workflow, so the choice of emails was made to facilitate testing.

Also, support of chat notifier would be a good thing.

I could do the integration of other channels in a few weeks, if anyone would like to contribute to this PR, feel free.

@tigitz
Copy link
Contributor

tigitz commented Feb 5, 2021

Maybe it has been discussed before but why not calling the bridge EmailNotifier instead ? And let developers use it for testing purposes or not.

The primary need of this bridge is to "Fake SMS" in dev, I get it, but it doesnt necessarily mean that you have to use Email to do that. You could "fake it" by writing in logs for example.

Also, a dedicated Email notifier could be useful in case where you have to notify both through SMS and Email while keeping the same kind of logic.

@JamesHemery
Copy link
Contributor Author

Maybe it has been discussed before but why not calling the bridge EmailNotifier instead ? And let developers use it for testing purposes or not.

The primary need of this bridge is to "Fake SMS" in dev, I get it, but it doesnt necessarily mean that you have to use Email to do that. You could "fake it" by writing in logs for example.

Also, a dedicated Email notifier could be useful in case where you have to notify both through SMS and Email while keeping the same kind of logic.

So, it's also an idea, but I think it would be more interesting to keep the name "FakeNotifier" and to add several channels (like emails, logs, ...). Because, except for tests, there is no reason to use SMS Notifier to finally send emails.

@OskarStark
Copy link
Contributor

Lets think a bit further, but I think my idea with the chat is not ideal, because they are not interchangeable because of the options, or we accept all options and add the json payload to the "log", "mail", or "database".

We can enable the recipe for dev, but also for test env 👍

Small recap
So we would end up with a symfony/fake-notifier for dev and test, with the following themes:

  • fakesms+mail should receive a mailer service id

  • fakesms+log should receive a logger service id + an optional channel ?? 🤔

  • fakesms+database should receive an entity manager service id ?? 🤔

  • fakechat+mail

  • fakechat+log

  • fakechat+database

And we end up with one Factory (like https://github.com/symfony/symfony/blob/5.x/src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesTransportFactory.php) and 6 transports

@OskarStark
Copy link
Contributor

OskarStark commented Mar 8, 2021

@JamesHemery open to go further? Do you agree with n ideas?

If you don't have to much time right now I think we can go with the mail only solution for now and add other ones later.

However to make it more clear I would name the scheme: fakesms+mail

@JamesHemery
Copy link
Contributor Author

Hi @OskarStark,

Yes I agree with these suggestions.

I will be doing the schema fix within a week.

@OskarStark
Copy link
Contributor

friendly ping @JamesHemery 😃

Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

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

Some minor

@JamesHemery
Copy link
Contributor Author

Some minor

I will make update tomorrow

Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

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

Last round of comments, afterwards I am going to merge this, thanks 👍

@OskarStark
Copy link
Contributor

@OskarStark OskarStark closed this Mar 29, 2021
@OskarStark OskarStark reopened this Mar 29, 2021
@Nyholm
Copy link
Member

Nyholm commented Mar 29, 2021

It is because of the weird logic in that method. I suggest rewriting it to something more similar to:

public function create(Dsn $dsn): TransportInterface
{
    if ('fakesms+email' !== $dsn->getScheme()) {
        throw new UnsupportedSchemeException($dsn, 'fakesms', $this->getSupportedSchemes());
    }
        
    $serviceId = $dsn->getHost();
    $to = $dsn->getRequiredOption('to');
    $from = $dsn->getRequiredOption('from');

    $factory = new FakeSmsEmailTransport($this->serviceProvider->get($serviceId), $to, $from);
    $factory->setHost($serviceId);

    return $factory;
}

@JamesHemery
Copy link
Contributor Author

It is because of the weird logic in that method. I suggest rewriting it to something more similar to:

public function create(Dsn $dsn): TransportInterface
    {
        if ('fakesms+email' !== $dsn->getScheme()) {
            throw new UnsupportedSchemeException($dsn, 'fakesms', $this->getSupportedSchemes());
        }
        
        $serviceId = $dsn->getHost();
        $to = $dsn->getRequiredOption('to');
        $from = $dsn->getRequiredOption('from');

        return (new FakeSmsEmailTransport($this->serviceProvider->get($serviceId), $to, $from))->setHost($serviceId);
    }

Yes, I think too. But this will need a rewrite when we will add new transport.

@Nyholm
Copy link
Member

Nyholm commented Mar 29, 2021

But this will need a rewrite when we will add new transport.

No (almost). It requires a rewrite when you add a new schema to this transport.

Im okey with that.

@Nyholm
Copy link
Member

Nyholm commented Mar 29, 2021

Or yes, A new transport to this FakeSmsFactory... still, Im okey with that.

@OskarStark
Copy link
Contributor

It took time, but here we go, this is in now. Thank you very much James.

@OskarStark OskarStark merged commit c14d189 into symfony:5.x Mar 29, 2021
@JamesHemery JamesHemery deleted the fakesms-notifier branch March 29, 2021 12:06
OskarStark added a commit to symfony/symfony-docs that referenced this pull request Mar 29, 2021
This PR was squashed before being merged into the 5.3-dev branch.

Discussion
----------

[Notifier] [FakeSms] Add the bridge

Docs for symfony/symfony#39949

Commits
-------

337e251 [Notifier] [FakeSms] Add the bridge
Nyholm added a commit that referenced this pull request Mar 29, 2021
This PR was merged into the 5.3-dev branch.

Discussion
----------

[Notifier] [FakeSms] Use correct namespace

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Follow #39949
| License       | MIT
| Doc PR        |

This fixes the build

Needed after #40550

Commits
-------

5572bab [Notifier] [FakeSms] Use correct namespace
Nyholm added a commit that referenced this pull request Mar 31, 2021
…karStark)

This PR was merged into the 5.3-dev branch.

Discussion
----------

[Notifier] [FakeSms] Change DSN to be more realistic

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Follows #39949
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Just a minor tests change

Commits
-------

0b13575 [Notifier] [FakeSms] Change DSN to be more realistic
OskarStark added a commit that referenced this pull request Apr 6, 2021
This PR was merged into the 5.3-dev branch.

Discussion
----------

[Notifier] [FakeChat] Added the bridge

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        | symfony/symfony-docs#15171
| Recipe PR     | todo

This PR is based on #39949 but for chat messages instead of SMS.

Commits
-------

0ce156c [Notifier] [FakeChat] Added the bridge
@fabpot fabpot mentioned this pull request Apr 18, 2021
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.

10 participants