Skip to main content

Twitch Integration

Connect your Twitch accounts to enable chat bots, channel management, and real-time event tracking.

Setup

Prerequisites

  1. A Twitch application registered at dev.twitch.tv
  2. Configure your OAuth redirect URI in Twitch: {server.public_url}/v1/integrations/callback/twitch
  3. Note your Client ID and Client Secret

Configuration

[server]
# The redirect URI is automatically built from this: {public_url}/v1/integrations/callback/twitch
public_url = "https://your-domain.com"

[integrations.twitch]
client_id = "your_twitch_client_id"
client_secret = "your_twitch_client_secret"

Or via environment variables:

SERVER_PUBLIC_URL=https://your-domain.com
TWITCH_INTEGRATION_CLIENT_ID=your_client_id
TWITCH_INTEGRATION_CLIENT_SECRET=your_client_secret
Redirect URI

The OAuth redirect URI is automatically constructed from server.public_url: {server.public_url}/v1/integrations/callback/twitch

Make sure to add this exact URL to your Twitch application's OAuth Redirect URLs.

OAuth Scopes

Channel Scopes

Scopes requested for channel (broadcaster) accounts:

ScopeDescriptionRequired
channel:manage:broadcastUpdate stream title, game, tagsYes
channel:read:stream_keyRead stream keyNo
channel:manage:scheduleManage streaming scheduleYes
channel:read:subscriptionsRead subscriber listYes
channel:manage:redemptionsManage channel points rewardsYes
channel:read:redemptionsView channel points redemptionsYes
bits:readView bits leaderboardYes
channel:manage:moderatorsAdd/remove moderatorsYes
channel:read:vipsView VIP listYes
channel:manage:vipsManage VIPsYes
channel:moderatePerform moderation actionsYes
moderator:read:followersRead follower listYes
channel:read:pollsView pollsYes
channel:manage:pollsCreate/end pollsYes
channel:read:predictionsView predictionsYes
channel:manage:predictionsCreate/resolve predictionsYes
channel:read:hype_trainView hype train eventsYes
channel:manage:raidsStart/cancel raidsYes
channel:read:adsRead ad scheduleYes
channel:manage:adsRun adsYes
channel:read:charityRead charity campaignYes
channel:read:goalsRead channel goalsYes
channel:read:guest_starRead Guest Star sessionsYes
channel:manage:guest_starManage Guest Star sessionsYes
Bot Badge Authorization

For bots to display the verified bot badge when chatting in your channel, the channel account must separately authorize the channel:bot scope. This can be done by adding it to the custom scopes when connecting or reconnecting the channel integration.

Bot Scopes

Scopes requested for bot accounts:

ScopeDescriptionRequired
user:botBot identityYes
user:read:chatRead chat messages via EventSubYes
user:write:chatSend chat messages via Helix APIYes
moderator:read:chat_messagesRead moderated chat messagesNo
moderator:manage:chat_messagesDelete chat messagesNo
moderator:manage:banned_usersBan/unban usersNo
moderator:read:blocked_termsView blocked termsNo
moderator:manage:blocked_termsManage blocked termsNo
moderator:read:chat_settingsView chat settingsNo
moderator:manage:chat_settingsManage chat settingsNo

Bot Badge Requirements

For your bot to display the verified bot badge in Twitch chat when using the Send Chat Message API, specific requirements must be met:

Required Authorizations

Bot Account must authorize:

  • user:bot - Bot identity scope
  • user:write:chat - Send messages via API
  • user:read:chat - Read chat via EventSub

Channel Account must authorize:

  • channel:bot - Allows bots to display badge in this channel

Sending Messages with Badge

To send messages that display the bot badge:

  1. Use POST /helix/chat/messages (NOT IRC)
  2. Use an App Access Token (generated via client credentials flow)
  3. The App Access Token works because users authorized the scopes to your client ID
  4. The bot account cannot be the channel broadcaster

Important: User Access Token = messages sent but NO badge. App Access Token = badge displayed.

Verified Bot Status

Bots with Verified Bot status from Twitch receive:

  • Higher chat rate limits (7,500 messages/30s vs 20)
  • Higher join rate (2,000/10s vs 20)
  • Verified badge displayed in chat

Apply for Verified Bot status through Twitch's developer portal when your bot reaches sufficient scale.

Chat Rate Limits

