Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages in full color showing how to combine Symfony with Docker, APIs, queues & async tasks, Webpack, Single-Page Applications, etc.

Buy printed version

How to send Chat Messages

5.1 version
Maintained Unmaintained

How to send Chat Messages

New in version 5.0: The Notifier component was introduced in Symfony 5.0 as an experimental feature.

The Symfony\Component\Notifier\ChatterInterface class allows you to send messages to chat services like Slack or Telegram:

// src/Controller/CheckoutController.php
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Notifier\ChatterInterface;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Routing\Annotation\Route;

class CheckoutController extends AbstractController
     * @Route("/checkout/thankyou")
    public function thankyou(ChatterInterface $chatter)
        $message = (new ChatMessage('You got a new invoice for 15 EUR.'))
            // if not set explicitly, the message is send to the
            // default transport (the first one configured)


        // ...

See also

Read the main Notifier guide to see how to configure the different transports.

Adding Interactions to a Slack Message

With a Slack message, you can use the Symfony\Component\Notifier\Bridge\Slack\SlackOptions to add some interactive options called Block elements:

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

$chatMessage = new ChatMessage('Contribute To Symfony');

// Create Slack Actions Block and add some buttons
$contributeToSymfonyBlocks = (new SlackActionsBlock())
        'Improve Documentation',
        'Report bugs',

$slackOptions = (new SlackOptions())
    ->block((new SlackSectionBlock())
        ->text('The Symfony Community')
            new SlackImageBlockElement(
    ->block(new SlackDividerBlock())

// Add the custom options to the chat message and send the message


This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.