# Start a workflow from Slack interactivity

> Run a workflow when someone presses a button, uses a shortcut, or submits a modal of your Slack app, with a Webhook block set to Slack interactivity.

To run a workflow when someone presses a button in one of your Slack app's messages, picks from a menu, uses a shortcut, or submits a modal, add a **Webhook** block whose **Source** is **Slack interactivity** and give its URL to the app as its interactivity Request URL. Slack posts one request per interaction. Each request starts its own run.

This source receives interactions only. The events Slack reports through its Events API, such as a message or a reaction, go to a different URL setting in the Slack app and to a block of their own: [start a workflow from Slack events](https://outwin.ai/docs/build/connect-an-api/start-a-workflow-from-slack-events/). Slash commands go to a third: [start a workflow from Slack slash commands](https://outwin.ai/docs/build/connect-an-api/start-a-workflow-from-slack-slash-commands/). Use one block and one URL for each kind.

Slack expects an answer to an interaction within about three seconds, and what the answer holds can change what the person sees. A workflow cannot write it, because a run starts after the answer is sent. OutWin answers every interaction at once with an empty reply, which shows the person nothing. This source has no **Reply** setting. What the workflow has to say comes afterward, from an HTTP request block.

You need a Slack app whose settings you can open, edit access to the workflow's project, and the member role or higher in the workspace to save the app's secret on a connection. The Slack steps happen in the Slack app's own settings pages.

## Add the Webhook block and generate its URL

1. In a draft workflow, add a **Webhook** block. The block palette also lists **Slack interactivity webhook** in the **Start** group, which adds the block with its source already set.
2. Under **Source**, choose **Slack interactivity**. The line under the setting reads "Verifies the signature · one run per event · skips duplicates".
3. Under **Webhook URL**, select **Generate URL**, then copy the URL.

The badge beside the URL reads "Runs start after publish". The URL contains a token, and anyone who has the URL can send requests to it. Keep it out of shared documents.

## Give the URL to your Slack app

An app has one interactivity Request URL, and every interaction of the app goes to it. It is not the Request URL on the app's event subscriptions page, and it is not the Request URL of a slash command.

1. In your Slack app's settings, select **Interactivity & Shortcuts**.
2. Turn **Interactivity** on.
3. Paste the URL you copied into **Request URL**, and save.

The Webhook block offers these interaction types: `block_actions`, `shortcut`, `message_action`, `view_submission`, `view_closed`, and `interactive_message`.

## Save the Signing Secret on a connection

Slack signs each request with the app's **Signing Secret**, the same secret it signs Events API requests with. That secret is the same for every request the app sends, so OutWin does not save it on the block. You save it once on an API connection, and each Webhook block that receives from the app chooses that connection. If a connection already holds the secret for a [Slack events](https://outwin.ai/docs/build/connect-an-api/start-a-workflow-from-slack-events/) block, choose that connection in step 4 and skip the first three steps.

1. In your Slack app's settings, open **Basic Information**. Copy the **Signing Secret** under **App Credentials**.
2. In OutWin, open **Connections**. If the workspace has no API connection for Slack, [add one](https://outwin.ai/docs/build/connect-an-api/#add-an-api-connection). In **Base URL**, enter `https://slack.com/api`, the address of the Slack API that [the workflow's answer](#answer-from-the-workflow) is sent to. Nothing is sent to it when interactions are received. If you will not answer from the workflow, leave the field empty and choose **None** under **Authentication**.
3. On the connection's page, under **Receiving events**, paste the secret into the field that shows "Paste the signing secret" and select **Save**. The section then shows only a masked hint and the saved date, with **Replace** and **Remove**.
4. In the block's settings, under **Connection that holds the signing secret**, choose the connection. Each connection in the list is marked "secret saved" or "no secret yet".

The line under the setting then starts "Verifying with the secret ending", followed by the hint. Under **Set up**, the second line changes to "The signing secret is saved: deliveries are verified."

In a workspace with no API connection, the setting shows "No API connections yet." in place of the list, with an **Add one** link that opens **Connections**. If you choose a connection that has no secret, the line reads "This connection has no signing secret yet." with a **Save it on the connection** link to its page.

With a secret saved, OutWin also checks the time Slack signed the request. A request signed more than five minutes before or after the moment it arrives is listed as **Refused**.

With no connection chosen, or with a connection that has no secret, the block still starts runs, and nothing is verified: anyone who has the URL can start the workflow. Publishing then shows a warning that ends "has no signing secret saved, so its deliveries are not verified: anyone who has this URL can start this workflow". The warning does not block publishing.

## What the person sees at once

OutWin answers every interaction with status `200` and no body. It is the one answer Slack accepts for every kind of interaction, so the block has no text to set.

| Interaction | What the person sees |
| --- | --- |
| A button or a menu in a message (`block_actions`) | Nothing. The message stays as it was. |
| A shortcut (`shortcut`, `message_action`) | Nothing. |
| A submitted modal (`view_submission`) | The modal closes. |
| A closed modal (`view_closed`) | Nothing. |

The answer is the same on a draft, on a paused workflow, for a duplicate, and for an interaction the filter turns away. A button pressed while the workflow is a draft therefore does nothing the person can see, and Slack shows no error.

Slack lets an app put instructions in its answer to a submitted modal: show an error beside a field, replace the modal, or open another on top of it. OutWin's answer is always empty, so a workflow cannot do any of these. A submitted modal closes whatever the person entered, and the workflow reads the values afterward.

## Choose which interactions start a run

Under **Events that start a run**, tick the interaction types that start a run. The type is the `type` field of what Slack sends. With none ticked, every interaction starts a run. To start runs for a type that is not listed, type it into the box under the list and select **Add**.

An interaction whose type is not ticked is listed as **Filtered out** and starts no run. One Request URL carries every button, shortcut, and modal of the app, so most workflows also narrow by a field. Select **Add a condition** under **Only when** and name the field, such as `body.actions[0].action_id` for a button or `body.view.callback_id` for a modal. [Webhook settings](https://outwin.ai/docs/reference/triggers-approvals-and-waits/#webhook-settings) lists the comparisons.

## Send a test and check what arrived

1. In Slack, press a button in one of the app's messages, or use one of its shortcuts.
2. In OutWin, look under **Recent deliveries** in the block's settings.

**Recent deliveries** lists every interaction that reached the URL, including while the workflow is a draft. On a draft each interaction is listed as **Dropped** with "The workflow is not published, so nothing ran." It starts no run and is not run later. The last line under **Set up** changes from "Waiting for the first event…" to, for example, `Received block_actions. Dropped.`

With a secret saved on the chosen connection, an interaction listed as **Dropped** on a draft has passed the signature check. A delivery that fails the check is listed as **Refused**.

If you have edit access, select an interaction to see what the block passed on. The list is kept for seven days, and the data of the newest 20 events is kept.

## Read the interaction in the next block

Each run receives one interaction. Slack sends it as a form with one field, `payload`, that holds JSON. The block passes that JSON on as the body, so its fields are read directly. An HTTP request block or a database block directly after the Webhook block reads it with these expressions. An AI block such as **Think** receives the whole value as its input.

| Expression | What it holds |
| --- | --- |
| `{{input.body}}` | The interaction as Slack sent it, with a `type` field and a `user` field. Other fields depend on the type. |
| `{{input.body.user.id}}` | The id of the person who acted. |
| `{{input.body.actions[0].action_id}}` | In `block_actions`, the id your app gave the button or menu. `{{input.body.actions[0].value}}` holds a button's value. |
| `{{input.body.channel.id}}` | The id of the channel, where the interaction happened in one. A global shortcut and a modal have none. |
| `{{input.body.view.callback_id}}` | In `view_submission` and `view_closed`, the id your app gave the modal. `{{input.body.view.state.values}}` holds what the person entered. |
| `{{input.body.callback_id}}` | In `shortcut` and `message_action`, the id your app gave the shortcut. |
| `{{input.body.response_url}}` | Where present, the address Slack gives an app for a later answer. Slack does not always send one: a global shortcut and a plain submitted modal have none. An HTTP request block cannot call it. |
| `{{input.event.type}}` | The interaction's type, such as `block_actions`. It is the body's `type` field. |
| `{{input.event.id}}` | The body's `trigger_id` field, where Slack sends one. |
| `{{input.delivery.verified}}` | `true` only when the signature was checked and passed. |

A block further along reads the same values through the Webhook block's name, as in `{{steps["Slack interactivity"].body.user.id}}` for a block named `Slack interactivity`. [Data and context](https://outwin.ai/docs/reference/data-and-context/) describes what each block passes on.

Slack's `trigger_id` opens a modal only within three seconds of the interaction. A run starts later than that, so a workflow cannot open a modal in answer to a button or a shortcut.

## Answer from the workflow

Some interactions hold a `response_url`, the address Slack gives an app for a later answer. An HTTP request block cannot call it. The block sends to the host of its API connection and adds a path, the path cannot hold a full URL, and a value that an expression puts in the path cannot hold a slash.

To answer, call Slack's Web API with the app's bot token. The token needs the `chat:write` scope.

1. On the Slack connection's page, under **Settings**, set **Base URL** to `https://slack.com/api`, choose **Bearer token** under **Authentication**, enter the bot token, and select **Save changes**. This can be the connection that holds the Signing Secret.
2. After the blocks that do the work, add an **HTTP request** block and choose the connection.
3. Under **Request**, choose `POST` and enter the path of the method from the table.
4. Under **Body**, choose **JSON** and enter the fields the method takes.

| To | Path | Fields of the body |
| --- | --- | --- |
| Tell the person alone | `/chat.postEphemeral` | `channel`, `user`, and `text` |
| Post to the channel | `/chat.postMessage` | `channel` and `text` |
| Change the message the button was on | `/chat.update` | `channel`, `ts`, and `text`. `ts` is `{{input.body.message.ts}}` in the event. |

This body tells the person who pressed a button, and nobody else, what happened:

```text
{
  "channel": "{{steps["Slack interactivity"].body.channel.id}}",
  "user": "{{steps["Slack interactivity"].body.user.id}}",
  "text": "The request is approved."
}
```

Slack delivers an ephemeral message only when the person is in the channel. `chat.update` changes only a message the app itself posted, and it cannot change an ephemeral one. Slack's page for each method lists the other conditions, such as the app's access to the channel.

Slack answers these calls with status `200` also when it turns one down. The body then holds `"ok": false` and an `error` field, and the block completes. To act on a failed call, read `{{input.response.body.ok}}` in the next block.

## Publish and check the runs

[Publish the workflow](https://outwin.ai/docs/run/publish-and-start/). From then on, each interaction that passes the filter starts a run. On a published workflow the block's settings are read-only, including the choice of connection, and **Recent deliveries** is in the block's inspector. You can still replace the secret on the connection's page.

| Outcome | What happened |
| --- | --- |
| **Ran** | The interaction started a run. |
| **Waiting** | 10 runs of the workflow are already active. The interaction starts a run when one of them ends. An interaction that waits longer than an hour is listed as **Dropped**. |
| **Duplicate** | An interaction with the same `trigger_id` already ran in the last 72 hours. The line reads "This event was already received and run, so it did not run again." |

Runs start in the order interactions arrive. Slack receives the same empty answer whatever the outcome, so the person who pressed a button cannot tell from Slack whether a run started. A workflow that should confirm sends its own message.

Receiving an interaction costs no credits, and neither does one that is filtered out or a duplicate. A run that starts uses credits for the blocks that run in it.

## If nothing runs

Open **Recent deliveries** and read the outcome and the sentence beside the newest interaction.

| What you see | Cause | Fix |
| --- | --- | --- |
| "Nothing has arrived yet." | No request has reached the URL. | Check that **Interactivity** is on in the Slack app and that its **Request URL** is the block's current URL. The URL on the event subscriptions page and the URL of a slash command are different settings. **Rotate token** on a published workflow changes the URL, and the old one stops working. |
| **Dropped** with "The workflow is not published, so nothing ran." | The workflow is a draft. | Publish the workflow. Interactions that arrived before then are not run later. |
| **Dropped** with "The workflow is paused, so nothing ran." | The workflow is paused. | Resume the workflow. Interactions that arrived while it was paused are not run later. |
| **Filtered out** with `Events of type "view_closed" are not chosen on this trigger.` | The interaction's type is not ticked under **Events that start a run**. | Tick the type, or clear every tick so that all interactions start a run. The settings are read-only on a published workflow. |
| **Filtered out** for a button that should start a run | A row under **Only when** does not hold for this interaction, for example because it names another `action_id`. | Select the interaction to see its fields, and correct the row. |
| **Refused** with "The signature did not match. Check that the secret saved here is the one the sender shows for this URL." | The secret on the chosen connection is not the app's **Signing Secret**. This can happen when the block chose another service's connection, when the secret was copied from another app, or when the app's secret was replaced in Slack. | Copy the **Signing Secret** from the app again and select **Replace** under **Receiving events** on the connection's page. You do not republish the workflow. |
| **Refused** with "The request carried no signature." | A secret is saved on the chosen connection, and the request did not carry Slack's signature. A request sent by hand to try the URL has none. | Press the button in Slack so that Slack sends the request. |
| **Refused** with "The request's timestamp is too far from now, so it may be a replay of an old delivery." | The request was signed more than five minutes before or after it arrived, for example because a saved copy of an earlier request was sent again. | Press the button in Slack again. |
| **Ran**, and the workflow's message does not appear in Slack | The HTTP request block completed, and Slack turned the call down in the body of its answer. | Open the run and read the block's output. The `error` field names the reason. |

A delivery listed as **Refused** is answered with status `401` and starts nothing. OutWin keeps none of its data, and Slack shows the person who acted an error. For every other outcome in the table, Slack receives status `200` with no body and OutWin does not run the interaction later.