Account TypeMessages/30sJoin Rate/10s
Regular User2020
Broadcaster/Mod/VIP10020
Verified Bot7,5002,000

Connecting Accounts

Connect Channel Account

  1. Go to Admin > Integrations
  2. Click "Connect" under Twitch
  3. Select "Channel" as the account type
  4. Authorize on Twitch
  5. You'll be redirected back to Heimdall

Connect Bot Account

  1. Log out of Twitch (if logged into broadcaster account)
  2. Log into your bot's Twitch account
  3. Go to Admin > Integrations
  4. Click "Connect" under Twitch
  5. Select "Bot" as the account type
  6. Enter a unique bot identifier (e.g., "nightbot", "mybot")
  7. Authorize on Twitch
  8. You'll be redirected back to Heimdall

Token Management

Token Lifetime

  • Access Token: 4 hours (automatically refreshed)
  • Refresh Token: Does not expire (valid until revoked)

Automatic Refresh

Heimdall automatically refreshes tokens before they expire. The scheduler runs periodically and refreshes tokens that will expire within the configured buffer time (default: 30 minutes).

Manual Refresh

If you encounter issues:

  1. Go to Admin > Integrations
  2. Find the Twitch integration
  3. Click "Refresh Token"

Token Errors

Common token errors:

ErrorCauseSolution
invalid_grantToken revoked on TwitchDisconnect and reconnect
invalid_clientClient credentials changedUpdate config, reconnect
token_expiredRefresh failedTry manual refresh, or reconnect

EventSub Integration

With Twitch integrations connected, you can subscribe to EventSub events for real-time notifications. EventSub subscriptions are managed separately from OAuth integrations.

Chat Events

TypeDescriptionRequired Scope
channel.chat.messageUser sends a message to chatuser:read:chat
channel.chat.clearModerator clears all chat messagesuser:read:chat
channel.chat.clear_user_messagesAll messages from a user removeduser:read:chat
channel.chat.message_deleteModerator deletes a specific messageuser:read:chat
channel.chat.notificationChat events (subs, raids, etc.)user:read:chat
channel.chat_settings.updateChat settings are modifieduser:read:chat
channel.chat.user_message_holdUser's message caught by automoduser:read:chat
channel.chat.user_message_updateMessage automod status updateduser:read:chat

AutoMod & Moderation

TypeDescriptionRequired Scope
automod.message.holdMessage caught by automod for reviewmoderator:manage:automod
automod.message.updateAutomod queue message status changesmoderator:manage:automod
automod.settings.updateAutomod settings modifiedmoderator:read:automod_settings
automod.terms.updateAutomod terms updatedmoderator:manage:automod
channel.moderateModerator performs actionchannel:moderate
channel.banUser banned or timed outchannel:moderate
channel.unbanUser unbannedchannel:moderate
channel.unban_request.createUser creates unban requestmoderator:read:unban_requests
channel.unban_request.resolveUnban request resolvedmoderator:manage:unban_requests
channel.moderator.addUser given moderator privilegesNone
channel.moderator.removeModerator privileges removedNone
channel.vip.addUser added as VIPNone
channel.vip.removeUser removed as VIPNone
channel.warning.sendUser receives warningNone
channel.warning.acknowledgeUser acknowledges warningNone
channel.suspicious_user.messageSuspicious user sends messageNone
channel.suspicious_user.updateSuspicious user status updatedNone

Channel Management

TypeDescriptionRequired Scope
channel.updateTitle, category, language changedNone
channel.followChannel receives a followmoderator:read:followers
channel.ad_break.beginMidroll commercial break startschannel:read:ads
channel.raidBroadcaster raids another channelNone
channel.shoutout.createBroadcaster sends a shoutoutNone
channel.shoutout.receiveBroadcaster receives a shoutoutNone
channel.shield_mode.beginShield Mode activatedNone
channel.shield_mode.endShield Mode deactivatedNone

Subscriptions & Monetization

TypeDescriptionRequired Scope
channel.subscribeNew subscriptionchannel:read:subscriptions
channel.subscription.endSubscription expireschannel:read:subscriptions
channel.subscription.giftGift subscriptions grantedchannel:read:subscriptions
channel.subscription.messageResub message sentchannel:read:subscriptions
channel.cheerUser cheers with bitsbits:read
channel.bits.useBits used on channelbits:read

Channel Points & Rewards

