---
title: Slack actions
source: https://docs.newrelic.com/docs/workflow-automation/setup-and-configure/actions-catalog/slack/slack-chat
---

This page provides a comprehensive reference for slack chat actions available in the workflow automation actions catalog. These actions enable you to slack messaging operations.

## Prerequisites

Before using communication actions in workflow automation, ensure you have:

-   A Slack workspace with appropriate permissions.
-   A Slack bot token configured as a secret in workflow automation.
-   Access to the Slack channels where you want to send messages.

## Configure Slack integration [#slack-configuration]

This section details the instructions for setting up a Slack application with the minimal scope permissions to allow the workflow automation Slack actions.

### Create a Slack app

1.  Go to the [Slack API](https://api.slack.com/apps) > **Create New App > From Scratch**
2.  Give your app a name and select a workspace, then click **Create App**.
3.  Upon creating, go to **App Home** on the left navigation and ensure your bot is online.

    ![The Slack App Home page with the My Bot online status highlighted.](https://docs.newrelic.com/images/my-bot-always-online.webp "Always show My Bot as Online")

### Configure OAuth permissions

1.  On the left navigation, select **OAuth & Permissions**.

2.  Scroll down to the **Bot Token Scopes** section, and add the following scopes to allow the workflow automation action usages:

    -   `chat:write` - Required to post a message
    -   `reactions:read` - Required to get reaction from a thread
    -   `files:write` - Required to upload a file attachment to a thread

        ![The image of the scope that needs to be added for workflow automation Slack actions.](https://docs.newrelic.com/images/slack-workflow-scopes.webp "Workflow automation Slack scopes")

3.  Scroll back up and click the **Install to [workspace]** button to start the OAuth setup with your Slack workspace.

4.  You should see a confirmation prompt. Click **Allow** to confirm.

5.  Upon success, copy the **Bot token** and keep it for the next step. The token should start with `xoxb-...`.

### Add app to channels

Now that the Slack app is created and configured, add it to the Slack channel(s) you'd like to use by editing that channel's **Integrations** and adding the Slack app to it.

### New Relic configuration

Once you've set up a Slack application and obtained a bot token, store this credential in New Relic secrets management using the GraphQL mutation below:

```graphql
mutation {
  secretsManagementCreateSecret(
    scope: {type: ACCOUNT id: "12345678"}
    namespace: "slack"
    key: "my-app-bot-token"
    description: "A slack token to send messages with newrelic workflow automation"
    value: "xoxb-..."
  ) {
    key
  }
}
```

Configure the following values:

-   `id` - Your New Relic account ID
-   `namespace` - Optional, use any alphanumeric string to categorize your secret
-   `key` - Use an alphanumeric string for referencing this secret
-   `description` - Optional description for the secret
-   `value` - The Slack bot token you copied from the previous step

You can execute this mutation using the [NerdGraph GraphiQL explorer](https://one.newrelic.com/nerdgraph-graphiql) with your New Relic user API key. Once submitted successfully, you should see a result similar to this:

```json
{
  "data": {
    "secretsManagementCreateSecret": {
      "key": "my-app-bot-token"
    }
  }
}
```

### Use the Slack token in workflows

Use the workflow automation feature by leveraging the Slack bot token secret stored with your namespace and key names.

**Example:**

```yaml
name: to-slack

steps:
  - name: postCsv
    type: action
    action: slack.chat.postMessage
    version: 1
    inputs:
      channel: test-channel-workflow
      text: "Hello World!"
      token: ${{ :secrets:slack:my-app-bot-token }}
```

> #### 💡 TIP
>
> If you didn't use a namespace, remove the `:namespace` part from the token input, like this: `${{ :secrets:my-app-bot-token }}`

## Slack actions

**Send message**

Sends a message to a slack channel, with an optional file attachment.

### Inputs

| Input Field             | Optionality | Type   | Description                                                                                                                                                                 | Example                                                                                                                   |
| ----------------------- | ----------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| **token**               | Required    | Secret | The Slack bot token to use. This should be passed as a secret syntax. Refer to [Add Slack configuration](#slack-configuration) for instructions on setting up a token.      | `${{ :secrets:slackToken }}`                                                                                              |
| **channel**             | Required    | String | The name of the channel, or a channelID, to send the message. See [Slack API](https://docs.slack.dev/reference/methods/chat.postMessage/#arg_channel) for more information. | `my-slack-channel`                                                                                                        |
| **text**                | Required    | String | The message to be posted to Slack in the specified `channel`.                                                                                                               | `Hello World!`                                                                                                            |
| **threadTs**            | Optional    | String | Timestamp belonging to parent message, used to create a message reply in a thread.                                                                                          | `<digits>.<digits>`                                                                                                       |
| **attachment**          | Optional    | Map    | Allows attaching a file with a message onto the specified `channel`.                                                                                                        |                                                                                                                           |
| **attachment.filename** | Required    | String | Specify the filename for the uploaded file in Slack.                                                                                                                        | `file.txt`                                                                                                                |
| **attachment.content**  | Required    | String | The content of the file to upload as UTF8.                                                                                                                                  | `Hello\nWorld!`                                                                                                           |
| **selectors**           | Optional    | List   | The selectors to get the only specified parameters as output.                                                                                                               | `[{\"name\": \"threadTs\", \"expression\": \".threadTs\"}, {\"name\": \"channelID\", \"expression\": \".channelID\")\"}]` |

### Outputs

| Output Field     | Type    | Description                                                                                             | Example             |
| ---------------- | ------- | ------------------------------------------------------------------------------------------------------- | ------------------- |
| **threadTs**     | String  | Timestamp of the message thread. May be used in future `postMessage` calls to post a reply in a thread. | `<digits>.<digits>` |
| **channelID**    | String  | Id of the channel where message is posted.                                                              | `<string>`          |
| **success**      | Boolean | Status of the request                                                                                   | `true / false`      |
| **errorMessage** | String  | Failure reason as message                                                                               | `<string>`          |

### Example

**Example 1: Send slack message**

| Workflow example                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ```yaml name: SendMessage  steps:   - name: send_slack_message     type: action     action: slack.chat.postMessage      version: 1     inputs:       token: ${{ :secrets:dn_staging_slack_token }}       channel: ${{ .workflowInputs.channel }}       text: ${{ .workflowInputs.text }}       selectors:         - name: threadTs           expression: ".threadTs"         - name: channelID           expression: ".channelID" ``` **Inputs:** ```json {   "inputs": [     {       "key" : "channel",       "value" : "test-channel-workflow"     },     {       "key" : "text",       "value" : "This is my message *with bold text* and `code backticks`"     }   ] } ``` **Expected output:** ```json [   {     "threadTs": "1718897637.400609",     "channelID": "C063JK1RHN1"     "success": true   } ] ``` |

**Example 2: Attach a file**

| Workflow example                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ```yaml name: SendFileMessage  steps:    - name: postCsv     type: action     action: slack.chat.postMessage     version: 1     inputs:       token: ${{ :secrets:dn_staging_slack_token }}       channel: test-channel-workflow       text: "Please find the attached file:"       attachment:         filename: 'file.txt'         content: "Hello\nWorld!" ``` **Expected output:** ```json [   {     "threadTs": "1718897637.400609",     "channelID": "C063JK1RHN1"     "success": true   } ] ``` |

**Get message reactions**

Get a reaction of a message from Slack channel.

### Inputs

| Input Field   | Optionality | Type   | Description                                                                                                                                                            | Example                                                        |
| ------------- | ----------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| **token**     | Required    | Secret | The Slack bot token to use. This should be passed as a secret syntax. Refer to [Add Slack configuration](#slack-configuration) for instructions on setting up a token. | `${{ :secrets:slackToken }}`                                   |
| **channelID** | Required    | String | The channelID, to get the message reactions. See [`reactions.get` method](https://docs.slack.dev/reference/methods/reactions.get/#arg_channel)                         | `C063JK1RHN1`                                                  |
| **timeout**   | Optional    | Int    | The time in seconds for how long to wait for any reaction. Default is 60s, maximum allowed is 600s (10min).                                                            | 60                                                             |
| **threadTs**  | Required    | String | Timestamp belonging to message, used to get reaction of that message.                                                                                                  | `<digits>.<digits>`                                            |
| **selectors** | Optional    | List   | The selectors to get the only specified parameters as output.                                                                                                          | `[{\"name\": \"reactions\", \"expression\": \".reactions \"}]` |

### Outputs

| Output Field     | Type    | Description                                                                            | Example               |
| ---------------- | ------- | -------------------------------------------------------------------------------------- | --------------------- |
| **reactions**    | List    | List of elements with all the reactions captured or an empty list if timeout occurred. | `<list>`              |
| **success**      | Boolean | Status of the request                                                                  | `true / false`        |
| **errorMessage** | String  | Failure reason as message                                                              | `Invalid slack token` |

### Example

**Example 1: Slack get reactions**

| Workflow example                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ```yaml name: GetReactions  steps:     - name: getReactions     type: action     action: slack.chat.getReactions     version: 1     inputs:       token: ${{ :secrets:dn_staging_slack_token }}       channelID: ${{ .steps.promptUser.outputs.channelID }}       threadTs: ${{ .steps.promptUser.outputs.threadTs }}       timeout: ${{ .workflowInputs.timeout }}       selectors: ${{ .workflowInputs.selectors }} ``` **Inputs:** ```json {   "inputs": [     {       "key" : "channelID",       "value" : "C063JK1RHN1"     },     {       "key" : "threadTs",       "value" : "1718897637.400609"     },     {       "key" : "selectors",       "value" : "[{\"name\": \"reactions\", \"expression\": \".reactions \"}]"     }   ] } ``` **Outputs:** ```json [             {                 "name": "grinning",                 "users": [                     "W222222"                 ],                 "count": 1             },             {                 "name": "question",                 "users": [                     "W333333"                 ],                 "count": 1             }         ]  or if it is timed out, [] ``` |
