Skip to content

[Notifier] Adds documentation for Slack stuff added in 5.3 #15364

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
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added _images/notifier/slack/message-reply.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _images/notifier/slack/slack-footer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _images/notifier/slack/slack-header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 114 additions & 0 deletions notifier/chatters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,120 @@ The result will be something like:

The `field()` method was introduced in Symfony 5.1.

Adding a header to a Slack Message
-------------------------------------------

To add a header to your message you can use the
:class:`Symfony\\Component\\Notifier\\Bridge\\Slack\\Block\\SlackHeaderBlock` class::

use Symfony\Component\Notifier\Bridge\Slack\Block\SlackDividerBlock;
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackHeaderBlock;
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
use Symfony\Component\Notifier\Message\ChatMessage;

$chatMessage = new ChatMessage('Symfony Feature');

$options = (new SlackOptions())
->block((new SlackHeaderBlock('My Header')))
->block((new SlackSectionBlock())->text('My message'))
->block(new SlackDividerBlock())
->block(
(new SlackSectionBlock())
->field('*Max Rating*')
->field('5.0')
->field('*Min Rating*')
->field('1.0')
);

// Add the custom options to the chat message and send the message
$chatMessage->options($options);

$chatter->send($chatMessage);

The result will be something like:

.. image:: /_images/notifier/slack/slack-header.png
:align: center

.. versionadded:: 5.3

The `SlackHeaderBlock` class was introduced in Symfony 5.3.

Adding a footer to a Slack Message
-------------------------------------------

To add a footer to your message you can use the
:class:`Symfony\\Component\\Notifier\\Bridge\\Slack\\Block\\SlackContextBlock` class::

use Symfony\Component\Notifier\Bridge\Slack\Block\SlackContextBlock;
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackDividerBlock;
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
use Symfony\Component\Notifier\Message\ChatMessage;

$chatMessage = new ChatMessage('Symfony Feature');

$contextBlock = (new SlackContextBlock())
->text('My Context')
->image('https://symfony.com/logos/symfony_white_03.png', 'Symfony Logo')
;

$options = (new SlackOptions())
->block((new SlackSectionBlock())->text('My message'))
->block(new SlackDividerBlock())
->block(
(new SlackSectionBlock())
->field('*Max Rating*')
->field('5.0')
->field('*Min Rating*')
->field('1.0')
)
->block($contextBlock)
;

$chatter->send($chatMessage);

The result will be something like:

.. image:: /_images/notifier/slack/slack-footer.png
:align: center

.. versionadded:: 5.3

The `SlackContextBlock` class was introduced in Symfony 5.3.

Sending a Slack Message as a reply
-------------------------------------------

To send your slack message as a reply in a thread you can use the
:method:`SlackOptions::threadTs() <Symfony\\Component\\Notifier\\Bridge\\Slack\\SlackOptions::threadTs>` method::

use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
use Symfony\Component\Notifier\Message\ChatMessage;

$chatMessage = new ChatMessage('Symfony Feature');

$options = (new SlackOptions())
->block((new SlackSectionBlock())->text('My reply'))
->threadTs('1621592155.003100')
;

// Add the custom options to the chat message and send the message
$chatMessage->options($options);

$chatter->send($chatMessage);

The result will be something like:

.. image:: /_images/notifier/slack/message-reply.png
:align: center

.. versionadded:: 5.3

The `threadTs()` method was introduced in Symfony 5.3.

Adding Interactions to a Discord Message
----------------------------------------

Expand Down