> For the complete documentation index, see [llms.txt](https://learn.mechanic.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.mechanic.dev/core/actions/integrations/slack.md).

# Slack

The Slack action allows Mechanic to post messages to public and private channels in your Slack instance (as the Mechanic app bot or a customer username).

The Slack action provides a wrapper around HTTP calls to the [Slack Web API](https://docs.slack.dev/apis/web-api/). The various Slack API methods supported by this integration all share the same top-level structure in the action options.

## Options

<table><thead><tr><th width="182.33333333333334">Option</th><th width="88">Type</th><th>Description</th></tr></thead><tbody><tr><td>account</td><td>string</td><td>Required: the Slack account to use. Must match one of the Slack accounts linked in the Mechanic authentication settings.</td></tr><tr><td>method</td><td>string</td><td>Required: the HTTP verb as required by the Slack API for the specific method (e.g. "GET", "POST")</td></tr><tr><td>url_path</td><td>string</td><td>Required: the Slack API method (e.g. "/chat.postMessage")</td></tr><tr><td>headers</td><td>hash</td><td>Required: "Content-Type": "application/json"</td></tr><tr><td>body</td><td>hash</td><td>Required: the object that contains a JSON representation of the properties and content of the message</td></tr></tbody></table>

### Supported API Methods

Currently, these are the only Slack API methods supported by this integration.

* [chat.postMessage](https://docs.slack.dev/reference/methods/chat.postmessage)
* [chat.update](https://docs.slack.dev/reference/methods/chat.update/)
* [chat.delete](https://docs.slack.dev/reference/methods/chat.delete/)

## Authentication

This action requires installing the Mechanic Slack app in your Slack account with the appropriate permissions. To install the app:

1. Go to **Settings → Authentication**
2. Select **Slack** in the provider list
3. Install the Mechanic Slack app

## Examples

### Post a Simple Message

```liquid
{% action "slack" %}
  {
    "account": "SLACK_ACCOUNT_NAME",
    "method": "POST",
    "url_path": "/chat.postMessage",
    "headers": {
      "Content-Type": "application/json"
    },
    "body": {
      "channel": "CHANNEL_ID",
      "text": "Slack Example Message",
      "blocks": [
        {
          "type": "section",
          "text": {
            "type": "mrkdwn",
            "text": "Lorem ipsum dolor sit amet consectetur adipiscing elit."
          }
        }
      ]
    }
  }
{% endaction %}
```

### Post a Message with Custom Username and Icon

```liquid
{% action "slack" %}
  {
    "account": "SLACK_ACCOUNT_NAME",
    "method": "POST",
    "url_path": "/chat.postMessage",
    "headers": {
      "Content-Type": "application/json"
    },
    "body": {
      "username": "AiRobot",
      "icon_emoji": ":robot_face:",
      "channel": "CHANNEL_ID",
      "text": "Slack Example Message",
      "blocks": [
        {
          "type": "section",
          "text": {
            "type": "mrkdwn",
            "text": "Lorem ipsum dolor sit amet consectetur adipiscing elit."
          }
        }
      ]
    }
  }
{% endaction %}
```

## Action Response

The body of the action response will vary based on which Slack API method is called. Generally, the response is an object with the following structure (most fields removed for brevity). Running a Slack action task and reviewing the response is often the best way to see what will be returned in the body.

```json
{
  "type": "slack",
  "run": {
    "ok": true,
    "result": {
      "status": 200,
      "body": {
        ...
      }
    }
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://learn.mechanic.dev/core/actions/integrations/slack.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
