Skip to main content
This guide connects a Slack app to a Cadenya Agent. It takes about 15 minutes. When you finish, the app does three things:
  • It answers DMs and @mentions with your Agent.
  • It shows each tool call in the thread and updates the status as the call runs.
  • It asks for approval with buttons before a tool runs.
The code is on GitHub: cadenya/slack-ai-agents-example. It uses Bolt for JavaScript and the @cadenya/cadenya SDK.
Slack thread where the Cadenya Agent replies to a request for a contact card. Three collapsed plans read Used 8 tools, Used 2 tools, and Used 3 tools. The last plan is expanded to show three GenerateFake calls. A code block with the contact card and thumbs up and down buttons follow.

The Agent's reply in a Slack thread. Each step of the agent loop shows its tool calls as a plan, and the final answer has feedback buttons.

Prerequisites

You need:
  • A Cadenya account.
  • The Cadenya CLI. The next section installs it.
  • A Slack workspace where you can install apps. Slack offers free developer sandboxes.
  • The Slack CLI. Log in with slack login.
  • Node.js 22 or later.
  • ngrok, or another tunnel.

Install the Cadenya CLI

Install the CLI with Homebrew:
The CLI guide lists the other install options. Then log in and choose a workspace:
Replace development with the external ID of your workspace.

How it works

Slack and Cadenya do not connect to each other. Your app sits between them. It sends Slack messages to Cadenya, and it posts Cadenya’s webhook events to Slack. One Slack thread is one Objective. The app stores the link between them on the Objective: Every webhook includes the Objective’s labels. The app reads the thread from them, so it needs no lookup and no database.

Set it up

1

Clone the example

2

Create the Agent

These commands create a Tool Set, an Agent, and a variation, then publish the Agent. The Tool Set uses Cadenya’s free Faker MCP server. It requires approval for every call, so you can try the approval buttons.Set MODEL_ID to a model from cadenya models list:
If you already have a published Agent, skip this step. Use that Agent’s ID for CADENYA_AGENT_ID in a later step.
3

Set the Agent's webhook URL

Cadenya sends webhooks to a public URL. The app listens on port 3210, so start a tunnel to that port:
Copy the forwarding URL and set it as the Agent’s webhook URL. Add /webhooks/cadenya to the end.
4

Fill in .env

The app needs four values:
.env
Create an API key with only the objectives:manage scope. This command prints the token. Cadenya shows it only when you create the key, so save it now.
Copy the webhook signing key from Account Admin. Every Agent in the account uses the same key.
5

Run it

The first run creates the Slack app from manifest.json and asks which workspace to install it in. The app uses Socket Mode, so Slack does not need a public URL.You should see:
6

Send a message

DM the app, or @mention it in a channel:
The thread shows a plan named Working on it and an approval request with Approve and Deny buttons:
Slack thread where the Cadenya Agent shows a plan titled Working on it, then a message that reads The agent wants to run GenerateCurseWord and needs approval, the tool arguments, and green Approve and red Deny buttons.

An approval request in the thread. This one is for the Faker server's GenerateCurseWord tool.

Click Approve. The task in the plan changes to complete, and the Agent’s reply appears in the thread.Some models call GetFakerOptions first. If that happens, approve that call too.To continue the conversation, reply in the thread. The app sends each reply to the same Objective.

How the code works

Most of the logic is in four files.

Send a Slack message to Cadenya

The app builds an external ID from the Slack thread. If the thread already has an Objective, the app continues it. Otherwise, the app creates one. This is a shortened version of cadenya/thread.js:
cadenya/thread.js
A few details:
  1. Neither call waits for the Agent. Slack expects a response to each event within 3 seconds. An Agent that calls tools takes longer. The reply arrives later, on a webhook.
  2. Slack can send the same event twice. The second create fails with 409 because the external ID exists, and the app ignores that error.
  3. You can’t reuse an external ID, even after its Objective ends. If someone replies in a thread whose Objective has ended, the app creates a new Objective. Its external ID is <external ID>-<message ts>, and the app finds it by label.
  4. enqueue: true queues a message that arrives while the Agent is still working.

Receive webhooks

