Skip to content

Slack notifier actions documentation #12963

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

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
Next Next commit
Slack notifier actions documentation
  • Loading branch information
savvasal committed Jan 20, 2020
commit 0014e28d4a1be25e7671d93650fb2b84ba12d0f2
41 changes: 41 additions & 0 deletions components/notifier.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,44 @@ Usage

We're still working on the docs of this component. Check this page again
in a few days.

Slack Actions Block for Slack Message
-------------------------------------

With a Slack Message you can add some interactive options called `Block elements`_::

use Symfony\Component\Notifier\Bridge\Slack\Block\SlackActionsBlock;
use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Chatter;
use Symfony\Component\Notifier\Bridge\Slack\SlackTransport;

// Initialize a chatter with Slack Transport
$chatter = new Chatter(new SlackTransport('token'));

// Create a message
$chatMessage = (new ChatMessage())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Parse the subject string at the constructor.
$chatMessage = new ChatMessage('Contribute to Symfony');

->subject('Contribute To Symfony');

// Create Slack Actions Block and add some buttons
$contributeToSymfonyBlocks = (new SlackActionsBlock())
->button(
'Improve Documentation',
'https://symfony.com/doc/current/contributing/documentation/standards.html',
'primary'
)
->button(
'Report bugs',
'https://symfony.com/doc/current/contributing/code/bugs.html',
'danger'
);
$contributeToSymfonyOptions = (new SlackOptions())->block($contributeToSymfonyBlocks);

// Add the Buttons as Options to the Message
$chatMessage->options($contributeToSymfonyOptions);

// And then send the Message
$chatter->send($chatMessage);


.. _`Block elements`: https://api.slack.com/reference/block-kit/block-elements