Chat client
Connect to Twitch IRC over WebSocket with typed events, PING/PONG handling, and automatic reconnect.
TwitchChatClient connects to Twitch IRC over WebSocket, handles PING/PONG, and emits strongly
typed events for every message.
import { TwitchChatClient } from "velho";
const chat = new TwitchChatClient({
username: "my_bot",
token: process.env.TWITCH_CHAT_TOKEN!,
reconnect: true,
autoJoin: ["#velho"],
});
await chat.connect();
chat.on("ready", () => console.log("Chat ready"));
chat.on("message", (message) => {
console.log(`[${message.channel}] <${message.username}> ${message.text}`);
});
chat.say("#velho", "Hello Twitch!");- Events include
ready,message,notice,join,part,reconnect,close, anderror. - Automatic reconnect with configurable delay; augment with custom backoff if necessary.
listensubscribes to messages and returns an unsubscribe callback.say()sends immediately; callers must enforce Twitch Chat rate limits.