-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Notification: Twitch (automated)
Hi,
I have struggled with the Twitch Notifications myself; going through the OAUTH2 Twitch Developer documentation, I was able to figure it out! In an effort to make this available in an easy automated form, I have written a script that does the leg work for you.
Here are the features/How it works rundown:
- The code will create a copy of your dotenv to (.env) and check it for TWITCH_CLIENT_ID, TWITCH_CLIENT_SECRET, and TWITCH_CHANNEL entries.
- If it finds the codes, it will proceed to direct you to the proper login site on https://id.twitch.tv with rights chat:edit and chat:read as required by streetmerchant (saving the session in ./user_data to make re-getting the token easy)
- The script will automatically extract the code Query Parameter from either the redirect (new session) or the target (saved session - no login).
- The script then proceeds to obtain current mozilla certificate from https://curl.se/docs/caextract.html and sends the POST with the proper TWITCH AUTH parameters to automatically obtain TWITCH_ACCESS_TOKEN and TWITCH_REFRESH_TOKEN and either replace the token in the copied .env file, or append to it.
- Lastly, the script will display all your tokens and ask if you would like to copy the generated .env (based on your current dotenv file) over to a working dotenv file.
- If you answer with yes (y), the script will create a backup of dotenv (dotenv.bak) and copy over the new file to dotenv. This file will include all needed codes, as well as any parameters currently in your dotenv file.
- Lastly, the script will suggest to run a npm run test:notification to test your notification.
NOTE: On rare occasions, the script will fail due to some random filesystem permission issue (either it cannot find dotenv and will quit with please populate parameters), or it fails during deletion of previous cacert.pem. If this happens, feel free to cancel the script and run again.
I hope that this will help some people to get Twitch notifications setup. Please feel free to 'optimize' the code (as I am certain, it will disgust some coders :)
The first steps are identical to Jef's approach. Creating an Application from https://dev.twitch.tv/console/apps with a redirect URL of http://localhost:
Must use unique name. Use https://www.uuidgenerator.net/ to get a UUID and append it to streetmerchant-.
From there, you should get the TWITCH_CLIENT_ID, TWITCH_CLIENT_SECRET, and TWITCH_CHANNEL (be careful, TWITCH_CLIENT_SECRET can only be seen one time when generated).
Add the three lines to your 'dotenv' file and save your file.
TWITCH_CLIENT_ID=your client id TWITCH_CLIENT_SECRET=your twitch secret TWITCH_CHANNEL=your twitch channel/username
My script requires puppeteer, dotenv, readline, yesno, querystring, and node-libcurl (apologies, but this is my first NODE.js script ever), so please make sure you install the necessary dependencies
npm i puppeteer dotenv readline yesno querystring node-libcurl
Get Twitch_Automated at https://github.com/agwosdz/twitch_automated/blob/main/Twitch_Automated.js
↩️ Go back to Home