Public
Like
discord-bot
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.
Viewing readonly version of main branch: v22View latest version
This project is a Discord bot that analyzes direct messages between two users (e.g., you and your partner), particularly focusing on:
- Tracking and categorizing shared links
- Searching conversation history
- Summarizing discussions on specific topics
- Analyzing furniture-related discussions
The project is structured to work with Val.town and has the following components:
- Database Layer: Uses Val.town's built-in SQLite database
- AI Integration: Leverages Anthropic's Claude API for analysis
- Discord Integration:
- Bot token for fetching messages
- Slash commands for user interactions
- Webhook endpoint for Discord interactions
- API Endpoints: Various endpoints for manual operations and automation
To run this project on Val.town, you need to set up the following environment variables:
DISCORD_TOKEN
: Your Discord bot tokenDISCORD_CLIENT_ID
: Your Discord application IDDISCORD_PUBLIC_KEY
: Public key for verifying Discord interactionsDISCORD_USER_ID
: Your Discord user IDSPOUSE_USER_ID
: Your partner's Discord user IDANTHROPIC_API_KEY
: Your Anthropic API key
- Create a Discord application: https://discord.com/developers/applications
- Add a bot to your application
- Set the required permissions:
- Read Messages/View Channels
- Read Message History
- Send Messages
- Enable the Message Content Intent in the Bot section
- Use the
OAuth2 URL Generator
to create an invite link with thebot
scope - Add the bot to a server where both you and your partner are members
- Create a new Val on Val.town
- Copy the contents of the backend directory
- Set up the required environment variables
- Create a cron schedule for periodically fetching messages and processing links
GET /health
: Check if the service is runningPOST /api/interactions
: Discord interactions endpointPOST /api/fetch-dms
: Manually trigger DM fetchingPOST /api/process-links
: Manually trigger link processingPOST /api/query
: Process a query about your messagesPOST /api/commands/search
: Endpoint for search commandsPOST /api/register-commands
: Register Discord slash commandsGET /api/cron/fetch-dms
: Cron endpoint for fetching DMsGET /api/cron/process-links
: Cron endpoint for processing links
The bot provides several slash commands:
/search [query]
: Search your conversation history/links [category]
: Find links shared in conversations, optionally filtered by category/categories
: List all available link categories/analyze [query]
: Perform a deeper analysis of your conversations
- Clone the repository
- Create a
.env
file with the required environment variables - Install dependencies with
deno cache --reload index.ts
- Run locally with
deno run --allow-net --allow-env index.ts
A basic frontend is provided in the frontend
directory. For now, we're focusing on the backend functionality, but the frontend can be extended to provide a web interface for searching and visualizing conversation data.
- The database uses Val.town's built-in SQLite database
- The code uses Deno and ESM modules compatible with Val.town
- HTTP endpoints are designed to work with Val.town's serverless model
- Discord verification is implemented according to Discord's security requirements
This project was ported from a Node.js implementation to work specifically with Val.town's environment.