- Public - Read-only queries accessible without authentication
- Authenticated - Functions requiring user authentication
- Private - Internal functions for bot and admin operations
Function Organization
All Convex functions are located inpackages/database/convex/ and organized by access level:
Public Functions
Public functions are read-only queries that don’t require authentication. They use thepublicQuery wrapper which provides caching and rate limiting.
Custom Function Wrapper
All public functions use thepublicQuery wrapper defined in /convex/public/custom_functions.ts:
Automatically includes these fields in addition to your custom args:
Enhanced context with caching capabilities:
ctx.cache.getMessage(id)- Get cached messagectx.cache.getChannel(id)- Get cached channelctx.cache.getServer(id)- Get cached serverctx.cache.getChannelSettings(id)- Get cached channel settings- Standard Convex
ctx.dbfor database access
Message Queries
Defined in/convex/public/messages.ts
getMessages
Get paginated messages from a channel.Discord channel ID
Message ID to start after (for pagination)
Convex pagination options
Array of enriched messages with author and attachment data
Whether pagination is complete
Cursor for next page
getMessagePageHeaderData
Get all data needed to render a message page header.Discord message ID
The canonical ID for the thread/message
The first message in the thread
The marked solution message, if any
Server information including name, icon, customDomain, etc.
Channel information including name, type, availableTags
Thread information if this is a thread
Number of replies in the thread
IDs of tags applied to the thread
getMessageAsSearchResult
Get a message formatted as a search result.Server Queries
Defined in/convex/public/servers.ts
getServerByDomain
Get server information by custom domain.getServerByDiscordId
Get server information by Discord server ID.Channel Queries
Defined in/convex/public/channels.ts
getChannelById
Get channel information and settings.Channel data including name, type, parent channel, and available tags
Channel settings including indexingEnabled, markSolutionEnabled, etc.
Search Queries
Defined in/convex/public/search.ts
searchMessages
Search messages across indexed servers and channels.Authenticated Functions
Authenticated functions require a valid user session. They use custom wrappers that validate authentication:Guild Manager Functions
Defined in/convex/client/guildManager.ts
These functions are for users with “Manage Guild” permissions on a Discord server.
getThreadsForServer
Get paginated threads for a server.Discord server ID (auto-injected from auth)
Pagination options
Sort order for threads (default: “newest”)
Array of threads with:
thread- Thread channel datamessage- First message in threadparentChannel- Parent channel infotags- Applied forum tags
User Server Settings
Defined in/convex/authenticated/user_server_settings.ts
getUserServerSettings
Get user-specific settings for a server.updateUserServerSettings
Update user server settings.Private Functions
Private functions are for internal use by the Discord bot, API keys, and admin operations. They provide full read/write access.Message Functions
Defined in/convex/private/messages.ts
upsertMessage
Insert or update a message.Discord server ID
Discord channel ID
Discord message ID
Discord user ID of author
Message text content
Skip validation checks (default: false)
markMessageAsSolution
Mark a message as the solution to a question.ID of the question message
ID of the solution message
unmarkSolution
Remove solution marking from a message.Server Functions
Defined in/convex/private/servers.ts
upsertServer
Insert or update a Discord server.getServerByDiscordId
Get full server data by Discord ID.Channel Functions
Defined in/convex/private/channels.ts
upsertChannel
Insert or update a channel.updateChannelSettings
Update channel settings.Discord Account Functions
Defined in/convex/private/discord_accounts.ts
upsertDiscordAccount
Insert or update a Discord account.Data Access Patterns
Caching
Public queries include an enhanced context with caching:Pagination
Use Convex’s built-in pagination:Enrichment
Use helper functions to enrich data with relationships:Access Control
Backend Access Tokens
For server-to-server API calls, use backend access tokens:Guild Manager Permissions
Guild manager functions automatically check if the user has “Manage Guild” permission:API Key Access
API key functions validate the key before executing:Database Schema
Core Tables
- messages - Discord messages
- channels - Discord channels and threads
- servers - Discord servers/guilds
- discord_accounts - Discord user accounts
- channel_settings - Per-channel configuration
- server_preferences - Per-server settings
- user_server_settings - User-specific server settings
- threadTags - Forum thread tags
- attachments - Message attachments
Indexes
Key indexes for performance:messages.by_channelId_and_id- Get messages in a channelmessages.by_serverId- Get all server messageschannels.by_serverId_and_id- Get server channelsthreadTags.by_threadId- Get tags for a thread