# Block Kit Messages

Roam supports a subset of Slack's [Block Kit](https://api.slack.com/block-kit) for sending rich, structured messages via the [`chat.post`](/docs/api/chat-post) API endpoint. Block Kit lets you compose messages with headers, formatted text sections, buttons, dividers, and contextual metadata — going beyond plain markdown.

Block Kit messages sent via `chat.post` are also returned by [`chat.history`](/docs/api/chat-history), with the same `blocks` and `color` fields.

:::info
Roam implements a focused subset of Slack's Block Kit. You can prototype your layouts in Slack's [Block Kit Builder](https://app.slack.com/block-kit-builder) — just be aware that only the block types listed below are supported.
:::

## Quick Example

```bash
curl -X POST https://api.ro.am/v1/chat.post \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "chatId": "757dfe66-37b4-4772-baa5-8c86ec68c176",
    "blocks": [
      {
        "type": "header",
        "text": { "type": "plain_text", "text": "Deployment Complete" }
      },
      {
        "type": "section",
        "text": {
          "type": "mrkdwn",
          "text": "Service **api-gateway** deployed to production.\nVersion: `v2.4.1`"
        }
      },
      {
        "type": "context",
        "elements": [
          { "type": "mrkdwn", "text": "Deployed by @rob · 2 minutes ago" }
        ]
      }
    ],
    "color": "good"
  }'
```

<!-- SCREENSHOT: basic-block-kit.png
Send the following JSON via chat.post to a test chat, then screenshot the rendered message in Roam:
{
  "chat": "CHAT_ID",
  "blocks": [
    {
      "type": "header",
      "text": { "type": "plain_text", "text": "Deployment Complete" }
    },
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "Service **api-gateway** deployed to production.\nVersion: `v2.4.1`"
      }
    },
    {
      "type": "context",
      "elements": [
        { "type": "mrkdwn", "text": "Deployed by @rob · 2 minutes ago" }
      ]
    }
  ],
  "color": "good"
}
-->

<div style={{border: "1px solid #ccc", borderRadius: "8px", padding: "20px 20px 0 20px", display: "inline-block"}}>
  ![Basic Block Kit message](/img/block-kit/basic-block-kit.png)
</div>

## Supported Block Types

| Block Type | Description | Key Fields |
|-----------|-------------|------------|
| `header` | Large bold heading | `text` (plain_text only) |
| `section` | Text block with optional button | `text` (plain_text or mrkdwn), optional `accessory` |
| `context` | Small metadata text | `elements` (array of text objects) |
| `divider` | Horizontal rule | _(none)_ |
| `actions` | Row of interactive buttons | `elements` (array of 1–8 buttons) |

### Header

Displays a large, bold text heading. Only supports `plain_text` (no markdown formatting).

```json
{
  "type": "header",
  "text": { "type": "plain_text", "text": "Weekly Status Report" }
}
```

### Section

The primary content block. Supports both `plain_text` and `mrkdwn` text, and can include an optional button `accessory` displayed to the right of the text.

```json
{
  "type": "section",
  "text": {
    "type": "mrkdwn",
    "text": "*Pull Request #482*\n`feature/user-onboarding` → `main`\n3 files changed, 47 insertions(+)"
  },
  "accessory": {
    "type": "button",
    "text": { "type": "plain_text", "text": "View PR" },
    "url": "https://github.com/example/repo/pull/482"
  }
}
```

<!-- SCREENSHOT: section-with-button.png
Send the following JSON via chat.post, then screenshot the rendered message:
{
  "chat": "CHAT_ID",
  "blocks": [
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "*Pull Request #482*\n`feature/user-onboarding` → `main`\n3 files changed, 47 insertions(+)"
      },
      "accessory": {
        "type": "button",
        "text": { "type": "plain_text", "text": "View PR" },
        "url": "https://github.com/example/repo/pull/482"
      }
    }
  ]
}
-->

<div style={{border: "1px solid #ccc", borderRadius: "8px", padding: "20px 20px 0 20px", display: "inline-block"}}>
  ![Section with button accessory](/img/block-kit/section-with-button.png)
</div>

### Context

