Skip to content

cgbuen/chatbot

Repository files navigation

Twitch Chatbot / Endpoint Server

My locally-running Twitch chatbot for some simple commands, including game ID display, currently-playing Spotify song, shoutouts with real-user checking, and a fun leaderboard chat game. It also logs the chat.

This runs on port 3000.

This also has evolved into a means by which to serve API endpoints, since much of the data needed for the chatbot to respond with can be reused into Express responses that can be consumed by another locally running server for a web application. This, for example, could be useful for a broadcast overlay. (Here is the corresponding one that I use.)

The endpoints gather data from the following sources:

  • Spotify API (for currently playing song)
  • Twitch API (for followers, bits, and subs)
  • Splatoon API (for gear, ranks, and other stats)
  • Animal Crossing: New Horizons API (for player/island info, as well as live keyboard inputs)
  • s2s / flapg APIs (for refreshing Nintendo tokens)
  • Your own local machine (for chat game stats, uptime, and other possible hardcoded data)

Before Installing: Register Developer Apps

One benefit of this project is that it allows you to not have to depend on your own machine's Spotify desktop client application when looking for the song that's currently being played, but instead Spotify's API data that they have on you, as you're playing music.

Note that Spotify's API requires OAuth 2.0 to get any user data, which makes for a somewhat complicated authentication process (it in fact requires the use of an actual Spotify developer app). The directions here allow you to quickly stand up your own app (it does not have to be published), so that you're authenticating to what you've made yourself, rather than someone else's live developer app.

Similar functionality has been added for the new Twitch API, which also uses OAuth 2.0. The purpose here is solely for spitting out tokens for gathering the followers / bits / subs data.

  1. Register as a Spotify Developer.
  2. Create a project by clicking the "Create a Client ID" and filling out all the appropriate fields.
  3. Go to "Edit Settings" and add http://localhost:3000/callback-spotify to the whitelist of Redirect URIs.
  4. Make note of the app's associated Client ID and Client Secret. These get used when configuring this bot later (see the Configure section).
  5. Repeat steps 1-4, but for Twitch.

Install

I'm using node 8.16.0 and npm 5.10.0, but this is probably simple enough to work with a lot of different versions.

npm ci

Configuration

Duplicate command-content.json.example in the root directory and rename it to command-content.json. This can be configured to show different information from the chatbot and in the ticker, including data and settings.

Then, duplicate vars.js.example in the root directory and rename it to vars.js. Notes:

  • BOT_USER can be the same handle you use for your channel (CHANNEL).
  • The default COUNTER value is "stats", and the default TOKEN_STORE value is "token-store". If you want to change either or both of these values, make sure to update the corresponding values in .gitignore.
  • NINTENDO_SESSION is the session_token that must be retrieved using an MitM proxy (e.g. Charles) into your personal device's Nintendo Switch app. Note that this goes here as your "configurable" variable rather than being placed in TOKEN_STORE, since TOKEN_STORE is only meant for tokens/data that are generated by the use of this software.

Run

npm start

This kicks off a few things:

  • The Express endpoint server, most notable for the API data that gets consumed by a separate React app
  • A sockets connection to Twitch chat (twitch-js), as per one of the endpoints which is opened in your browser, which then redirects to your main Twitch stream dashboard page
  • A separate sockets connection to Twitch for channel points redemptions (written from scratch here), as per one of the endpoints which is opened in your browser, which then redirects to your Twitch channel's rewards settings page

Notes

You'll have to hit the following endpoints if you're running this the first time. These retrieve your proper access and refresh tokens and store them into your TOKEN_STORE directory.

Note that there is user-specific data that is generated upon use of this software, which end up getting stored in TOKEN_STORE despite not being tokens per se. They just need to be stored somewhere safe, and they might as well be considered sensitive anyway.

About

Twitch chatbot / endpoint server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published