Skip to main content

Bot Control

Overview

The Bot Control dashboard allows users to manage their chat bots across all platforms (Twitch, YouTube, Kick, Trovo) and Discord servers from a single page. Users can pause/resume bots per platform, trigger reconnects, and manage Discord server connections with feature-channel mappings.

Chat Bot Control

Per-platform bot management at /dashboard/bots:

  • Status: Active (bot_enabled=true + channel connection exists), Paused (bot_enabled=false), No Connection
  • Toggle: Pause/Resume bot for a platform via toggleBotForPlatform mutation (updates bot_enabled on channel_connections)
  • Reconnect: Send bot_join action via Redis pub/sub to trigger immediate channel rejoin

Database

channel_connections.bot_enabled (BOOLEAN, default true) — when false, bots ignore this channel during sync.

API

TypeEndpointPermission
GraphQL QuerybotStatusbot-connections:read
GraphQL MutationtoggleBotForPlatform(platform, enabled)bot-connections:create
GraphQL MutationrejoinBot(platform)bot-connections:create
RESTGET /bot-statusbot-connections:read
RESTPOST /bot-togglebot-connections:create
RESTPOST /bot-rejoinbot-connections:create
System QuerybotChannels(platform)System key only

Bot Worker Actions

All chat bots listen for Redis pub/sub actions on lumio:bot:action:{platform}:{account_id}:

  • bot_join / bot_sync — Log and let periodic sync apply changes
  • bot_leave — Immediately remove account's channels from in-memory map + clear Redis cache

Discord Server Mapping

Discord guilds are mapped to Lumio accounts via discord_guild_connections table.

Tables

  • discord_guild_connections — guild_id → account_id mapping (UNIQUE on guild_id)
  • discord_guild_settings — per-guild JSONB settings
  • discord_guild_channel_mappings — feature → Discord channel routing (live_notification, event_feed, chat_mirror, etc.)

OAuth Flow

  1. User clicks "Add Server" → authorizeDiscordGuild mutation generates Discord OAuth URL
  2. Discord redirects to /api/discord-guilds/callback
  3. Callback calls exchangeDiscordGuild mutation via serverGql
  4. Guild connection created in DB
  5. Discord bot receives GuildCreate event → caches channels/roles/features in Redis, updates guild name/icon in DB

Redis Cache

KeyContentTTL
lumio:discord_guild:{guild_id}account_id1h
lumio:discord_guild:{guild_id}:channelsJSON array of channels1h
lumio:discord_guild:{guild_id}:rolesJSON array of roles1h
lumio:discord_guild:{guild_id}:featuresJSON array of feature mappings1h
lumio:discord_channel_guild:{channel_id}guild_id (reverse lookup)1h

Feature-Channel Mappings

Predefined features (extensible without migration):

Feature KeyDescription
live_notificationStream live alerts
event_feedFollows, subs, donations
chat_mirrorPlatform chat → Discord
announcementAnnouncements
moderation_logBan/timeout logs
clip_feedNew clips

API

TypeEndpointPermission
GraphQL QuerydiscordGuildConnectionsbot-connections:read
GraphQL MutationauthorizeDiscordGuildbot-connections:create
GraphQL MutationexchangeDiscordGuild(...)bot-connections:create
GraphQL MutationdisconnectDiscordGuild(guildId)bot-connections:delete
GraphQL QuerydiscordGuildChannels(guildId)bot-connections:read
GraphQL QuerydiscordGuildRoles(guildId)bot-connections:read
GraphQL QuerydiscordGuildFeatures(guildId)bot-connections:read
GraphQL MutationsetDiscordGuildFeature(...)bot-connections:create
System QuerydiscordBotGuildsSystem key only
System MutationupdateDiscordGuildInfo(...)System key only
System MutationremoveDiscordGuildByBot(guildId)System key only

Admin

Admin permissions: bot-control:read/edit, discord-guilds:read/delete (enforced via require_admin_permission).

  • /admin/bot-control — View/toggle bots per account
  • /admin/discord-guilds — View all guild-to-account mappings, delete connections

Security

  • Guild ownership verified before channel/role queries
  • Channel ownership verified in Discord bot actions (post_message)
  • GuildDelete with unavailable=true only cleans cache, preserves DB
  • Admin middleware on API routes
  • Snowflake validation on all Discord IDs
  • UUID validation on action listener account_id

Key Files

PathDescription
apps/api/src/graphql/bot_connections.rsGraphQL queries and mutations for bot status/toggle/rejoin
apps/api/src/graphql/discord_guilds.rsGraphQL for Discord guild management
apps/api/src/db/discord_guilds.rsDatabase operations for Discord guilds
apps/discord-bot/src/handlers/events.rsDiscord bot gateway event handling
crates/lo-bot-modules/Bot module system used by all chat bots

See Also