0Pricing
AI Agents · Lesson

Sending Messages and Rich Blocks

Plain text, markdown, Block Kit JSON — formatting Slack messages.

Simple Text Messages with say()

The simplest way to post a Slack message is say(text). The text supports mrkdwn — Slack's markdown variant. Use *bold*, _italic_, ~strike~, `code`, and mentions like <@USERID>.

@app.event('app_mention')
def handle_mention(event, say):
    user = event['user']

    # Simple text response with mrkdwn formatting
    say(
        text=(
            f'Hello <@{user}>!\n'
            '*Agent Report:*\n'
            '- Tasks completed: `42`\n'
            '- Errors: `0`\n'
            '- _Runtime: 3.2 seconds_'
        ),
        mrkdwn=True  # enabled by default
    )

    # Slack mentions
    say(f'<@{user}> your request is being processed')
    say('Posting to <!channel>: all hands meeting tomorrow')

Introduction to Block Kit

Block Kit is Slack's UI framework for building rich, interactive messages. Instead of plain text, you compose messages from typed blocks: section, header, divider, actions, context. Blocks are passed as a list to the blocks parameter of say() or chat_postMessage().

@app.event('app_mention')
def handle_mention(event, say):
    blocks = [
        {
            'type': 'header',
            'text': {'type': 'plain_text', 'text': 'Agent Status Report'}
        },
        {
            'type': 'divider'
        },
        {
            'type': 'section',
            'text': {
                'type': 'mrkdwn',
                'text': '*Status:* Running\n*Tasks:* 42 completed'
            }
        }
    ]

    say(
        text='Agent Status Report',  # fallback for notifications
        blocks=blocks
    )

All lessons in this course

  1. Slack Bolt SDK Basics
  2. Listening to Events and Slash Commands
  3. Sending Messages and Rich Blocks
  4. Building a Team Notification Bot
← Back to AI Agents