Examples

Example code for interacting with the WebSocket server using JavaScript
We recommend using the Streamer.bot Client library if you are using JavaScript or TypeScript!

Connect

// Streamerbot Client will automatically connect to 127.0.0.1:8080
const client = new StreamerbotClient();

Execute Actions

// Execute an action with actionId "9c6203fd-363f-4834-983e-b10423c568ea"
const response = await client.doAction("9c6203fd-363f-4834-983e-b10423c568ea");

Handle Events

Streamer.bot Client will automatically handle event subscriptions when you add an event handler!
// Subscribe to Twitch Chat messages and register an event handler
client.on('Twitch.ChatMessage', ({ event, data }) => {
  // Do something with Twitch Chat data...
  console.log('Twitch Chat:', data);
});

// Subscribe to *All* Twitch events
client.on('Twitch.*', ({ event, data }) => {
  // Do something with Twitch data...
  console.log('Twitch Event:', event.type, data);
});

// Subscribe to *All events*
client.on('*', ({ event, data }) => {
  // Do something with all events...
  console.log(`[${event.source}.${event.type}]`, data);
});