A Cloudflare Worker that provides inspirational quotes from Ray via Slack slash commands. Share the positivity and motivation that Ray brings to the team!
- Slash Command:
/rayfirmation- Get a random inspirational quote from Ray - Stats Command:
/rayfirmation stats- View usage statistics and available quotes - Add Quote Command:
/rayfirmation add "quote"- Add a new rayfirmation to the database - Interactive Buttons:
- 🎲 Shuffle - Get a different rayfirmation
- 💫 Rayfirm - Share the rayfirmation with the entire channel
- Usage Tracking: Persistent storage of total rayfirmations shared using Cloudflare KV
- Database Storage: All rayfirmations stored in Cloudflare D1 database for scalability
- Ephemeral Responses: Private interactions with public sharing option
- Cloudflare account with Workers enabled
- Slack workspace with admin permissions
- Wrangler CLI installed (
npm install -g wrangler)
git clone <your-repo-url>
cd rayfirmations-
Login to Wrangler:
wrangler login
-
Create KV Namespace:
wrangler kv:namespace create "TOTAL_COUNT" -
Create D1 Database:
wrangler d1 create rayfirmations-db
-
Apply Database Schema:
wrangler d1 execute rayfirmations-db --file=./schema.sql
-
Configure wrangler.toml (update the file with your IDs):
name = "rayfirmations" main = "worker.js" compatibility_date = "2024-01-01" [[kv_namespaces]] binding = "TOTAL_COUNT" id = "your-kv-namespace-id" preview_id = "your-preview-kv-namespace-id" [[d1_databases]] binding = "RAYDB" database_name = "rayfirmations-db" database_id = "your-d1-database-id"
wrangler deploy-
Go to api.slack.com/apps
-
Create a new app
-
Add the following OAuth scopes:
commands- For slash commandschat:write- For posting messagesusers:read- For user information
-
Create Slash Command:
- Command:
/rayfirmation - Request URL:
https://your-worker.your-subdomain.workers.dev - Short Description: "Get an inspirational quote from Ray"
- Usage Hint: "Just type /rayfirmation, /rayfirmation stats, or /rayfirmation new"
- Command:
-
Configure Interactive Components:
- Request URL:
https://your-worker.your-subdomain.workers.dev
- Request URL:
-
Add Required Scopes (in OAuth & Permissions):
commands- For slash commandschat:write- For posting messagesusers:read- For user information
-
Install App to Workspace
- Type
/rayfirmationin any Slack channel - You'll receive a private message with a random rayfirmation
- Use the buttons to:
- Shuffle: Get a different quote
- Rayfirm: Share the quote with everyone in the channel
- Type
/rayfirmation statsto view usage statistics - You'll see:
- Total number of rayfirmations shared
- Total number of available quotes in the database
- Formatted display with emojis and proper formatting
- Type
/rayfirmation newto see instructions - Use the format:
/rayfirmation add "Your new quote here" - Example:
/rayfirmation add "You are absolutely amazing!" - The quote will be added to the database if it's unique
- You'll receive a confirmation message
Requirements for new quotes:
- Must be enclosed in quotes
- Cannot be empty
- Must be under 500 characters
- Must be unique (not already in database)
- Ephemeral: Initial responses are private to the user
- In-Channel: When "Rayfirm" is clicked, the message is shared publicly with italic formatting
- Cloudflare Workers: Serverless edge computing
- Cloudflare KV: Persistent storage for usage tracking
- Cloudflare D1: SQLite database for storing rayfirmations
- Slack API: Interactive components and slash commands
The D1 database contains a single table:
CREATE TABLE quotes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
text TEXT NOT NULL UNIQUE,
added_by_id TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);The added_by_id field tracks who added each quote:
"system"for the original quotes loaded from the schema- User ID for quotes added by users via the
/rayfirmation addcommand
# Install dependencies (if any)
npm install
# Run locally
wrangler dev# View database contents
wrangler d1 execute rayfirmations-db --command="SELECT * FROM quotes LIMIT 5;"
# View quotes with contributors
wrangler d1 execute rayfirmations-db --command="SELECT text, added_by_id, created_at FROM quotes ORDER BY created_at DESC LIMIT 10;"
# Add new rayfirmation
wrangler d1 execute rayfirmations-db --command="INSERT INTO quotes (text, added_by_id) VALUES ('Your new rayfirmation here!', 'your-user-id');"
# Get total count
wrangler d1 execute rayfirmations-db --command="SELECT COUNT(*) as total FROM quotes;"
# Get count by contributor
wrangler d1 execute rayfirmations-db --command="SELECT added_by_id, COUNT(*) as count FROM quotes GROUP BY added_by_id ORDER BY count DESC;"The bot can be tested using tools like:
- ngrok for local development
- Slack's built-in testing interface
TOTAL_COUNT- KV namespace for tracking usage statisticsRAYDB- D1 database for storing rayfirmations
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License.
For issues and questions, please open an issue in the repository.