Bolt serves the webhook endpoint as a custom route. The route verifies the signature, then reads the Slack thread from the labels:
cadenya/webhook-route.js
To see what Cadenya sends, open the ngrok inspector at http://localhost:4040. It lists each webhook with its headers and body, and it can replay one. This tool_result webhook shows the Slack labels and the external ID on data.objective:
ngrok inspector showing a POST to /webhooks/cadenya. The JSON body has the type objective_event.tool_result, and its data.objective has labels for slack_channel, slack_team, slack_thread_ts, and slack_user, plus an externalId built from the same values.

A tool result webhook in the ngrok inspector. The Objective's labels name the Slack team, channel, thread, and user.

A few details:
  1. unwrap needs the raw request body. Read the body before any code parses it as JSON.
  2. Cadenya retries a failed delivery. The route stores each webhook-id it has processed and skips repeats.
  3. A webhook from a sub-agent includes rootObjective. The app uses its labels, so the event goes to the thread that started the work.
The webhooks guide describes the payload and every event type.

Show tool calls as a plan

Events from the same step of the agent loop have the same iterationId. One step is an assistant message plus the tool calls it requested. The app uses iterationId to group events into one Slack message. For each iteration, the app starts a Slack message with chat.startStream in plan mode. Then it appends a chunk for each webhook. This is a simplified version of cadenya/thread-renderer.js:
cadenya/thread-renderer.js
Slack shows each task_update as a task in a plan block. The task ID is the tool call ID, so a second update changes the status of the same task. When every tool call in the iteration has finished, the app stops the stream. The final answer also gets feedback buttons. The app uses a Slack stream because chat.appendStream lets several webhooks add to one message. The reply text still arrives all at once. Cadenya sends text deltas on the event stream, not on webhooks. A few details:
  1. Webhooks for one Objective can arrive at the same time, or out of order. For example, a toolCalled webhook can arrive before the assistantMessage that requested the call. The app processes one event at a time for each Objective. It never changes a finished task back to in progress.
  2. Slack closes a stream after 10 minutes. An approval can take longer than that. If the stream has closed, the app continues in a new message.
  3. Tool calls from a sub-agent do not appear in the plan. Its approval requests and errors still appear in the thread.

Approve or deny a tool call

Slack has no built-in approval step. The app posts Block Kit buttons and puts the Objective ID and tool call ID in each button’s value. When someone clicks a button, the handler reads the IDs back:
listeners/actions/tool-approval-buttons.js
The Agent reads the memo when a call is denied, so write it as an instruction to the model. The feedback buttons work the same way. A click calls objectives.createFeedback with a score of 1 or -1. Cadenya uses feedback to choose between variations.

Let the Agent act in Slack

The Faker tools run on a remote server. A client tool runs in your app instead. Your app has the Slack token, so a client tool can call the Slack API. The example defines one client tool, add_emoji_reaction, in cadenya/client-tools.js. The app passes the definition to objectives.create:
When the Agent calls the tool, the app receives a toolCalled webhook. The app calls Slack’s reactions.add, then returns the result with objectives.setToolCallContent. You can add your own client tools the same way. For example, a tool can pin a message or look up a user. A client tool can do anything your bot token allows.

Before you deploy

The example is small on purpose. Change three things before you run it in production:
  1. Use a stable URL. Host the app at a permanent address and update the Agent’s webhook URL. You can keep Socket Mode, unless you plan to list the app in the Slack Marketplace. The Marketplace requires HTTP.
  2. Store state outside the process. The app keeps two things in memory: the webhook-id values it has processed, and the open Slack message for each iteration. If you run more than one process, move both to a shared store. Use a unique constraint on webhook-id, and store each stream’s ts by iterationId.
  3. Support more than one Slack workspace. The app uses one bot token. To serve several workspaces, add Bolt’s OAuth installation store. Then choose the token with the slack_team label.

See the conversation in Cadenya

As always, Cadenya stores the entire history of the conversation. Open the Objective in the dashboard to see each message, tool call, and approval on a timeline. The External ID in the details panel is the one the app built from the Slack thread.
Cadenya dashboard showing an Objective timeline with user message, reasoning, assistant message, tool approval, tool called, and tool result events. The GenerateCurseWord call is expanded and marked Approved and Completed. A details panel shows the Slack external ID, the Slack agent, and execution stats.

The Objective for the approval example. The timeline shows the approval request, who approved it, and the tool call that followed.

Where to go next

  • To connect the Agent to your own API, create a Tool Set.
  • For suggested prompts, status, and streaming in Slack, see Slack’s guide to developing agents.