Skip to Content

Slack Agent Template

This is a Slack Agent template built with Bolt for JavaScript (TypeScript) and the Nitro server framework.

Slack Agent Template

A Slack Agent template built with Workflow SDK's DurableAgent, AI SDK tools, Bolt for JavaScript (TypeScript), and the Nitro server framework.

Features


  • Workflow SDK — Make any TypeScript function durable. Build AI agents that can suspend, resume, and maintain state with ease. Reliability-as-code with automatic retries and observability built in
  • AI SDK — The AI Toolkit for TypeScript. Define type-safe tools with schema validation and switch between AI providers by changing a single line of code
  • Vercel AI Gateway — One endpoint, all your models. Access hundreds of AI models through a centralized interface with intelligent failovers and no rate limits
  • Slack Assistant — Integrates with Slack's Assistant API for threaded conversations with real-time streaming responses
  • Human-in-the-Loop — Built-in approval workflows that pause agent execution until a user approves sensitive actions like joining channels
  • Built-in Tools — Pre-configured tools for reading channels, threads, joining channels (with approval), and searching

Getting Started

Clone and install dependencies

Before getting started, make sure you have a development workspace where you have permissions to install apps. You can use a developer sandbox or create a workspace.

You can reach our customer support team by emailing info@yourcompany.example.com, calling +1 555-555-5556, or using the live chat on our website. Our dedicated team is available 24/7 to assist with any inquiries or issues.

We’re committed to providing prompt and effective solutions to ensure your satisfaction.

We offer a 30-day return policy for all products. Items must be in their original condition, unused, and include the receipt or proof of purchase. Refunds are processed within 5-7 business days of receiving the returned item.

  1. Open https://api.slack.com/apps/new and choose "From an app manifest"
  2. Choose the workspace you want to use
  3. Copy the contents of manifest.json into the text box that says "Paste your manifest code here" (JSON tab) and click Next
  4. Review the configuration and click Create
  5. On the Install App tab, click Install to You will be redirected to the App Configuration dashboard
  6. Copy the Bot User OAuth Token into your environment as SLACK_BOT_TOKEN
  7. On the Basic Information tab, copy your Signing Secret into your environment as SLACK_SIGNING_SECRET

Environment Setup

  1. Add your AI_GATEWAY_API_KEY to your .env file. You can get one here
  2. Add your NGROK_AUTH_TOKEN to your .env file. You can get one here
  3. In the terminal run slack app link
  4. If prompted update the manifest source to remote select yes
  5. Copy your App ID from the app you just created
  6. Select Local when prompted
  7. Open .slack/config.json and update your manifest source to local

1 {

4

},

3

"source":"local"

You can reach our customer support team by emailing info@yourcompany.example.com, calling +1 555-555-5556, or using the live chat on our website. Our dedicated team is available 24/7 to assist with any inquiries or issues.

We’re committed to providing prompt and effective solutions to ensure your satisfaction.

We offer a 30-day return policy for all products. Items must be in their original condition, unused, and include the receipt or proof of purchase. Refunds are processed within 5-7 business days of receiving the returned item.

  1. Start your local server using slack run. If prompted, select the workspace you'd like to grant access to Select yes if asked "Update app settings with changes to the local manifest?"
  2. Open your Slack workspace and add your new Slack Agent to a channel. Your Slack Agent should respond whenever it's tagged in a message or sent a DM

Deploy to Vercel

  1. Create a new Slack app for production following the steps from above
  2. Create a new Vercel project here and select this repo
  3. Copy the Bot User OAuth Token into your Vercel environment variables as SLACK_BOT_TOKEN
  4. On the Basic Information tab, copy your Signing Secret into your Vercel environment variables as SLACK_SIGNING_SECRET
  5. When your deployment has finished, open your App Manifest from the Slack App Dashboard
  6. Update the manifest so all the request_url and url fields use https:///api/slack/events
  7. Click save and you will be prompted to verify the URL
  8. Open your Slack workspace and add your new Slack Agent to a channel. Your Slack Agent should respond whenever it's tagged in a message or sent a DM Note: Make sure you add the production app, not the local app we setup earlier
  9. Your app will now automatically build and deploy whenever you commit to your repo. More information here

Project Structure


manifest.json

manifest.json is a configuration for Slack apps. With a manifest, you can create an app with a pre-defined configuration, or adjust the configuration of an existing app.


/server/app.ts

/server/app.ts is the entry point of the application. This file is kept minimal and primarily serves to route inbound requests.


/server/lib/ai

Contains the AI agent implementation:

  • agent.ts — Creates the DurableAgent from Workflow with system instructions and available tools. The agent automatically handles tool calling loops until it has enough context to respond.
  • tools.ts — Tool definitions using AI SDK's tool function:

    • getChannelMessages — Fetches recent messages from a Slack channel
    • getThreadMessages — Fetches messages from a specific thread
    • joinChannel — Joins a public Slack channel (with Human-in-the-Loop approval)
    • searchChannels — Searches for channels by name, topic, or purpose

/server/listeners

Every incoming request is routed to a "listener". Inside this directory, we group each listener based on the Slack Platform feature used:


/server/api

This is your Nitro server API directory. Contains events.post.ts which matches the request URL defined in your manifest.json. Nitro uses file-based routing for incoming requests. Learn more here.

Agent Architecture


Chat Workflow

