-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Notifier] add doc #12846
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
[Notifier] add doc #12846
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,174 @@ | ||||||
.. index:: | ||||||
single: Notifier | ||||||
single: Components; Notifier | ||||||
|
||||||
The Notifier Component | ||||||
==================== | ||||||
|
||||||
The Notifier component helps sending emails. | ||||||
|
||||||
If you're using the Symfony Framework, read the | ||||||
:doc:`Symfony Framework Notifier documentation </notifier>`. | ||||||
|
||||||
Installation | ||||||
------------ | ||||||
|
||||||
.. code-block:: terminal | ||||||
|
||||||
$ composer require symfony/notifier | ||||||
|
||||||
.. include:: /components/require_autoload.rst.inc | ||||||
|
||||||
----- | ||||||
|
||||||
The Notifier component has notify you when something goes wrong:: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
it can be you or someone else, that the devops or whomever |
||||||
|
||||||
use Symfony\Bridge\Twig\Mime\NotificationEmail; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. generaly the doc use to put such code in context, inside a controller or a service for example |
||||||
use Symfony\Component\Mailer\Mailer; | ||||||
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport; | ||||||
|
||||||
$transport = new EsmtpTransport('localhost'); | ||||||
$mailer = new Mailer($transport); | ||||||
|
||||||
$email = (new NotificationEmail()) | ||||||
->form('fabien@symfony.com') | ||||||
->to('fabien@symfony.com') | ||||||
->exception($exception); | ||||||
|
||||||
$mailer->send($email); | ||||||
|
||||||
The ``$email`` object is created via the :doc:`Mime component </components/mime>`. | ||||||
|
||||||
And configurable email template:: | ||||||
|
||||||
$email = (new NotificationEmail()) | ||||||
->htmlEmail('email/system.html.twig') | ||||||
->textEmail('email/system.txt.twig'); | ||||||
|
||||||
With template:: | ||||||
|
||||||
{% extends "@email/system.html.twig" %} | ||||||
{% block style %} | ||||||
{{ parent() }} | ||||||
.container.body_alert { | ||||||
border-top: 30px solid #ec5840; | ||||||
} | ||||||
{% endblock %} | ||||||
{% block lines %} | ||||||
This is an automated email for the MyApp application. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{{ parent() }} | ||||||
{% endblock %} | ||||||
{% block action %} | ||||||
{{ parent() }} | ||||||
<spacer size="16"></spacer> | ||||||
<button class="secondary" href="https://myapp.com/">Go to MyApp</button> | ||||||
{% endblock %} | ||||||
{% block exception %}{% endblock %} | ||||||
{% block footer_content %} | ||||||
<p><small>© MyApp</small></p> | ||||||
{% endblock %} | ||||||
|
||||||
|
||||||
SMS | ||||||
--------- | ||||||
|
||||||
Sending SMS Messages the easy way:: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SMS stands for Short Message Service
Suggested change
? |
||||||
|
||||||
/** | ||||||
* @Route("/checkout/thankyou") | ||||||
*/ | ||||||
public function thankyou(Texter $texter /* ... */) { | ||||||
$sms = new SmsMessage('+1415999888', 'Revenue has just increased by 1€ per year!'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need the |
||||||
$texter->send($sms); | ||||||
|
||||||
return $this->render('checkout/thankyou.html.twig', [ | ||||||
// ... | ||||||
]); | ||||||
} | ||||||
|
||||||
Below is the list of other popular provider with built-in support: | ||||||
|
||||||
================== | ||||||
Service | ||||||
================== | ||||||
Telegram | ||||||
Nexmo | ||||||
Slack | ||||||
Twilio | ||||||
================== | ||||||
|
||||||
SMS low-level API:: | ||||||
|
||||||
$sms = new SmsMessage('+1415999888', 'Revenue has just increased!'); | ||||||
$twilio = Transport::fromDsn('twilio://SID:TOKEN@default?from=FROM'); | ||||||
$twilio->send($sms); | ||||||
$nexmo = Transport::fromDsn('nexmo://KEY:SECRET@default?from=FROM'); | ||||||
$nexmo->send($sms); | ||||||
|
||||||
SMS... higher-level API:: | ||||||
|
||||||
$texter = new Texter($twilio, $bus); | ||||||
$texter->send($sms); | ||||||
$transports = new Transports(['twilio' => $twilio, 'nexmo' => $nexmo]); | ||||||
$texter = new Texter($transports, $bus); | ||||||
$texter->send($sms); | ||||||
$sms->setTransport('nexmo'); | ||||||
$texter->send($sms); | ||||||
$bus->dispatch($sms); | ||||||
|
||||||
$dsn = 'failover(twilio://SID:TOKEN@default?from=FROM nexmo://KEY:SECRET@default?from=FROM)'; | ||||||
|
||||||
Message | ||||||
--------- | ||||||
|
||||||
Sending Messages the easy way:: | ||||||
|
||||||
/** | ||||||
* @Route("/checkout/thankyou") | ||||||
*/ | ||||||
public function thankyou(Chatter $chatter /* ... */) | ||||||
{ | ||||||
$message = new ChatMessage('Revenue increased by 1€ per year...'); | ||||||
$chatter->send($message); | ||||||
return $this->render('checkout/thankyou.html.twig', [ | ||||||
// ... | ||||||
]); | ||||||
} | ||||||
|
||||||
Messages low-level API:: | ||||||
|
||||||
$message = new ChatMessage('Revenue increased by 1€ per year...'); | ||||||
$slack = Transport::fromDsn('slack://TOKEN@default?channel=CHANNEL'); | ||||||
$slack->send($sms); | ||||||
$telegram = Transport::fromDsn('telegram://TOKEN@default?channel=CHAT_ID'); | ||||||
$telegram->send($sms); | ||||||
|
||||||
Messages higher-level API:: | ||||||
|
||||||
$transports = Transport::fromDsns([ | ||||||
'slack' => 'slack://TOKEN@default?channel=CHANNEL', | ||||||
'telegram' => 'telegram://TOKEN@default?channel=CHAT_ID' | ||||||
]); | ||||||
$chatter = new Chatter($transports, $bus); | ||||||
$chatter->send($message); | ||||||
$message->setTransport('telegram'); | ||||||
$chatter->send($message); | ||||||
$bus->dispatch($message); | ||||||
|
||||||
$options = (new SlackOptions()) | ||||||
->iconEmoji('tada') | ||||||
->iconUrl('https://symfony.com') | ||||||
->username('SymfonyNext') | ||||||
->channel($channel) | ||||||
->block((new SlackSectionBlock())->text('Some Text')) | ||||||
->block(new SlackDividerBlock()) | ||||||
->block((new SlackSectionBlock()) | ||||||
->text('Some Text in another block') | ||||||
->accessory(new SlackImageBlockElement('http://placekitten.com/700/500', 'kitten')) | ||||||
) | ||||||
; | ||||||
$message = new ChatMessage('Default Text', $options); | ||||||
|
||||||
$dsn = 'all(slack://TOKEN@default?channel=CHANNEL telegram://TOKEN@default?channel=CHAT_ID)'; | ||||||
|
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.