Skip to main content

Twitch chat integration plugin for elizaOS agents

Project description

@elizaos/plugin-twitch

Twitch chat integration plugin for elizaOS agents.

Features

  • Real-time Chat: Connect to Twitch channels and participate in chat
  • Multi-channel Support: Join and monitor multiple channels simultaneously
  • Role-based Access Control: Filter interactions by user roles (broadcaster, moderator, VIP, subscriber)
  • Mention Detection: Optionally only respond when @mentioned
  • Token Refresh: Automatic OAuth token refresh (when configured)
  • Markdown Stripping: Automatically converts markdown to plain text for Twitch

Installation

npm install @elizaos/plugin-twitch

Prerequisites

  1. Twitch Developer Account: Register your application at Twitch Developer Console
  2. OAuth Token: Generate a token with chat:read and chat:edit scopes at Twitch Token Generator

Configuration

Set the following environment variables:

Required

Variable Description
TWITCH_USERNAME Bot's Twitch username
TWITCH_CLIENT_ID Application client ID from Twitch Developer Console
TWITCH_ACCESS_TOKEN OAuth access token with chat:read and chat:edit scopes
TWITCH_CHANNEL Primary channel to join (without # prefix)

Optional

Variable Description Default
TWITCH_CLIENT_SECRET Application client secret (for token refresh) -
TWITCH_REFRESH_TOKEN OAuth refresh token (for automatic refresh) -
TWITCH_CHANNELS Comma-separated list of additional channels -
TWITCH_REQUIRE_MENTION Only respond when @mentioned false
TWITCH_ALLOWED_ROLES Comma-separated roles allowed to interact all

Allowed Roles

  • all - Anyone can interact
  • owner / broadcaster - Channel owner only
  • moderator - Moderators
  • vip - VIP users
  • subscriber - Subscribers

Usage

Basic Setup

import twitchPlugin from "@elizaos/plugin-twitch";

const agent = new Agent({
  plugins: [twitchPlugin],
});

Actions

TWITCH_SEND_MESSAGE

Send a message to a Twitch channel.

// User: "Send a message saying 'Hello everyone!'"
// Agent will send to the current channel

TWITCH_JOIN_CHANNEL

Join a new Twitch channel.

// User: "Join the channel xqc"
// Agent will join #xqc

TWITCH_LEAVE_CHANNEL

Leave a Twitch channel.

// User: "Leave the channel xqc"
// Agent will leave #xqc (cannot leave primary channel)

TWITCH_LIST_CHANNELS

List all channels the bot is currently in.

// User: "What channels are you in?"
// Agent will list all joined channels

Providers

twitchChannelState

Provides context about the current Twitch channel:

  • Channel name
  • Whether it's the primary channel
  • List of all joined channels
  • Bot username

twitchUserContext

Provides context about the user in the conversation:

  • User ID and username
  • Display name
  • Roles (broadcaster, moderator, VIP, subscriber)
  • Chat color

Events

The plugin emits the following events:

Event Description
TWITCH_MESSAGE_RECEIVED A chat message was received
TWITCH_MESSAGE_SENT A message was sent
TWITCH_JOIN_CHANNEL Bot joined a channel
TWITCH_LEAVE_CHANNEL Bot left a channel
TWITCH_CONNECTION_READY Connected to Twitch
TWITCH_CONNECTION_LOST Connection lost

Message Limits

  • Maximum message length: 500 characters
  • Messages longer than 500 characters are automatically split

Security Considerations

  1. Token Security: Never expose your access token in client-side code
  2. Scope Limitation: Only request necessary OAuth scopes
  3. Role Filtering: Use TWITCH_ALLOWED_ROLES to restrict who can interact
  4. Mention Requirement: Enable TWITCH_REQUIRE_MENTION in busy channels

Troubleshooting

Connection Issues

  1. Verify your OAuth token is valid and not expired
  2. Check that the username matches the token owner
  3. Ensure the client ID is correct

Authentication Errors

  1. Regenerate your OAuth token
  2. Verify scopes include chat:read and chat:edit
  3. Check for typos in environment variables

Message Not Sending

  1. Verify you have joined the target channel
  2. Check that the channel name is correct (no # prefix)
  3. Ensure your token has chat:edit scope

Multi-language Support

This plugin supports:

  • TypeScript - Full implementation with @twurple/chat
  • Python - Full implementation with twitchio
  • Rust - Full implementation with native WebSocket

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

elizaos_plugin_twitch-2.0.0a5.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

elizaos_plugin_twitch-2.0.0a5-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file elizaos_plugin_twitch-2.0.0a5.tar.gz.

File metadata

  • Download URL: elizaos_plugin_twitch-2.0.0a5.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for elizaos_plugin_twitch-2.0.0a5.tar.gz
Algorithm Hash digest
SHA256 7fbfc97797247870d03976af8e643b0def24dbd08550ff5c36569d30db186033
MD5 a88f4e9cd5e7e8b1ec57dbaa7f06eacd
BLAKE2b-256 5a3741ebe751b8d3cc4fcf727b939e445a330fdfb4cbf70d40175bbdfb111a96

See more details on using hashes here.

File details

Details for the file elizaos_plugin_twitch-2.0.0a5-py3-none-any.whl.

File metadata

File hashes

Hashes for elizaos_plugin_twitch-2.0.0a5-py3-none-any.whl
Algorithm Hash digest
SHA256 afb79c4e03717b1cfba6f68cf69f5af726b7d854af28e58fe28d220c08677e79
MD5 49cc1ddfd50a410480af51fedf4b4cc2
BLAKE2b-256 94934ae0dc513dfd7bb22d63f9f19a0636ef3909db89de59245563436444d823

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page