Slack Bots on Sprites: OAuth is Easy Now
Slack bots are handy, but they typically require OAuth, which means you need a server with a public URL to handle callbacks. This is annoying. But with Sprites, you get an instant internet-accessible environment with a persistent filesystem that makes it trivial.
OAuth Pain
Getting your Slack bot working involves jumping through these OAuth hurdles:
- Create an endpoint to receive Slack’s authorization callback
- Get that endpoint online with a public URL
- Securely store tokens after the callback
- Maintain those tokens across restarts
This requires deploying something to a host, setting up Ngrok and implementing a storage solution for tokens.
Slack Bot Sprites
Create a Sprite for your bot:
sprite create slack-bot
sprite console -s slack-bot
Install your dependencies:
npm init -y
npm install @slack/bolt express
Build an OAuth Handler
Now we need a server that:
- Handles the OAuth callback from Slack
- Stores access tokens to the filesystem
- Loads those tokens when the server restarts
- Implements your bot’s functionality
Ask your code assistant to: “Create a server.js file that handles Slack OAuth callbacks using the Bolt framework, stores tokens to the filesystem, and implements a simple slash command. The server should run on port 8080.”
Register Your Slack Bot as a Sprite Service
Sprites don’t use systemd or traditional init systems. Instead, they have their own service manager that enables the Sprite’s automatic sleep/wake behavior.
So you’ll want to register your bot as a service with the HTTP port flag:
sprite-env services create --name slack-bot --cmd "node server.js" --http_port 8080
This does three critical things:
- Auto-start on HTTP requests: When a request hits your Sprite URL, the Sprite wakes from hibernation
- Auto-route requests: The Sprite proxy routes incoming traffic to your specified port (8080)
- Persistent registration: Your service registration survives Sprite restarts and hibernation
When idle, your Sprite hibernates to save costs and wakes in under a second when Slack sends events or users visit the install URL.
Get Your Public URL
sprite url update --auth public -s slack-bot
Configure Your Slack App
The rest is standard Slack stuff:
- Visit https://api.slack.com/apps
- Create a new app
- Under “OAuth & Permissions”, add your Sprite’s URL
- Copy your Client ID and Client Secret
- Set them as environment variables in your Sprite:
sprite-env env set SLACK_CLIENT_ID=your_client_id
sprite-env env set SLACK_CLIENT_SECRET=your_client_secret
sprite-env env set SLACK_SIGNING_SECRET=your_signing_secret
Install Your Bot
Visit: https://your-slack-bot.sprites.app/slack/install
This triggers the OAuth flow. Slack redirects back to your Sprite, which handles the callback and stores the token in its filesystem.
Checkpoint Your Working Setup
Once everything is working, create a checkpoint:
sprite checkpoint create
A Sprite checkpoint is a snapshot of the entire environment, not just your code. So if/when you break your bot, just:
sprite restore <checkpoint-id>`
More Time for Cheeky Slack Messages
Building a Slack bot in a Sprite means no longer having to:
- Set up and maintain the server
- Configure networking and SSL
- Implement your own hibernation/wake logic (or pay for idle time)
- Handle security updates and monitoring
Instead, write your bot, deploy it, forget about it. The Sprite wakes up when Slack calls, sleeps when it doesn’t, and you only pay for the moments it’s actually working.