Namek / twitch-spotify-request-bot

This is a bot that listens to the chat of a given Twitch stream for messages with a Spotify song link in them and then adds that song to a playlist and/or your queue.

Home Page:https://www.marcdonald.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Twitch Spotify Request Bot

What is this?

This is a bot that listens to the chat of a given Twitch stream for messages with a Spotify song link in them and then adds that song to a playlist and/or your queue. The Spotify link must be at the start of the message in order to be picked up.

✔️ Message that WOULD be picked up:

!prefix https://open.spotify.com/track/4uLU6hMCjMI75M1A2tKUQC?si=x-_FFgqBRB20mzW_lM7kDQ pls play this, it's a bop

❌ Message that WOULD NOT be picked up:

!prefix this is a bop can you please play this https://open.spotify.com/track/4uLU6hMCjMI75M1A2tKUQC?si=x-_FFgqBRB20mzW_lM7kDQ

Deploy

Click here to deploy your bot to heroku

Deploy

  1. Go to the Spotify developer dashboard and create a new application. The app can have whatever name and description you want
  2. You just need to fill the required information in the Heroku page
  3. Once the app is created in Heroku, go back to Spotify developer dashboard, select your app and then click on Edit Settings and add a redirect URL of https://app-name.herokuapp.com/spotifyAuth (NB: Same URL that you declared in HOST from the step 2. Just add the /spotifyAuth at the end)
  4. Wait the build process and then click on 'View' or 'Open app' in Heroku page
  • The playlist ID can be found by right-clicking on the playlist -> clicking Share -> Copy Spotify URI and then copying the ID after spotify:playlist: eg. spotify:playlist:{THIS_STRING_IS_THE_ID})
  • The Spotify client ID and secret are obtained from the application you created in the Spotify developer dashboard
  • If you wish to have chat feedback, set CHAT_FEEDBACK to true then generate a Twitch Chat OAuth Token and set it as the TWITCH_TOKEN field in the .env file. Also set the BOT_USERNAME field to the name of the account you wish to use (must be the same account you generate the OAuth token for)

Prerequisites for local

  • Some basic programming knowledge (running terminal commands and editing .env files)
  • Node (developed and tested on 14.6.0 - your mileage may vary on other versions)
  • A Spotify account

Setup

  1. Go to the Spotify developer dashboard and create a new application. The app can have whatever name and description you want
  2. Once the app is created, click on Edit Settings and add a redirect URL of http://localhost:8000/spotifyAuth (NB: the port will be whatever you have set as the AUTH_SERVER_PORT in the ./.env file, by default it is 8000)
  3. Create a ./.env file based on ./.env.template file and fill in the fields
  • The playlist ID can be found by right-clicking on the playlist -> clicking Share -> Copy Spotify URI and then copying the ID after spotify:playlist: e.g. spotify:playlist:{THIS_STRING_IS_THE_ID})
  • The Spotify client ID and secret are obtained from the application you created in the Spotify developer dashboard
  • If you wish to have chat feedback, set CHAT_FEEDBACK to true then generate a Twitch Chat OAuth Token and set it as the TWITCH_TOKEN field in the .env file. Also set the BOT_USERNAME field to the name of the account you wish to use (must be the same account you generate the OAuth token for)
  1. Run bash ./build.sh. This will automatically compile from source using npm and then build OS-native binaries using pkg
  2. Run the freshly compiled binary for your OS in ./dist.
  3. Open the authorization link and give the app the required permissions
  4. If you have ADD_TO_QUEUE toggled on, ensure you have the Spotify client open and that it is active (i.e. is playing a song)
  5. Type a Spotify link in the chat (ensuring the link is the first piece of text in the message) and make sure it shows up in your desired playlist (Spotify links should start with https://open.spotify.com/track/)
  6. If there's a problem with Spotify authorization at any point, try deleting the spotify-auth-store.json file and starting the app again

Note

Running without generating a binary file

If you would prefer to launch the bot without generating a binary file you can replace steps 4 and 5 the following

  • Run npm install or yarn
  • Run npm run build && npm start or yarn build && yarn start

Generating package-lock files

Avoid generating new package-lock.json files unless you are using an Ubuntu machine. This is due to a bug with the Heroku deploy requiring xubuntu dependencies.

Development

  • Run npm run dev for watching/recompiling
  • Run npm run dev:inspect for watching/recompiling + debug

Open Source Libraries Used

Used for connecting to and performing actions using Spotify

MIT License

Used for connecting to Twitch chat

MIT License

Used for creating a temporary local web server to retrieve the callback from the Spotify authorization

MIT License

Used to speed up development with hot reload

MIT License

Used to make code pretty

MIT License

Used to run TypeScript

MIT License

Used for strong typings

Apache 2.0 License

Used to load environment variables

BSD 2-Clause "Simplified" License

Used to set types for environment variables

MIT License

Used to create platform binaries

MIT License

Contributors

Checkout the Contributors file to see everyone who has helped out with the bot

Used for the icon

Apache 2 License

About

This is a bot that listens to the chat of a given Twitch stream for messages with a Spotify song link in them and then adds that song to a playlist and/or your queue.

https://www.marcdonald.com

License:MIT License


Languages

Language:TypeScript 96.2%Language:Shell 3.8%