Skip to content
DireWork

Twitch integration setup

Create a Twitch application, sign in, and connect your bot account

This guide walks you through every step of setting up Twitch integration for DireWork — from creating the Twitch application to connecting your bot account.

Overview

DireWork uses Twitch OAuth for two things:

  1. Streamer login — You sign in with your main Twitch account
  2. Bot account — A separate Twitch account that reads and sends chat messages

Both use the same Twitch application, but different redirect URLs.


Step 1: Create a Twitch application

  1. Go to the Twitch Developer Console
  2. Log in with your main Twitch account (the streamer account)
  3. Click Applications in the left sidebar
  4. Click Register Your Application

Twitch only lets accounts with two-factor authentication register applications. If the console asks you to enable it, turn it on under Twitch Settings → Security and Privacy, then come back.

Fill in the application details

FieldValue
NameDireWork (or any name you want)
OAuth Redirect URLsSee below
CategoryBroadcasting Suite
Client TypeConfidential

Add redirect URLs

You need to add two redirect URLs. Click the + Add button for each:

For local development:

http://localhost:3001/api/auth/callback/twitch
http://localhost:3001/api/bot/callback/twitch

For production (add these too if you plan to deploy — swap in your workers.dev subdomain):

https://dirework.<your-subdomain>.workers.dev/api/auth/callback/twitch
https://dirework.<your-subdomain>.workers.dev/api/bot/callback/twitch

The redirect URLs must match exactly — including the protocol (http vs https), port number, and path. A mismatch will cause "Invalid redirect URI" errors.

  1. Click Create

Copy your credentials

After creating the app:

  1. You'll see the Client ID on the application page — copy it
  2. Click New Secret to generate a Client Secret
  3. Copy the secret immediately — it's only shown once

If you lose the client secret, you'll need to generate a new one by clicking New Secret again. This will invalidate the old secret.


Step 2: Configure environment variables