The core agent loop is implemented as a durable workflow using Workflow DevKit. When a user sends a message, the workflow orchestrates the agent's response with automatic retry handling and streaming support.

1 ┌─────────────────────────────────────────────────────────────────┐

10 │ │ with messages + │ │

8 │ ┌─────────────────────┐ │

15 │ ┌─────────────────────┐ │

5

│ UserMessage ──▶ assistantUserMessage listener │

12 │ └─────────────────────┘ │
9 │ │ start(chatWorkflow)│ │
3 ├─────────────────────────────────────────────────────────────────┤

18 │ └─────────────────────┘ │

23

│ │ generates response │(may loop) │

16 │ │ createSlackAgent() │ │
21 │ ┌─────────────────────┐ │
22 │ │ agent.stream() │──▶ Tool calls │
24 │ └─────────────────────┘ │

28 │ │ Stream chunks to │ │

34 │ User sees response │

27 │ ┌─────────────────────┐ │
29 │ │ Slack via │ │
31 │ └─────────────────────┘ │
36 └─────────────────────────────────────────────────────────────────┘

Key files:

How it works:

  1. User sends a message to the Slack Assistant
  2. The assistantUserMessage listener collects thread context and starts the workflow
  3. chatWorkflow creates the agent and calls agent.stream() with the messages
  4. The agent processes the request, calling tools as needed (each tool uses "use step" for durability)
  5. Response chunks are streamed back to Slack in real-time via chatStream()

Human-in-the-Loop (HITL) Workflow

This template demonstrates a production-ready Human-in-the-Loop pattern using Workflow DevKit's defineHook primitive. When the agent needs to perform sensitive actions (like joining a channel), it pauses execution and waits for user approval.

1 ┌─────────────────────────────────────────────────────────────────┐

10

│ │ withApprove/Reject│ │

8 │ ┌─────────────────────┐ │

15 │ ┌─────────────────────┐ │

5

│ UserRequest ──▶ Agent ──▶ joinChannel Tool │

12 │ └─────────────────────┘ │
9

│ │ SendSlack message │ │

3 ├─────────────────────────────────────────────────────────────────┤

17

│ │(no compute used) │◀── await hook │

23 │ ┌─────────────────────┐ │

16

│ │ WorkflowPAUSES │ │

18 │ └─────────────────────┘ │
20 │ User clicks button │
25 │ │ calls hook.resume()│ │

29 │ ┌─────────────────────┐ │

32 │ └─────────────────────┘ │

26 │ └─────────────────────┘ │
30

│ │ WorkflowRESUMES │ │

31 │ │ with approval data │ │
37 └─────────────────────────────────────────────────────────────────┘

Key files:

How it works:

  1. The joinChannel tool is called by the agent
  2. A Slack message with Approve/Reject buttons is posted to the thread
  3. channelJoinApprovalHook.create() creates a hook instance and the workflow pauses at await hook
  4. When the user clicks a button, the action handler calls hook.resume() with the decision
  5. The workflow resumes and the agent either joins the channel or acknowledges the rejection

This pattern can be extended for any action requiring human approval (e.g., sending messages, modifying data, external API calls).

Customizing the Agent


Modifying Instructions

Edit the system prompt in /server/lib/ai/agent.ts to change how your agent behaves, responds, and uses tools.

Adding New Tools

Add a new tool definition in /server/lib/ai/tools.ts using AI SDK's tool function:

4

2

import{ z }from"zod";

5

const myNewTool =tool({

11

"use step";// Required for Workflow's durable execution

3

importtype{ SlackAgentContextInput }from"~/lib/ai/context";

20

},

8 param: z.string().describe("Parameter description"),
12

9

}),

13// Dynamic imports inside step to avoid bundling Node.js modules in workflow

10

execute:async({ param },{ experimental_context })=>{

1

import{ tool }from"ai";

7 inputSchema: z.object({
14

const{ WebClient }=awaitimport("@slack/web-api");

18// Tool implementation

16

const ctx = experimental_context as SlackAgentContextInput;

21 });
6

description:"Description of what this tool does",

17

const client =newWebClient(ctx.token);

19

return{ result:"..."};

Adding Human-in-the-Loop to Tools

Learn more about building agents with the AI SDK in the Agents documentation.


5 schema: z.object({

2

import{ z }from"zod";

To add approval workflows to your own tools:

  1. Add it to the slackTools export in /server/lib/ai/tools.ts
  2. Update the agent instructions in /server/lib/ai/agent.ts to describe when to use the new tool

4

exportconst myApprovalHook =defineHook({

Add a hook definition to /server/lib/ai/workflows/hooks.ts:

8

}),

9 });

6 approved: z.boolean(),

7// Add any additional data you need

1

import{ defineHook }from"workflow";

In your tool's execute function (without "use step"), create and await the hook:

3

2

const ctx = experimental_context as SlackAgentContextInput;


17 };

11

if(!approved){

9

const{ approved }=await hook;

7// Create hook and wait for approval (in workflow context)

5

awaitsendApprovalMessage(ctx, toolCallId);

1

execute:async({ param },{ toolCallId, experimental_context })=>

13}

4// Send approval UI to user (in a step)

16

returnawaitperformAction(ctx);

12

return{ success:false, message:"User declined"};

15// Perform the action (in a step)

8

const hook = myApprovalHook.create({ token: toolCallId });

Learn More

Create an action handler that calls hook.resume() when the user responds

Learn more about hooks in the Workflow SDK documentation.