Bring Val Town into Slack - a self-improving Slackbot that powers your internal workflows!
This remix adds a workflow view: the
events.tsrequest pipeline (trigger, filters, dispatch, event-type branching, agent loop, reply) rendered in a Zapier-style editor layout, styled with thevaldottown/skills→valtown-uiskill. Steps expand to show implementation details; the Run test button plays a simulated execution. Implementation is inzapier-view/(static HTML/CSS/JS served byzapier-view/main.ts).
Featuring one-click Slack app setup — no manual scope configuration, event subscription, or URL copying required.
-
After remixing the template, visit your val's HTTP endpoint (the root
/URL) to see the setup page -
Click "Create Slack App" — this opens Slack with a pre-filled app manifest containing all scopes, events, chat tab config, and your webhook URL already configured. Just click Create → Install to Workspace.
Optionally tweak the app name and bot user fields above the button first — they're prefilled with
Townie/townie-slackbot, and whatever you type is baked into the manifest.Note: immediately after you install the app and Go to App Settings, you may see a banner saying "You've changed the permission scopes your app uses. Please reinstall your app for these changes to take effect" - you'll need to click reinstall.
-
Copy 2 secrets from your new Slack app into this val's environment variables (the setup page links straight to each one):
SLACK_BOT_TOKEN— OAuth & Permissions → Bot User OAuth TokenSLACK_SIGNING_SECRET— Basic Information → Signing Secret
-
Add your AI tokens as environment variables:
TOWNIE_TOKEN— your Val Town API token (if you have a Val Town org, navigate to your org settings to make an API key just for the org, and in either case make sure to give write permissions so it can build vals!)ANTHROPIC_API_KEY— from the Claude console
The setup page shows a live checklist of which env vars are configured. Once all four are green, your bot is live — try messaging it in Slack!
Slack supports creating apps from a manifest URL. The setup page dynamically generates a manifest with your val's endpoint URL baked in, so you never have to manually configure scopes, event subscriptions, or paste webhook URLs. This collapses the original 8-step process into 3 steps.
townie/
├── events.ts # HTTP entry point — mounts the route modules below
├── prompt.md # System prompt for your agent
├── README.md
├── routes/
│ ├── setup.tsx # GET / setup page (and /source)
│ ├── connectors.tsx # GET /auth/* OAuth for external MCP services
│ └── slack.ts # POST /events intake → POST /process does the work
├── views/ # Server-rendered JSX (Hono JSX + Twind)
│ ├── layout.tsx # HTML shell + shared style tokens
│ ├── setup-page.tsx # Setup page and its components
│ ├── message-page.tsx # Generic success / error page
│ └── render.ts # JSX → HTML document
├── connectors/ # External MCP service integrations (optional)
│ ├── registry.ts # Service registry + tool loader (add connectors here)
│ └── oauth.ts # Generic OAuth 2.0 + PKCE engine
└── lib/
├── generate-response.ts # AI core (Claude + MCP + web search)
├── conversation-store.ts # SQLite-backed conversation persistence
├── handle-app-mention.ts # Handles @mentions in channels and threads
├── handle-message.ts # Handles DMs in assistant (Slack app) threads
├── handle-thread-started.ts # Greeting + suggested prompts on new assistant thread
├── should-respond.ts # Should an *untagged* channel message get a reply?
├── should-skip-event.ts # Drops bot/self-triggered events before dispatch
├── progress.ts # One message, edited in place, then into the answer
├── people.ts # Val Town handle → the name people actually use
├── slack-manifest.ts # The manifest behind one-click app creation
├── slack-utils.ts # Slack client and utils
└── val-links.ts # Links back into this val (code, env vars)
Pages are React-style components in views/*.tsx, rendered server-side by
Hono's JSX runtime — no markup in template
strings, so the setup page is type-checked and highlighted like the rest of the
code. Styling is Twind (Tailwind classes applied at
runtime from a CDN), so there's no build step and no stylesheet to keep in sync.
This template uses Claude Opus 4.6 directly in
lib/generate-response.ts, which requires setting
an ANTHROPIC_API_KEY environment variable. Alternatively, you could use a
gateway to switch between models easily, like the
Vercel AI Gateway or the
Kilo Gateway.
This agent comes with the following tools:
You should of course edit and add your own tools! That's the whole point of BYOA :)
This val uses pinned imports (latest package version as of 2/19/26) to avoid breaking changes:
@slack/web-api@7.14.1hono@4.12.0ai@6.0.92@ai-sdk/anthropic@3.0.45@ai-sdk/mcp@1.0.21
Based on pmillspaugh/townie, which is based on Vercel's Slackbot Agent Guide, adapted for Val Town.