Create or edit your packages/infra/.env file (copy it from .env.example if you haven't yet) and add the Twitch credentials:

# Twitch OAuth (from dev.twitch.tv)
TWITCH_CLIENT_ID="paste_your_client_id_here"
TWITCH_CLIENT_SECRET="paste_your_client_secret_here"

Your complete .env should look like this:

# Better Auth
BETTER_AUTH_SECRET="generate-a-random-32-character-string"
BETTER_AUTH_URL="http://localhost:3001"
CORS_ORIGIN="http://localhost:3001"

# Twitch OAuth
TWITCH_CLIENT_ID="abc123def456..."
TWITCH_CLIENT_SECRET="xyz789..."

Generate a strong secret with:

openssl rand -base64 32

BETTER_AUTH_URL must match the origin you used in your Twitch redirect URLs. For local dev, that's http://localhost:3001.


Step 3: Sign in

  1. Start the app with bun run dev
  2. Open http://localhost:3001
  3. On a fresh install you'll land on the setup screen — click Claim with Twitch
  4. You'll be redirected to Twitch — authorize the app with your streamer account
  5. After authorizing, you'll land on the dashboard as the instance owner

If sign-in fails, check:

  • Your TWITCH_CLIENT_ID and TWITCH_CLIENT_SECRET are correct
  • The redirect URL http://localhost:3001/api/auth/callback/twitch is in your Twitch app
  • BETTER_AUTH_URL is set to http://localhost:3001

Step 4: Create a bot account on Twitch

The bot account is the Twitch account that sends messages in your chat. A separate bot account is recommended. Using your own streamer account also works, but every bot reply will then come from you.

Create the bot account

  1. Open a private/incognito browser window (so you don't get logged out of your main account)
  2. Go to twitch.tv
  3. Click Sign Up and create a new account
    • Choose a name like YourNameBot or DireWorkBot
    • You'll need a different email address
  4. Complete the account setup (verify email, etc.)

Twitch allows multiple accounts. The bot account is just a regular Twitch account that DireWork uses to send chat messages.

In your main streamer account's chat, type:

/mod YourBotUsername

This prevents the bot from being rate-limited when sending messages.


Step 5: Connect the bot account

  1. Go to Bot settings at http://localhost:3001/dashboard/bot (the bot chip in the dashboard's header links there too)
  2. Find the Bot account card
  3. Click Connect bot account
  4. You'll be redirected to Twitch — sign in with the bot account (not your streamer account, unless you chose to use it as the bot)
  5. Authorize the app
  6. You'll be redirected back to Bot settings (/dashboard/bot?bot=connected) with a success message

The bot will have chat:read and chat:edit permissions (plus the Helix chat scopes user:read:chat and user:write:chat) — enough to read messages and respond to commands — and moderator:read:followers for the follower check below.

One more thing before the bot talks: the bot runs in a token-gated browser page, not on a server. Copy its URL from Dashboard → Bot and keep it open: the invisible widget in an OBS browser source or a Moblin widget, or the dock in an OBS custom browser dock or a pinned tab. The bot listens to chat only while that page is open. See Chat commands for the full command list.

Where to keep the bot page

Pick one. The dashboard's Set up streaming card and the Run the bot card on Dashboard → Bot ask How will you run the bot? and show the URL for your pick (Widget URL or Dock URL) with its steps. Both carry the same secret token, so treat them like a stream key, and run one or the other: only one bot page joins chat at a time. Open a second copy and it stands by (tab title DireWork bot · Standby); the dock version shows The bot is running somewhere else with a Take over button that moves the bot to it. A standby page takes over on its own once the running page closes. While a page runs the bot, the dashboard's bot chip says Bot connected.

OptionURLNotes
Widget…/bot/<token>A blank, transparent page: nothing shows on stream, so it can sit on any scene at any size. Add it as an OBS browser source (untick Shutdown source when not visible) or a Moblin browser widget (keep it in a scene that stays loaded). Its browser tab title says the state, such as DireWork bot · Connected.
Dock / browser tab…/bot/<token>?view=dockA narrow control panel styled like OBS's dark theme: status light, muted state, timer and bot buttons, last error, recent commands and a Reconnect button. Mute bot / Unmute bot and Reconnect stay pinned at the top, so they're reachable even in a short dock. Add it as an OBS custom browser dock, or open it in a browser tab and pin the tab.

Either page can stay open while you update DireWork. It picks up alias changes, and new commands from an update, within an hour; reload it (or refresh the OBS browser source) to use them right away.

The widget never shows errors on stream. If the bot stops (the URL was reset, or Twitch no longer accepts the bot's login), the dock shows why, and Dashboard → Bot is where you fix it.

OBS 31+ is recommended. OBS 28–30 is untested; OBS 27.1's Chromium 75-era browser source can't run DireWork's bundles.

Add the dock (Windows, macOS and Linux X11):

  1. In OBS, open Docks → Custom Browser Docks (older versions: View → Docks → Custom Browser Docks).
  2. Give it a name such as DireWork Bot, paste the Dock URL, and click Apply.
  3. Drag the dock where you want it. If it's in the way, tab it behind another dock.

Don't close the dock. Closing it (the X, or unticking it in the Docks menu) unloads the page and stops the bot until you open the dock again. A dock tabbed behind another one keeps running.

Dock buttons. Each button sends a chat command as you (the broadcaster), exactly as if you'd typed it, but the bot's reply shows in the dock instead of chat:

ButtonSends
Start, Pause, Resume, Skip, Reset!timer start, !timer pause, !timer resume, !timer skip, !timer reset
Mute bot / Unmute bot!mute / !unmute
Clear done!clear done
  • Reset and Clear done ask before they run.
  • The dock doesn't watch the timer, so all five timer buttons always show. A button that doesn't apply right now gets the same answer a mod would in chat (for example, "not running").
  • While muted, only Unmute bot works: a muted bot ignores every other command.
  • The buttons turn on once the bot is connected. If a timer or task command is turned off in Dashboard → Bot, its button sends but the bot has no reply.

Streaming from a phone? Add the Widget URL as a browser widget in an app that draws web pages on the stream, such as Moblin (iOS 16.4+ / Safari 16.4+); the bot runs while that widget's scene is loaded. If your phone instead sends its feed to a PC or cloud OBS (SRT, RTMP) that goes live to Twitch, add the widget or the dock on that OBS. Apps with no browser widget that stream straight to Twitch can't keep the bot running.

OAuth scopes

DireWork requests specific OAuth scopes for each connection type:

ConnectionScopesPurpose
Streamer loginopenidAuthentication, profile info (no email)
Bot accountchat:read, chat:editRead and send chat messages over IRC (the connection the bot page actually uses)
Bot accountuser:read:chat, user:write:chatHelix chat API equivalents — reserved for a future move to Helix sends
Bot accountmoderator:read:followersCheck whether a viewer follows you, for Who can add tasks → Followers. Twitch answers only when the bot is a mod in your chat

You don't need to configure scopes manually — DireWork requests them automatically during the OAuth flow. The scopes are minimal by design: only what's needed for the bot to read and write chat messages.

Connected your bot before chat:read/chat:edit were added? Existing tokens don't gain scopes automatically — disconnect the bot account and connect it again to pick up the new scopes.

Connected your bot before the follower check? It keeps working exactly as before. Only Who can add tasks → Followers needs the new permission: click Reconnect the bot where Bot settings asks, or Connect bot account again with the same account.

If connection fails

Common issues:

ErrorSolution
Token exchange failedCheck that http://localhost:3001/api/bot/callback/twitch is in your Twitch app's redirect URLs
Redirected to home pageMake sure you're logged in to DireWork first
No error but nothing happenedCheck the browser console and server logs for details
"Invalid redirect URI" on TwitchThe redirect URL in your Twitch app doesn't match exactly — check for trailing slashes, wrong port, or http vs https

The most common issue is a redirect URL mismatch. The URL {BETTER_AUTH_URL}/api/bot/callback/twitch must exactly match one of the redirect URLs in your Twitch Developer Console app.


Step 6: Set up OBS overlays

After signing in, your dashboard shows both overlay URLs in OBS sources, under the timer controls:

  1. Copy the Timer overlay URL
  2. In OBS, add a Browser Source
  3. Paste the overlay URL (it looks like http://localhost:3001/overlay/t/YOUR_TOKEN)
  4. Set width and height to 300 (the timer scales to fill the source; use 700 x 800 for the task list)
  5. Check "Shutdown source when not visible"
  6. Repeat with the Tasks tab's Tasks overlay URL

See the Overlays guide for more details.


Redirect URLs reference

URL PatternPurposeWhen it's used
{BETTER_AUTH_URL}/api/auth/callback/twitchStreamer loginWhen you sign in with Twitch
{BETTER_AUTH_URL}/api/bot/callback/twitchBot account connectionWhen you click "Connect bot account"

For local development, BETTER_AUTH_URL = http://localhost:3001

For production, replace with your web worker's origin (e.g., https://dirework.<your-subdomain>.workers.dev)


Who can sign in?

You don't need to configure access. DireWork is single-owner: the first Twitch account to sign in claims the instance, and after that no one else can take it over.

Until that first sign-in, though, any Twitch user who opens your instance's URL can claim it. Sign in as soon as your first deploy finishes and don't share the URL before then. If someone else claimed it, follow Recovering an instance someone else claimed.


Production checklist

When deploying to production, make sure to:

  • Set BETTER_AUTH_URL and CORS_ORIGIN to your web worker's origin — for GitHub Actions deploys, set these as GitHub repository variables (repo Settings → Secrets and variables → Actions → Variables); the deploy job consumes them via ${{ vars.* }} in deploy.yml — don't edit the workflow file itself
  • Add production redirect URLs to your Twitch app:
    • https://dirework.<your-subdomain>.workers.dev/api/auth/callback/twitch
    • https://dirework.<your-subdomain>.workers.dev/api/bot/callback/twitch
  • Use https:// (not http://) for all production URLs

The full walkthrough lives in the Deployment guide.