Skip to content

[Notifier] Docs for Slack options field() method #15198

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
Apr 15, 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/field-method.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions notifier/chatters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,44 @@ to add some interactive options called `Block elements`_::

$chatter->send($chatMessage);

Adding Fields and Values to a Slack Message
-------------------------------------------

To add fields and values to your message you can use the
:method:`SlackSectionBlock::field() <Symfony\\Component\\Notifier\\Bridge\\Slack\\Block\\SlackSectionBlock::field>` method::

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');

$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')
);

// 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/field-method.png
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure an image is needed here ... the feature is easy to understand ... and this image will be outdated as soon as Slack makes any visual change in their app (which is common).

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 but decided to add it because its not clear "how" the are displayed, because you add them in procedural way but its rendered like "table"

If you want, feel free to remove it while merging

:align: center

.. versionadded:: 5.1

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

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

Expand Down