Public
Remixed
AI Slack bot (Claude + web search) for Charlie test workspace
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

ai-slackbot

An AI agent powered by Claude with web search, deployed on Val Town.

Features

  • Responds to @mentions in channels and threads, with full thread history as context
  • Acts as a Slack assistant in DMs (Chat tab), with greeting + suggested prompts
  • Powered by Claude Sonnet 4.6 with Anthropic's built-in web search tool
  • One-click Slack app setup — no manual scope or event configuration
  • Easily extensible: swap models, add tools, change prompts

Setup (~2 minutes)

  1. Click Remix to get your own copy of this val.
  2. Open your val's HTTP endpoint in a new tab (you should see it in the homepage of your remixed val), then click Create Slack App. The app's manifest — scopes, events, and webhook URL — is pre-filled, so just click Next → pick workspace → Create.
  3. Install to Workspace in the Slack app's Install App tab.
  4. Paste 3 secrets into your val's environment variables (the slots are already created — just fill the values):
    • SLACK_BOT_TOKEN — Slack app → OAuth & Permissions → Bot User OAuth Token (xoxb-...)
    • SLACK_SIGNING_SECRET — Slack app → Basic Information → Signing Secret
    • ANTHROPIC_API_KEY — from the Claude console

Usage

  • DM the bot — open the Slack app, click Messages, and chat. The conversation maintains thread context automatically.
  • @mention in a channel — the bot replies in a thread on your message. Follow-ups in that thread also get full thread context.

⚠️ Invite the bot to the channel first (/invite @AI Slackbot). Without channel membership, the bot receives the mention event but can't read thread history, and will only see your single mention as context.

Architecture

ai-slackbot/
├── events.ts                        # HTTP entry point: setup page + Slack event router
├── prompt.md                        # System prompt for your agent
├── README.md
└── lib/
    ├── generate-response.ts         # AI core (Claude + web search)
    ├── handle-app-mention.ts        # @mentions in channels and threads
    ├── handle-message.ts            # DMs in assistant (Chat tab) threads
    ├── handle-thread-started.ts     # Greeting + suggested prompts on new assistant thread
    └── slack-utils.ts               # Slack client, request verification, thread fetching

Slack POSTs events to /events. The handler verifies the signature, then dispatches the heavy work to /process as a separate HTTP request — Val Town kills detached promises after the response is sent, so the early-return pattern gives the real handler its own full execution lifecycle.

Customization

  • Swap the model or model providerlib/generate-response.ts (uses the Vercel AI SDK, so any provider works)
  • Edit the system promptprompt.md
  • Add tools (database queries, knowledge bases, custom APIs) → extend the tools object in lib/generate-response.ts. See the AI SDK tools docs.
  • Change greeting or suggested prompts in DMs → lib/handle-thread-started.ts
  • Change Slack scopes, events, or app metadata → edit the manifest object at the top of events.ts. Re-create the Slack app from the updated setup page.

Version pinning

This val uses pinned imports to avoid breaking changes:

  1. @slack/web-api@7.14.1
  2. hono@4.12.0
  3. ai@6.0.92
  4. @ai-sdk/anthropic@3.0.45

Credits

Based on Vercel's Slackbot Agent Guide and Pete Millspaugh's pmillspaugh/duck