Displays small supplementary text, useful for metadata like timestamps, authors, or status indicators. Contains an array of text objects.

```json
{
  "type": "context",
  "elements": [
    { "type": "mrkdwn", "text": "Approved by **@alice**" },
    { "type": "plain_text", "text": "Updated 5 min ago" }
  ]
}
```

### Divider

A simple horizontal rule to visually separate content. No additional fields.

```json
{ "type": "divider" }
```

### Actions

A row of up to 8 buttons. See [Buttons](#buttons) below for the two button types (URL and interactive).

```json
{
  "type": "actions",
  "elements": [
    {
      "type": "button",
      "text": { "type": "plain_text", "text": "Approve" },
      "action_id": "deploy_approve",
      "value": "v2.4.1",
      "style": "primary"
    },
    {
      "type": "button",
      "text": { "type": "plain_text", "text": "Reject" },
      "action_id": "deploy_reject",
      "value": "v2.4.1",
      "style": "danger"
    },
    {
      "type": "button",
      "text": { "type": "plain_text", "text": "View Logs" },
      "url": "https://monitoring.example.com/deploys/v2.4.1"
    }
  ]
}
```

<!-- SCREENSHOT: actions-buttons.png
Send the following JSON via chat.post, then screenshot the rendered message:
{
  "chat": "CHAT_ID",
  "blocks": [
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "*Incident #1234*: API latency above 500ms"
      }
    },
    {
      "type": "actions",
      "elements": [
        {
          "type": "button",
          "text": { "type": "plain_text", "text": "Acknowledge" },
          "action_id": "incident_ack",
          "value": "1234",
          "style": "primary"
        },
        {
          "type": "button",
          "text": { "type": "plain_text", "text": "Escalate" },
          "action_id": "incident_escalate",
          "value": "1234",
          "style": "danger"
        },
        {
          "type": "button",
          "text": { "type": "plain_text", "text": "View Dashboard" },
          "url": "https://monitoring.example.com/incidents/1234"
        }
      ]
    }
  ]
}
-->

<div style={{border: "1px solid #ccc", borderRadius: "8px", padding: "20px 20px 0 20px", display: "inline-block"}}>
  ![Actions block with buttons](/img/block-kit/actions-buttons.png)
</div>

## Text Objects

Blocks use text objects to hold content. There are two types:

| Type | Formatting | Used In |
|------|-----------|---------|
| `plain_text` | No formatting, rendered as-is | All blocks and button labels |
| `mrkdwn` | **GitHub-flavored markdown** (same dialect as `chat.post` `text`). The type name is Block Kit structural legacy — the dialect is **not** Slack mrkdwn. | `section`, `context` |

```json
{ "type": "plain_text", "text": "Simple text" }
```

```json
{ "type": "mrkdwn", "text": "**Bold** and *italic* with `code`" }
```

:::warning Not Slack mrkdwn
Roam does **not** parse Slack's mrkdwn dialect. Use GFM everywhere (top-level
`text` and `mrkdwn` block text):

- Bold: `**bold**` (Slack `*bold*` renders as *italic* in Roam)
- Italic: `*italic*` or `_italic_`
- Strike: `~~strike~~` (not Slack `~strike~`)
- Code: `` `code` ``

The Block Kit type is still called `mrkdwn` for structural parity with Slack's
builder; only the **type name** is shared, not the markup dialect.
:::

Note: `header` blocks and button `text` fields only accept `plain_text`.

## Buttons

Buttons can appear in `actions` blocks or as a `section` accessory. Every button must have one of two behaviors:

### URL Buttons

Include a `url` field. Clicking opens the URL in a new browser tab. No server-side callback is made.

```json
{
  "type": "button",
  "text": { "type": "plain_text", "text": "Open Dashboard" },
  "url": "https://example.com/dashboard"
}
```

### Interactive Buttons

Include `action_id` and `value` fields (no `url`). When a user clicks the button, Roam sends a POST request to your app's [Interactivity URL](#interactivity).

```json
{
  "type": "button",
  "text": { "type": "plain_text", "text": "Approve" },
  "action_id": "approve_request",
  "value": "req-42",
  "style": "primary"
}
```

