|
| 1 | +--- |
| 2 | +title: Twitch Setup |
| 3 | +description: Connect Spacebot to Twitch chat. |
| 4 | +--- |
| 5 | + |
| 6 | +# Twitch Setup |
| 7 | + |
| 8 | +Connect Spacebot to Twitch chat. Takes about 5 minutes. |
| 9 | + |
| 10 | +You need a **Twitch account** for the bot and an **OAuth token**. |
| 11 | + |
| 12 | +## Step 1: Create a Twitch Account |
| 13 | + |
| 14 | +Create a Twitch account for your bot (or use an existing one). The bot will send messages as this account. |
| 15 | + |
| 16 | +## Step 2: Get an OAuth Token |
| 17 | + |
| 18 | +Go to [twitchapps.com/tmi](https://twitchapps.com/tmi/) and authorize with the bot account. You'll get a token that looks like `oauth:abc123def456...`. |
| 19 | + |
| 20 | +<Callout type="info"> |
| 21 | +For production use, you can create a Twitch application at [dev.twitch.tv/console/apps](https://dev.twitch.tv/console/apps) and generate tokens with the `chat:read` and `chat:edit` scopes via the OAuth flow. The TMI token generator is fine for getting started. |
| 22 | +</Callout> |
| 23 | + |
| 24 | +## Step 3: Add Credentials to Spacebot |
| 25 | + |
| 26 | +<Tabs items={["Spacebot UI", "TOML Config"]}> |
| 27 | +<Tab value="Spacebot UI"> |
| 28 | + |
| 29 | +1. Open your Spacebot dashboard |
| 30 | +2. Go to **Settings** → **Messaging Platforms** |
| 31 | +3. Click **Setup** on the Twitch card |
| 32 | +4. Enter the bot's **username** and **OAuth token** |
| 33 | +5. Click **Save** |
| 34 | + |
| 35 | +Spacebot connects immediately — no restart needed. |
| 36 | + |
| 37 | +</Tab> |
| 38 | +<Tab value="TOML Config"> |
| 39 | + |
| 40 | +```toml |
| 41 | +[messaging.twitch] |
| 42 | +enabled = true |
| 43 | +username = "my_bot" |
| 44 | +oauth_token = "oauth:abc123def456..." |
| 45 | +channels = ["somechannel", "anotherchannel"] |
| 46 | +``` |
| 47 | + |
| 48 | +You can also reference environment variables: |
| 49 | + |
| 50 | +```toml |
| 51 | +[messaging.twitch] |
| 52 | +enabled = true |
| 53 | +username = "env:TWITCH_BOT_USERNAME" |
| 54 | +oauth_token = "env:TWITCH_OAUTH_TOKEN" |
| 55 | +channels = ["somechannel"] |
| 56 | +``` |
| 57 | + |
| 58 | +Token changes in config require a restart. |
| 59 | + |
| 60 | +</Tab> |
| 61 | +</Tabs> |
| 62 | + |
| 63 | +## Step 4: Join Channels |
| 64 | + |
| 65 | +Specify which Twitch channels the bot should join. Channel names are case-insensitive and should not include the `#` prefix. |
| 66 | + |
| 67 | +<Tabs items={["Spacebot UI", "TOML Config"]}> |
| 68 | +<Tab value="Spacebot UI"> |
| 69 | + |
| 70 | +Add channel names in the **Channels** tag input on the Twitch binding form. |
| 71 | + |
| 72 | +</Tab> |
| 73 | +<Tab value="TOML Config"> |
| 74 | + |
| 75 | +```toml |
| 76 | +[messaging.twitch] |
| 77 | +channels = ["streamer_name", "another_channel"] |
| 78 | +``` |
| 79 | + |
| 80 | +</Tab> |
| 81 | +</Tabs> |
| 82 | + |
| 83 | +## Verify It's Working |
| 84 | + |
| 85 | +The Twitch card on the Settings page shows a green status dot when connected. Send a message (or a trigger command if you configured one) in a joined channel — you should see the bot reply. |
| 86 | + |
| 87 | +## Trigger Prefix |
| 88 | + |
| 89 | +Twitch channels can be extremely high-volume. By default the bot responds to every message, which is probably not what you want in a busy stream. |
| 90 | + |
| 91 | +Set a trigger prefix so the bot only responds to messages that start with it: |
| 92 | + |
| 93 | +<Tabs items={["Spacebot UI", "TOML Config"]}> |
| 94 | +<Tab value="Spacebot UI"> |
| 95 | + |
| 96 | +The trigger prefix is configured in the TOML config file. |
| 97 | + |
| 98 | +</Tab> |
| 99 | +<Tab value="TOML Config"> |
| 100 | + |
| 101 | +```toml |
| 102 | +[messaging.twitch] |
| 103 | +trigger_prefix = "!ask" |
| 104 | +``` |
| 105 | + |
| 106 | +With this config, the bot ignores all messages except those starting with `!ask`. The prefix is stripped before processing — if someone types `!ask what is rust?`, the bot sees `what is rust?`. |
| 107 | + |
| 108 | +Set to an empty string or omit to respond to all messages. |
| 109 | + |
| 110 | +</Tab> |
| 111 | +</Tabs> |
| 112 | + |
| 113 | +## Filtering |
| 114 | + |
| 115 | +### Restrict to specific channels |
| 116 | + |
| 117 | +By default the bot responds in every channel it joins. To route specific channels to specific agents, add channel names to your bindings. |
| 118 | + |
| 119 | +<Tabs items={["Spacebot UI", "TOML Config"]}> |
| 120 | +<Tab value="Spacebot UI"> |
| 121 | + |
| 122 | +Go to **Settings** → **Bindings** tab and add channel names to your Twitch binding. |
| 123 | + |
| 124 | +</Tab> |
| 125 | +<Tab value="TOML Config"> |
| 126 | + |
| 127 | +```toml |
| 128 | +[[bindings]] |
| 129 | +agent_id = "main" |
| 130 | +channel = "twitch" |
| 131 | +channel_ids = ["streamer_name"] |
| 132 | +``` |
| 133 | + |
| 134 | +If `channel_ids` is empty or omitted, the bot responds in all joined channels. |
| 135 | + |
| 136 | +</Tab> |
| 137 | +</Tabs> |
| 138 | + |
| 139 | +### User filtering |
| 140 | + |
| 141 | +Restrict which Twitch users can interact with the bot by adding login names to the binding's allowed users list. |
| 142 | + |
| 143 | +<Tabs items={["Spacebot UI", "TOML Config"]}> |
| 144 | +<Tab value="Spacebot UI"> |
| 145 | + |
| 146 | +Add Twitch usernames to the **DM Allowed Users** list on the binding form. |
| 147 | + |
| 148 | +</Tab> |
| 149 | +<Tab value="TOML Config"> |
| 150 | + |
| 151 | +```toml |
| 152 | +[[bindings]] |
| 153 | +agent_id = "main" |
| 154 | +channel = "twitch" |
| 155 | +dm_allowed_users = ["trusted_user", "another_mod"] |
| 156 | +``` |
| 157 | + |
| 158 | +When the list is empty (default), all users can interact. Permission changes hot-reload within a couple seconds — no restart needed. |
| 159 | + |
| 160 | +</Tab> |
| 161 | +</Tabs> |
| 162 | + |
| 163 | +### Multiple channels, multiple agents |
| 164 | + |
| 165 | +Route different Twitch channels to different agents. |
| 166 | + |
| 167 | +<Tabs items={["Spacebot UI", "TOML Config"]}> |
| 168 | +<Tab value="Spacebot UI"> |
| 169 | + |
| 170 | +Create multiple bindings in the **Bindings** tab, each with different channel names and agents. |
| 171 | + |
| 172 | +</Tab> |
| 173 | +<Tab value="TOML Config"> |
| 174 | + |
| 175 | +```toml |
| 176 | +[[bindings]] |
| 177 | +agent_id = "main" |
| 178 | +channel = "twitch" |
| 179 | +channel_ids = ["my_stream"] |
| 180 | + |
| 181 | +[[bindings]] |
| 182 | +agent_id = "support-bot" |
| 183 | +channel = "twitch" |
| 184 | +channel_ids = ["help_channel"] |
| 185 | +``` |
| 186 | + |
| 187 | +Each agent has its own memory, identity, and conversation history. |
| 188 | + |
| 189 | +</Tab> |
| 190 | +</Tabs> |
| 191 | + |
| 192 | +## Conversations |
| 193 | + |
| 194 | +Each Twitch channel maps to a single conversation (`twitch:<channel_name>`). Unlike Discord or Slack, Twitch chat has no threads — all messages in a channel share one conversation context. |
| 195 | + |
| 196 | +## Limitations |
| 197 | + |
| 198 | +- **No streaming** — Twitch IRC doesn't support message editing, so responses are sent as complete messages rather than streamed word-by-word. |
| 199 | +- **Text only** — File attachments are sent as `[File: filename]` text notices since Twitch chat doesn't support media. |
| 200 | +- **500 character limit** — Long responses are automatically split into multiple messages. |
| 201 | +- **No history backfill** — Twitch IRC doesn't provide message history, so new conversations start fresh. |
| 202 | +- **Rate limits** — Twitch limits bots to ~20 messages per 30 seconds (100 if the bot account is a verified bot or moderator in the channel). |
| 203 | + |
| 204 | +## Troubleshooting |
| 205 | + |
| 206 | +| Symptom | Cause | Fix | |
| 207 | +|---------|-------|-----| |
| 208 | +| `Login authentication failed` | Invalid OAuth token | Generate a fresh token at [twitchapps.com/tmi](https://twitchapps.com/tmi/) | |
| 209 | +| Bot connects but doesn't respond | Trigger prefix set | Messages must start with the configured prefix (e.g. `!ask`) | |
| 210 | +| Bot responds to everything | No trigger prefix | Set `trigger_prefix` in the config to limit when the bot responds | |
| 211 | +| Messages getting dropped | Rate limit | Reduce response frequency or get the bot account verified | |
| 212 | +| Bot doesn't join channel | Wrong channel name | Use the login name (lowercase), not the display name | |
0 commit comments