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
- Twitch Developer Account: Register your application at Twitch Developer Console
- OAuth Token: Generate a token with
chat:readandchat:editscopes 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 interactowner/broadcaster- Channel owner onlymoderator- Moderatorsvip- VIP userssubscriber- 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
- Token Security: Never expose your access token in client-side code
- Scope Limitation: Only request necessary OAuth scopes
- Role Filtering: Use
TWITCH_ALLOWED_ROLESto restrict who can interact - Mention Requirement: Enable
TWITCH_REQUIRE_MENTIONin busy channels
Troubleshooting
Connection Issues
- Verify your OAuth token is valid and not expired
- Check that the username matches the token owner
- Ensure the client ID is correct
Authentication Errors
- Regenerate your OAuth token
- Verify scopes include
chat:readandchat:edit - Check for typos in environment variables
Message Not Sending
- Verify you have joined the target channel
- Check that the channel name is correct (no # prefix)
- Ensure your token has
chat:editscope
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fbfc97797247870d03976af8e643b0def24dbd08550ff5c36569d30db186033
|
|
| MD5 |
a88f4e9cd5e7e8b1ec57dbaa7f06eacd
|
|
| BLAKE2b-256 |
5a3741ebe751b8d3cc4fcf727b939e445a330fdfb4cbf70d40175bbdfb111a96
|
File details
Details for the file elizaos_plugin_twitch-2.0.0a5-py3-none-any.whl.
File metadata
- Download URL: elizaos_plugin_twitch-2.0.0a5-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afb79c4e03717b1cfba6f68cf69f5af726b7d854af28e58fe28d220c08677e79
|
|
| MD5 |
49cc1ddfd50a410480af51fedf4b4cc2
|
|
| BLAKE2b-256 |
94934ae0dc513dfd7bb22d63f9f19a0636ef3909db89de59245563436444d823
|