:::note
Interactive buttons require your app to have an **Interactivity URL** configured. If you send a message with interactive buttons and no Interactivity URL is set, the API returns a `400` error.
:::

### Button Styles

| Style | Appearance |
|-------|-----------|
| _(none)_ | Default neutral style |
| `"primary"` | Green, for confirmations and primary actions |
| `"danger"` | Red, for destructive or critical actions |

<!-- SCREENSHOT: button-styles.png
Send the following JSON via chat.post, then screenshot the rendered message:
{
  "chat": "CHAT_ID",
  "blocks": [
    {
      "type": "actions",
      "elements": [
        {
          "type": "button",
          "text": { "type": "plain_text", "text": "Default" },
          "action_id": "btn_default",
          "value": "default"
        },
        {
          "type": "button",
          "text": { "type": "plain_text", "text": "Primary" },
          "action_id": "btn_primary",
          "value": "primary",
          "style": "primary"
        },
        {
          "type": "button",
          "text": { "type": "plain_text", "text": "Danger" },
          "action_id": "btn_danger",
          "value": "danger",
          "style": "danger"
        }
      ]
    }
  ]
}
-->

<div style={{border: "1px solid #ccc", borderRadius: "8px", padding: "20px 20px 0 20px", display: "inline-block"}}>
  ![Button styles](/img/block-kit/button-styles.png)
</div>

## Color

Roam supports a top-level `color` field on Block Kit messages. This renders as a colored vertical strip on the left side of the message — useful for indicating status at a glance.

This is a Roam extension. In Slack, color is an attachments feature and not available directly on Block Kit messages.

| Value | Color |
|-------|-------|
| `"good"` | Green |
| `"warning"` | Yellow / amber |
| `"danger"` | Red |
| `"#RRGGBB"` | Any hex color (e.g. `"#5B3FD9"`) |

```bash
curl -X POST https://api.ro.am/v1/chat.post \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "chatId": "757dfe66-37b4-4772-baa5-8c86ec68c176",
    "blocks": [
      {
        "type": "section",
        "text": { "type": "mrkdwn", "text": "Build succeeded" }
      }
    ],
    "color": "good"
  }'
```

<!-- SCREENSHOT: color-variants.png
Send three separate messages via chat.post to the same chat, then screenshot them together in one image:

Message 1 (good):
{
  "chat": "CHAT_ID",
  "blocks": [
    { "type": "section", "text": { "type": "mrkdwn", "text": "Build succeeded :white_check_mark:" } }
  ],
  "color": "good"
}

Message 2 (warning):
{
  "chat": "CHAT_ID",
  "blocks": [
    { "type": "section", "text": { "type": "mrkdwn", "text": "Disk usage at 85% :warning:" } }
  ],
  "color": "warning"
}

Message 3 (danger):
{
  "chat": "CHAT_ID",
  "blocks": [
    { "type": "section", "text": { "type": "mrkdwn", "text": "Service outage detected :x:" } }
  ],
  "color": "danger"
}
-->

<div style={{border: "1px solid #ccc", borderRadius: "8px", padding: "20px 20px 0 20px", display: "inline-block"}}>
  ![Color variants](/img/block-kit/color-variants.png)
</div>

## Interactivity

