A production-ready Slack bot that stores and recalls information using pluggable memory adapters. Perfect showcase for webhook handling with codehooks.io.
- Pluggable Memory Architecture: Swap between different storage backends
- Two Memory Adapters:
SimpleMemoryAdapter: Keyword-based search using Codehooks NoSQL (no external dependencies)OpenAIVectorAdapter: Semantic search using OpenAI embeddings
- Natural Language Commands: Intuitive interaction patterns
- User-Scoped Memory: Each user has private memory storage
- TypeScript: Type-safe codebase with full type definitions
- Production Ready: Includes Slack signature verification and error handling
┌─────────────────┐
│ Slack Events │
│ (Webhooks) │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Codehooks.io │
│ Entry Point │
└────────┬────────┘
│
▼
┌─────────────────┐ ┌──────────────────────┐
│ Message Parser │──────▶│ Memory Adapter │
│ & Router │ │ (Interface) │
└─────────────────┘ └──────────┬───────────┘
│
┌────────────────┴────────────────┐
│ │
▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ SimpleAdapter │ │ OpenAIAdapter │
│ (Keyword Search) │ │ (Vector Search) │
└──────────────────┘ └──────────────────┘
│ │
▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ Codehooks NoSQL │ │ OpenAI API │
└──────────────────┘ │ + Codehooks DB │
└──────────────────┘
coho create my-slack-bot --template slack-memory-bot
cd my-slack-bot
npm install
coho deploymkdir my-slack-bot
cd my-slack-bot
coho install slack-memory-bot
npm install
coho deployYour API is now live at https://YOUR_PROJECT.api.codehooks.io/dev/
Set your environment variables using one of these methods:
Option A: Via Codehooks Studio
- Go to your project in Codehooks Studio
- Navigate to Settings → Environment Variables
- Add the following variables:
MEMORY_ADAPTERwith valuesimpleSLACK_BOT_TOKENwith valuexoxb-...SLACK_SIGNING_SECRETwith your signing secretSLACK_BOT_USER_IDwith valueU...
Option B: Via CLI
# Set up Simple adapter (default - no external dependencies)
coho set-env MEMORY_ADAPTER "simple"
# Add your Slack credentials (get from api.slack.com/apps)
coho set-env SLACK_BOT_TOKEN "xoxb-..."
coho set-env SLACK_SIGNING_SECRET "..."
coho set-env SLACK_BOT_USER_ID "U..."- Go to api.slack.com/apps → Create New App → "From an app manifest"
- Select your workspace → Next
- Copy the contents of
slack-app-manifest.jsonfrom this repo - Important: Update the
request_urlwith your deployment URL:https://YOUR_PROJECT.api.codehooks.io/dev/slack/events - Paste the manifest → Click Create
- Click Install to Workspace and authorize
- Get your credentials:
- Bot Token: OAuth & Permissions → Copy "Bot User OAuth Token"
- Signing Secret: Basic Information → Copy "Signing Secret"
- Bot User ID: App Home → Copy the Member ID under "Your App's Bot User"
Done! All scopes and event subscriptions are configured automatically.
- Go to api.slack.com/apps → Create New App → "From scratch"
- Name: "Memory Bot", select your workspace
- OAuth & Permissions → Add Bot Token Scopes:
app_mentions:read,chat:write,im:history,im:read,im:write
- Install App to workspace → Copy Bot User OAuth Token
- Event Subscriptions → Enable Events
- Request URL:
https://YOUR_PROJECT.api.codehooks.io/dev/slack/events - Subscribe to:
app_mention,message.im
- Request URL:
- Copy Signing Secret from Basic Information
- Get Bot User ID from App Home or your workspace
That's it! Your bot is ready to use.
- Codehooks.io account
- Slack workspace with admin access
- Codehooks CLI installed
- Node.js 18+ (for npm install)
Add these Bot Token Scopes:
app_mentions:read- Read messages that mention your botchat:write- Send messages as the botim:history- View messages in DMsim:read- View basic info about DMsim:write- Allow users to send DMs to the bot (required!)
Install the app to your workspace and copy the Bot User OAuth Token (starts with xoxb-)
You'll configure this after deploying to Codehooks (see step 5)
Codehooks compiles TypeScript automatically, so no build step needed!
# Initialize project in your folder
coho init YOUR_PROJECT_NAME --empty
# Deploy (Codehooks compiles TypeScript automatically)
coho deployAfter deployment, you'll get a URL like:
https://YOUR_PROJECT.api.codehooks.io/dev/
Set your environment variables using one of these methods:
Option A: Via Codehooks Studio
- Go to your project in Codehooks Studio
- Navigate to Settings → Environment Variables
- Add the required variables listed below
Option B: Via CLI
- Use the commands listed below
coho set-env SLACK_BOT_TOKEN "xoxb-your-bot-token"
coho set-env SLACK_SIGNING_SECRET "your-signing-secret"
coho set-env SLACK_BOT_USER_ID "U123456789" # Your bot's user IDcoho set-env MEMORY_ADAPTER "simple"coho set-env MEMORY_ADAPTER "openai"
coho set-env OPENAI_API_KEY "sk-..."Finding Your Values:
SLACK_BOT_TOKEN: From OAuth & Permissions pageSLACK_SIGNING_SECRET: From Basic Information pageSLACK_BOT_USER_ID: Install the bot, then go to your Slack workspace and copy the ID from the bot's profile URL
- Go to your Slack app's "Event Subscriptions" page
- Enable Events
- Set Request URL to:
https://YOUR_PROJECT.api.codehooks.io/dev/slack/events - Wait for the green "Verified" checkmark
- Subscribe to these bot events:
app_mention- When bot is @mentionedmessage.im- Direct messages to the bot
- Save Changes
- Reinstall the app to your workspace (Slack will prompt you)
Mention the bot:
@memorybot remember John likes pizza
@memorybot recall what does John like
@memorybot list my memories
@memorybot help
No need to mention the bot:
remember Sarah's birthday is May 15th
recall Sarah
list
forget abc123
clear all
| Command | Description | Example |
|---|---|---|
remember [text] |
Store a memory | remember John likes pizza |
recall [query] |
Search memories | recall pizza |
list |
Show all memories | list my memories |
forget [id] |
Delete a memory | forget abc123 |
clear all |
Delete all memories | clear all memories |
help |
Show help | help |
- Use Case: Development, demos, small-scale usage
- Search: Keyword-based matching
- Cost: Free (uses Codehooks NoSQL)
- Setup: No configuration needed (default)
coho set-env MEMORY_ADAPTER "simple"- Use Case: Production, semantic search
- Search: Vector embeddings with cosine similarity
- Cost: ~$0.02 per 1,000 memories (using
text-embedding-3-small) - Setup: Requires OpenAI API key
coho set-env MEMORY_ADAPTER "openai"
coho set-env OPENAI_API_KEY "sk-..."Semantic Search Example:
remember: "John loves Italian food"
recall: "what cuisine does John prefer?"
→ Finds the memory even with different words!
slack/
├── src/
│ ├── index.ts # Codehooks entry point
│ ├── adapters/
│ │ ├── MemoryAdapter.ts # Adapter interface
│ │ ├── SimpleMemoryAdapter.ts # Keyword search
│ │ ├── OpenAIVectorAdapter.ts # Vector search
│ │ └── index.ts # Factory
│ ├── slack/
│ │ ├── events.ts # Event handlers
│ │ ├── verification.ts # URL & signature verification
│ │ └── parser.ts # Message parsing
│ └── utils/
│ └── types.ts # TypeScript types
├── package.json
├── tsconfig.json
├── config.json # Codehooks project config
└── README.md
# Install dependencies
npm install
# Test TypeScript compilation (optional - Codehooks does this automatically)
coho compile
# Optional: Local type checking with tsc
npm run buildNote:
- Codehooks compiles TypeScript automatically on deployment
coho compiletests compilation without deploying- The
tsconfig.jsoncan be auto-generated by Codehooks or customized manually
Test the health endpoint:
curl https://YOUR_PROJECT.api.codehooks.io/dev/healthView logs:
coho logs --follow- Create a new adapter class implementing
MemoryAdapterinterface - Add it to
src/adapters/index.ts - Update the factory function to support your adapter type
- Document environment variables needed
Example skeleton:
export class CustomAdapter implements MemoryAdapter {
getName(): string {
return 'CustomAdapter';
}
async remember(userId: string, content: string): Promise<Memory> {
// Your implementation
}
async recall(userId: string, query: string): Promise<Memory[]> {
// Your implementation
}
// ... implement other methods
}- Ensure your Codehooks deployment is successful
- Check that the URL is correct:
https://YOUR_PROJECT.api.codehooks.io/dev/slack/events - Check logs:
coho logs
- Verify bot token is set:
coho env list - Check that bot has correct OAuth scopes
- Verify event subscriptions are configured
- Check Slack app is installed in workspace
- Review logs:
coho logs --follow
- Verify API key is valid:
coho env list - Check OpenAI account has credits
- Review error messages in logs
- Ensure
SLACK_SIGNING_SECRETis set correctly - Check timestamp drift (server time sync)
- ✅ Slack signature verification prevents unauthorized requests
- ✅ User-scoped memory prevents data leakage between users
- ✅ Environment variables for sensitive credentials
- ✅ No authentication needed for webhook endpoints (Slack verifies)
- ✅ Bot token stored securely in Codehooks environment
- SimpleAdapter: ~10-50ms per query (depends on memory count)
- OpenAIAdapter: ~200-500ms per query (includes API call)
- Scalability: Codehooks auto-scales; consider vector DB for 10,000+ memories per user
- Add Memvid adapter (Python bridge)
- Support for attachments/images
- Workspace-wide memory sharing option
- Memory expiration (TTL)
- Export memories to JSON/CSV
- Analytics dashboard
MIT
This project showcases codehooks.io capabilities:
- Webhook handling (Slack Events API)
- NoSQL database (memory storage)
- Environment variables (configuration)
- TypeScript support
- Serverless deployment
- Auto-scaling
Perfect for building webhook integrations with Slack, Stripe, GitHub, and more!