VercelLogotypeVercelLogotype
LoginSign Up

AI SDK Slackbot

An open-source AI Slackbot.

DeployView Demo

AI SDK Slackbot

An AI-powered chatbot for Slack powered by the AI SDK by Vercel.

Features

  • Integrates with Slack's API for easy Slack communication
  • Use any LLM with the AI SDK (easily switch between providers)
  • Works both with app mentions and as an assistant in direct messages
  • Maintains conversation context within both threads and direct messages
  • Built-in tools for enhanced capabilities:
    • Real-time weather lookup
    • Web search (powered by Exa)
  • Easily extensible architecture to add custom tools (e.g., knowledge search)

Prerequisites

  • Node.js 18+ installed
  • Slack workspace with admin privileges
  • OpenAI API key
  • Exa API key (for web search functionality)
  • A server or hosting platform (e.g., Vercel) to deploy the bot

Setup

1. Install Dependencies

npm install
# or
pnpm install

2. Create a Slack App

  1. Go to https://api.slack.com/apps and click "Create New App"
  2. Choose "From scratch" and give your app a name
  3. Select your workspace

3. Configure Slack App Settings

  • Go to "Basic Information"

    • Under "App Credentials", note down your "Signing Secret". This will be an environment variable SLACK_SIGNING_SECRET
  • Go to "App Home"

    • Under Show Tabs -> Messages Tab, Enable "Allow users to send Slash commands and messages from the messages tab"
  • Go to "OAuth & Permissions"

    • Add the following Bot Token Scopes:
      • app_mentions:read
      • assistant:write
      • chat:write
      • im:history
      • im:read
      • im:write
    • Install the app to your workspace and note down the "Bot User OAuth Token" for the environment variable SLACK_BOT_TOKEN
  • Go to "Event Subscriptions"

    • Enable Events
    • Set the Request URL to either
      • your deployment URL: (e.g. https://your-app.vercel.app/api/events)
      • or, for local development, use the tunnel URL from the Local Development section below
    • Under "Subscribe to bot events", add:
      • app_mention
      • assistant_thread_started
      • message:im
    • Save Changes

Remember to include /api/events in the Request URL.

You may need to refresh Slack with CMD+R or CTRL+R to pick up certain changes, such as enabling the chat tab

4. Set Environment Variables

Create a .env file in the root of your project with the following:

# Slack Credentials
SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_SIGNING_SECRET=your-signing-secret
# OpenAI Credentials
OPENAI_API_KEY=your-openai-api-key
# Exa API Key (for web search functionality)
EXA_API_KEY=your-exa-api-key

Replace the placeholder values with your actual tokens.

Local Development

Use the Vercel CLI and untun to test out this project locally:

pnpm i -g vercel
pnpm vercel dev --listen 3000 --yes
npx untun@latest tunnel http://localhost:3000

Make sure to modify the subscription URL to the untun URL.

Note: you may encounter issues locally with waitUntil. This is being investigated.

Production Deployment

Deploying to Vercel

  1. Push your code to a GitHub repository

  2. Deploy to Vercel:

    • Go to vercel.com
    • Create New Project
    • Import your GitHub repository
  3. Add your environment variables in the Vercel project settings:

    • SLACK_BOT_TOKEN
    • SLACK_SIGNING_SECRET
    • OPENAI_API_KEY
    • EXA_API_KEY
  4. After deployment, Vercel will provide you with a production URL

  5. Update your Slack App configuration:

    • Go to your Slack App settings

    • Select your app

    • Go to "Event Subscriptions"

      • Enable Events
      • Set the Request URL to: https://your-app.vercel.app/api/events
    • Save Changes

Usage

The bot will respond to:

  1. Direct messages - Send a DM to your bot
  2. Mentions - Mention your bot in a channel using @YourBotName

The bot maintains context within both threads and direct messages, so it can follow along with the conversation.

Available Tools

  1. Weather Tool: The bot can fetch real-time weather information for any location.

    • Example: "What's the weather like in London right now?"
  2. Web Search: The bot can search the web for up-to-date information using Exa.

    • Example: "Search for the latest news about AI technology"
    • You can also specify a domain: "Search for the latest sports news on bbc.com"

Extending with New Tools

The chatbot is built with an extensible architecture using the AI SDK's tool system. You can easily add new tools such as:

  • Knowledge base search
  • Database queries
  • Custom API integrations
  • Company documentation search

To add a new tool, extend the tools object in the lib/ai.ts file following the existing pattern.

You can also disable any of the existing tools by removing the tool in the lib/ai.ts file.

License

MIT

GitHub Repovercel-labs/ai-sdk-slackbot
Use Cases
AI
Backend
Stack
Other
None

Related Templates

Chatbot

A full-featured, hackable Next.js AI chatbot built by Vercel
Chatbot thumbnail

Dynamic Model Usage with AI SDK

A chatbot that allows you to dynamically set the LLM using Vercel AI SDK with Feature Flags and Edge Config
Dynamic Model Usage with AI SDK thumbnail

Get Started

  • Templates
  • Supported frameworks
  • Marketplace
  • Domains

Build

  • Next.js on Vercel
  • Turborepo
  • v0

Scale

  • Content delivery network
  • Fluid compute
  • CI/CD
  • Observability
  • AI GatewayNew
  • Vercel AgentNew

Secure

  • Platform security
  • Web Application Firewall
  • Bot management
  • BotID
  • SandboxNew

Resources

  • Pricing
  • Customers
  • Enterprise
  • Articles
  • Startups
  • Solution partners

Learn

  • Docs
  • Blog
  • Changelog
  • Knowledge Base
  • Academy
  • Community

Frameworks

  • Next.js
  • Nuxt
  • Svelte
  • Nitro
  • Turbo

SDKs

  • AI SDK
  • Workflow SDKNew
  • Flags SDK
  • Chat SDK
  • Streamdown AINew

Use Cases

  • Composable commerce
  • Multi-tenant platforms
  • Web apps
  • Marketing sites
  • Platform engineers
  • Design engineers

Company

  • About
  • Careers
  • Help
  • Press
  • Legal
  • Privacy Policy

Community

  • Open source program
  • Events
  • Shipped on Vercel
  • GitHub
  • LinkedIn
  • X
  • YouTube

Loading status…

Select a display theme:
    • AI Cloud
      • AI Gateway

        One endpoint, all your models

      • Sandbox

        Isolated, safe code execution

      • Vercel Agent

        An agent that knows your stack

      • AI SDK

        The AI Toolkit for TypeScript

      • v0

        Build applications with AI

    • Core Platform
      • CI/CD

        Helping teams ship 6× faster

      • Content Delivery

        Fast, scalable, and reliable

      • Fluid Compute

        Servers, in serverless form

      • Workflow

        Long-running workflows at scale

      • Observability

        Trace every step

    • Security
      • Bot Management

        Scalable bot protection

      • BotID

        Invisible CAPTCHA

      • Platform Security

        DDoS Protection, Firewall

      • Web Application Firewall

        Granular, custom protection

    • Company
      • Customers

        Trusted by the best teams

      • Blog

        The latest posts and changes

      • Changelog

        See what shipped

      • Press

        Read the latest news

      • Events

        Join us at an event

    • Learn
      • Docs

        Vercel documentation

      • Academy

        Linear courses to level up

      • Knowledge Base

        Find help quickly

      • Community

        Join the conversation

    • Open Source
      • Next.js

        The native Next.js platform

      • Nuxt

        The progressive web framework

      • Svelte

        The web’s efficient UI framework

      • Turborepo

        Speed with Enterprise scale

    • Use Cases
      • AI Apps

        Deploy at the speed of AI

      • Composable Commerce

        Power storefronts that convert

      • Marketing Sites

        Launch campaigns fast

      • Multi-tenant Platforms

        Scale apps with one codebase

      • Web Apps

        Ship features, not infrastructure

    • Tools
      • Marketplace

        Extend and automate workflows

      • Templates

        Jumpstart app development

      • Partner Finder

        Get help from solution partners

    • Users
      • Platform Engineers

        Automate away repetition

      • Design Engineers

        Deploy for every idea

  • Enterprise
  • Pricing
Log InContact
Sign Up
Sign Up
DeployView Demo
AI Gateway

One endpoint, all your models

Sandbox

Isolated, safe code execution

Vercel Agent

An agent that knows your stack

AI SDK

The AI Toolkit for TypeScript

v0

Build applications with AI

CI/CD

Helping teams ship 6× faster

Content Delivery

Fast, scalable, and reliable

Fluid Compute

Servers, in serverless form

Workflow

Long-running workflows at scale

Observability

Trace every step

Bot Management

Scalable bot protection

BotID

Invisible CAPTCHA

Platform Security

DDoS Protection, Firewall

Web Application Firewall

Granular, custom protection

Customers

Trusted by the best teams

Blog

The latest posts and changes

Changelog

See what shipped

Press

Read the latest news

Events

Join us at an event

Docs

Vercel documentation

Academy

Linear courses to level up

Knowledge Base

Find help quickly

Community

Join the conversation

Next.js

The native Next.js platform

Nuxt

The progressive web framework

Svelte

The web’s efficient UI framework

Turborepo

Speed with Enterprise scale

AI Apps

Deploy at the speed of AI

Composable Commerce

Power storefronts that convert

Marketing Sites

Launch campaigns fast

Multi-tenant Platforms

Scale apps with one codebase

Web Apps

Ship features, not infrastructure

Marketplace

Extend and automate workflows

Templates

Jumpstart app development

Partner Finder

Get help from solution partners

Platform Engineers

Automate away repetition

Design Engineers

Deploy for every idea