When a user clicks an [interactive button](#interactive-buttons), Roam sends a POST request to your app's **Interactivity URL** with details about the action.

### Setup

1. In **Roam Administration > Developer**, open your API client's settings.
2. Under **Interactivity URL**, click **Add Interactivity URL**.
3. Enter a publicly accessible HTTPS endpoint (e.g. `https://example.com/roam/interactivity`).
4. Save the configuration.

:::note
The interactivity URL is also the URL for [App Actions](/docs/guides/app-actions).
Modal events share `type: "block_actions"` but carry a `viewId` instead of `clientId`.
:::

### Payload

When a button is clicked, Roam sends a `POST` request with a JSON body:

```json
{
  "type": "block_actions",
  "clientId": "your-client-id",
  "user": {
    "id": "ad1e9cc0-0ffd-47e5-895c-2630a73327b4",
    "email": "alice@example.com"
  },
  "message": {
    "chatId": "295155ae-7df5-4ed5-9ebc-89a170559c81",
    "timestamp": 1765602474760032,
    "threadTimestamp": 1765602400000000
  },
  "blockId": "actions-1",
  "actionId": "approve_request",
  "value": "req-42"
}
```

| Field | Type | Description |
|-------|------|-------------|
| `type` | string | Always `"block_actions"` |
| `clientId` | string | Your API client ID |
| `user` | object | The user who clicked the button |
| `user.id` | string | User ID |
| `user.email` | string | Verified email address of the user |
| `message` | object | The message containing the button |
| `message.chatId` | string | Chat where the button was clicked |
| `message.timestamp` | integer | Timestamp (Unix microseconds) of the message containing the button |
| `message.threadTimestamp` | integer | Thread timestamp. Omitted if the message is not part of a thread. |
| `blockId` | string | ID of the block containing the button |
| `actionId` | string | The `action_id` from the button definition |
| `value` | string | The `value` from the button definition |

### Request Signing

Interactivity requests are signed using the same [Standard Webhooks](https://github.com/standard-webhooks/standard-webhooks) mechanism as [webhook deliveries](/docs/webhooks/webhooks#signature-verification). Your **Webhook Signing Secret** from the API Client settings is used to sign interactivity requests. See the webhook documentation for verification code examples.

### Timeout and Error Handling

Your endpoint must respond within **3 seconds**. If your action requires longer processing, acknowledge the request immediately and process asynchronously.

| Scenario | What the user sees |
|----------|-------------------|
| 2xx response | Button is marked as clicked |
| Response takes > 3 seconds | "App didn't respond in time" |
| Connection error | "App didn't respond" |
| Non-2xx response | "App returned an error" |

## Limits

| Constraint | Limit |
|-----------|-------|
| Maximum blocks per message | 10 |
| Maximum total payload size | 8,000 bytes |
| Maximum buttons per `actions` block | 8 |
| Mutual exclusivity | `blocks` cannot be combined with `text` or `items` |

## Complete Example

Here's a realistic deploy approval notification using multiple block types, both button types, and a color strip:

```bash
curl -X POST https://api.ro.am/v1/chat.post \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "chatId": "757dfe66-37b4-4772-baa5-8c86ec68c176",
    "blocks": [
      {
        "type": "header",
        "text": { "type": "plain_text", "text": "Deploy Request: api-gateway v2.4.1" }
      },
      {
        "type": "section",
        "text": {
          "type": "mrkdwn",
          "text": "**Environment:** Production\n**Branch:** `main`\n**Commit:** `a1b2c3d` — Fix rate limiting edge case"
        },
        "accessory": {
          "type": "button",
          "text": { "type": "plain_text", "text": "View Diff" },
          "url": "https://github.com/example/api-gateway/compare/v2.4.0...v2.4.1"
        }
      },
      { "type": "divider" },
      {
        "type": "context",
        "elements": [
          { "type": "mrkdwn", "text": "Requested by **@alice** · All CI checks passing" }
        ]
      },
      {
        "type": "actions",
        "elements": [
          {
            "type": "button",
            "text": { "type": "plain_text", "text": "Approve" },
            "action_id": "deploy_approve",
            "value": "api-gateway-v2.4.1",
            "style": "primary"
          },
          {
            "type": "button",
            "text": { "type": "plain_text", "text": "Reject" },
            "action_id": "deploy_reject",
            "value": "api-gateway-v2.4.1",
            "style": "danger"
          }
        ]
      }
    ],
    "color": "#5B3FD9"
  }'
```

<!-- SCREENSHOT: complete-example.png
Send the JSON above (from the curl command) via chat.post to a test chat, then screenshot the rendered message in Roam. This should show:
- Purple color strip on the left (#5B3FD9)
- "Deploy Request: api-gateway v2.4.1" header
- Section with deploy details and "View Diff" URL button on the right
- Divider line
- Context line with requester and CI status
- Two action buttons: green "Approve" and red "Reject"
-->

<div style={{border: "1px solid #ccc", borderRadius: "8px", padding: "20px 20px 0 20px", display: "inline-block"}}>
  ![Complete Block Kit example](/img/block-kit/complete-example.png)
</div>