TypeDescriptionRequired Scope
channel.channel_points_custom_reward.addCustom reward createdNone
channel.channel_points_custom_reward.updateCustom reward modifiedNone
channel.channel_points_custom_reward.removeCustom reward deletedNone
channel.channel_points_custom_reward_redemption.addViewer redeems custom rewardNone
channel.channel_points_custom_reward_redemption.updateRedemption status changedNone
channel.channel_points_automatic_reward_redemption.addAutomatic reward redeemedNone

Polls & Predictions

TypeDescriptionRequired Scope
channel.poll.beginPoll startedNone
channel.poll.progressUsers respond to pollNone
channel.poll.endPoll endedNone
channel.prediction.beginPrediction startedNone
channel.prediction.progressUsers participate in predictionNone
channel.prediction.lockPrediction lockedNone
channel.prediction.endPrediction endedNone

Goals & Charity

TypeDescriptionRequired Scope
channel.goal.beginBroadcaster starts a goalNone
channel.goal.progressProgress made towards goalNone
channel.goal.endBroadcaster ends goalNone
channel.charity_campaign.startCharity campaign startedNone
channel.charity_campaign.progressCharity fundraising progressNone
channel.charity_campaign.donateUser donates to charityNone
channel.charity_campaign.stopCharity campaign endedNone

Hype Train

TypeDescriptionRequired Scope
channel.hype_train.beginHype Train startsNone
channel.hype_train.progressHype Train gains momentumNone
channel.hype_train.endHype Train endsNone

Stream Events

TypeDescriptionRequired Scope
stream.onlineBroadcaster starts streamingNone
stream.offlineBroadcaster stops streamingNone

Shared Chat (Multi-Stream)

TypeDescriptionRequired Scope
channel.shared_chat.beginChannel joins shared chat sessionNone
channel.shared_chat.updateShared chat session changesNone
channel.shared_chat.endChannel leaves shared chatNone

Guest Star (Beta)

TypeDescriptionRequired Scope
channel.guest_star_session.beginGuest Star session startsNone
channel.guest_star_session.endGuest Star session endsNone
channel.guest_star_guest.updateGuest or slot updatedNone
channel.guest_star_settings.updateHost preferences modifiedNone

User & Authorization Events

TypeDescriptionRequired Scope
user.updateUser updates their accountNone
user.whisper.messageUser receives a whisperNone
user.authorization.grantUser grants app authorizationNone
user.authorization.revokeUser revokes app authorizationNone

Drops & Extensions

TypeDescriptionRequired Scope
drop.entitlement.grantDrop entitlement grantedNone
extension.bits_transaction.createBits transaction in extensionNone

Infrastructure

TypeDescriptionRequired Scope
conduit.shard.disabledEventSub transport shard disabledNone

Subscribing to Events

To subscribe to EventSub events, use the Twitch API:

curl -X POST 'https://api.twitch.tv/helix/eventsub/subscriptions' \
-H 'Authorization: Bearer {app_access_token}' \
-H 'Client-Id: {client_id}' \
-H 'Content-Type: application/json' \
-d '{
"type": "channel.follow",
"version": "2",
"condition": {
"broadcaster_user_id": "12345",
"moderator_user_id": "12345"
},
"transport": {
"method": "webhook",
"callback": "https://your-domain.com/webhooks/twitch",
"secret": "your_webhook_secret"
}
}'

For WebSocket transport (recommended for bots):

curl -X POST 'https://api.twitch.tv/helix/eventsub/subscriptions' \
-H 'Authorization: Bearer {user_access_token}' \
-H 'Client-Id: {client_id}' \
-H 'Content-Type: application/json' \
-d '{
"type": "channel.chat.message",
"version": "1",
"condition": {
"broadcaster_user_id": "12345",
"user_id": "67890"
},
"transport": {
"method": "websocket",
"session_id": "your_websocket_session_id"
}
}'

Troubleshooting

"Missing required scope" error

The user didn't authorize all required scopes. Ask them to:

  1. Go to Twitch Settings > Connections
  2. Revoke Heimdall's access
  3. Reconnect through Admin > Integrations

Bot messages not showing badge

Ensure:

  1. Channel account has authorized channel:bot scope
  2. Bot account has authorized user:bot scope
  3. You're using App Access Token, not User Access Token
  4. Bot account is not the channel broadcaster

Rate limit exceeded

Your bot is sending too many messages. Implement:

  • Message queuing
  • Rate limiting per channel
  • Consider applying for Verified Bot status