> For the complete documentation index, see [llms.txt](https://docs.octoxlabs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.octoxlabs.com/action-center/slack/send-direct-message-to-a-user.md).

# Send Direct Message to a User

Posts a message to each selected user with Slack's `chat.postMessage` API, using the user's Slack ID as the channel, which opens a direct message. The message can be plain text, Markdown, blocks or attachments. It is the same text for every user. The users come from the assets the previous node collected.

### Before you begin

* A Slack API token: a bot token (`xoxb-`) with the scope `chat:write`, or, if you select **Send Direct Message as a User/Bot**, a user token (`xoxp-`) with `chat:write`. The form refuses the wrong token type. Enter it in **Slack API Token**.
* Asset type: **User** only (`allowed_asset_types` is `user`).
* Required column: `Specifics.slack.id`. Users whose Slack ID is empty are skipped without a message.
* Job defaults: Slack Domain, Slack API Token and the other fields can be saved as defaults for this job in [Action Center Settings](broken://pages/fa25776ab251a33bb2a7e69faf62f677f3b76280).

### Settings

| Setting                           | Type             | Required | Default     | Description                                                                                                                |
| --------------------------------- | ---------------- | -------- | ----------- | -------------------------------------------------------------------------------------------------------------------------- |
| Slack Domain                      | Text             | No       | `slack.com` | The Slack domain the requests are sent to. Requests go to `https://<domain>/api/...`.                                      |
| Slack API Token                   | Text             | Yes      | None        | Bot (`xoxb-`) or user (`xoxp-`) token with scope `chat:write`. Not masked after saving.                                    |
| Text                              | Text             | No       | None        | Plain text message, for example `Hello world`.                                                                             |
| Markdown text                     | Text             | No       | None        | Markdown formatted text, up to 12,000 characters, for example `**This is bold text**`. Do not combine with Text or Blocks. |
| Blocks                            | Long text (JSON) | No       | None        | A JSON array of Slack blocks, for example `[{"type": "section", "text": {"type": "plain_text", "text": "Hello world"}}]`.  |
| Attachments                       | Long text (JSON) | No       | None        | A JSON array of Slack attachments, for example `[{"pretext": "pre-hello", "text": "text-world"}]`.                         |
| Send Direct Message as a User/Bot | Checkbox         | No       | Off         | Select to send the message as the user instead of as a bot.                                                                |

### How it works

* Validation when you save the node: with the box selected the token must start with `xoxp-`; with it cleared the token must start with `xoxb-`. If Markdown text is set, Text and Blocks must be empty.
* At run time the job sends one `chat.postMessage` request per user, one after another, with whichever of Text, Markdown text, Blocks and Attachments you filled in. Users that have no value in `Specifics.slack.id` are filtered out before the job runs.
* If no user has a Slack ID, the job fails with `No Slack user IDs found in the selected users.` On the first Slack error the job fails with `Slack API send direct message to user error: <code>`; users messaged before that have already received it.
* Passes the same assets it received to the next node.

### Example

| Setting                           | Value                                                                                  |
| --------------------------------- | -------------------------------------------------------------------------------------- |
| Slack Domain                      | `slack.com`                                                                            |
| Slack API Token                   | `YOUR_SLACK_BOT_TOKEN` (starts with `xoxb-`)                                           |
| Text                              | `Your account was flagged by an OctoXLabs workflow. Please contact the security team.` |
| Send Direct Message as a User/Bot | Off                                                                                    |

### What's next?

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>About Action Center</strong></td><td>Workflows, triggers, conditions and job nodes.</td><td><a href="broken://pages/c53d026b9438b74e5c96c7a59bb6d75211026536">Broken link</a></td></tr><tr><td><strong>Action Center Settings</strong></td><td>Save default values for this job.</td><td><a href="broken://pages/fa25776ab251a33bb2a7e69faf62f677f3b76280">Broken link</a></td></tr><tr><td><strong>Send Notification (Slack)</strong></td><td>Post an asset summary to a Slack webhook.</td><td><a href="broken://pages/abddc604648c974485cefa2b90ddc124682b070a">Broken link</a></td></tr><tr><td><strong>Add Users to Channel</strong></td><td>Add users to a channel.</td><td><a href="broken://pages/4b971ea07e372bcb0ceb4ebf7e84410058a4a27d">Broken link</a></td></tr></tbody></table>

{% hint style="info" %}
Available starting from version 6.3.0.
{% endhint %}
