Files

101 lines
6.1 KiB
Markdown
Raw Permalink Normal View History

2021-08-26 15:42:37 +02:00
# Node-RED_Twitch_EventSub
Node-RED flow to subscribe, receive and respond to Twitch webhook
2022-02-18 14:03:53 +01:00
<img src="https://github.com/n3odym3/Node-RED_Twitch_EventSub/blob/main/pictures/Dashboard.png" >
2021-08-26 17:47:57 +02:00
<img src="https://github.com/n3odym3/Node-RED_Twitch_EventSub/blob/main/pictures/EventSubFlow.PNG" >
## Note
- My [Twitch channel](https://www.twitch.tv/ioodyme)
2022-02-18 14:03:53 +01:00
- To [support me](https://paypal.me/ioodyme)
2021-08-26 17:47:57 +02:00
- It is **HIGHLY** recommended to [secure](https://nodered.org/docs/user-guide/runtime/securing-node-red#editor--admin-api-security) your Node-RED flow (your server will be exposed to the internet) !!
- [EventSub doc](https://dev.twitch.tv/docs/eventsub)
2022-02-18 14:03:53 +01:00
- This Flow is compatible with the [Twitch API](https://dev.twitch.tv/docs/api/reference)
2021-08-26 17:47:57 +02:00
## Prerequisites
2021-08-27 01:09:58 +02:00
- [Node-RED](https://nodered.org/) running on port 443 with [HTTPS](https://nodered.org/docs/user-guide/runtime/securing-node-red#enabling-https-access) enabled OR a [ngrok auth token](https://dashboard.ngrok.com/get-started/your-authtoken)
2021-08-26 17:47:57 +02:00
- Twitch [APP](https://dev.twitch.tv/console/apps/) Client ID
- Twitch [APP](https://dev.twitch.tv/console/apps/) Client Secret
## Dependencies
- node-red-dashboard
- node-red-contrib-crypto-js-dynamic
- Optional : node-red-contrib-ngrok
2021-08-27 01:09:58 +02:00
## For ngrok users
- Create a free account on [ngrok](https://ngrok.com/)
2021-08-26 17:47:57 +02:00
- Save your AuthToken
2021-08-27 01:09:58 +02:00
- Install the [ngrok](https://flows.nodered.org/node/node-red-contrib-ngrok) node on Node-RED
- Drag and drop a ngrok node on your flow
2021-08-26 17:47:57 +02:00
- Setup the node using your AuthToken
- Open a tunnel and save the URL
<img src="https://github.com/n3odym3/Node-RED_Twitch_EventSub/blob/main/pictures/NgrockURL.png" width="50%">
## Twitch Setup
- Create an [APP](https://dev.twitch.tv/console/apps/) and save your APP ID and Secret
2021-08-27 01:09:58 +02:00
- Add the following URL using your domain name or ngrok tunnel URL
2021-08-26 17:48:48 +02:00
<img src="https://github.com/n3odym3/Node-RED_Twitch_EventSub/blob/main/pictures/Redirect.png" width="80%">
2021-08-26 17:47:57 +02:00
*Note : As your Node-RED should be secured with http basic auth the URI are **https://admin:password@xxxxxxxxx.eu.ngrok.io** or **https://admin:password@your.domain.name** with "admin" and "password" corresponding to you Node-RED dashboard auth.
It can be different from your Node-RED admin auth.*
2021-08-28 01:05:19 +02:00
2021-08-26 17:47:57 +02:00
## Node-RED Setup
2022-02-18 15:06:40 +01:00
### API
<img src="https://github.com/n3odym3/Node-RED_Twitch_EventSub/blob/main/pictures/Settings1.png" width="75%">
2021-08-26 17:47:57 +02:00
- [Import](https://nodered.org/docs/user-guide/editor/workspace/import-export) the [flow](https://github.com/n3odym3/Node-RED_Twitch_EventSub/blob/main/EventSub-Twitch-Flow.json)
- Edit the API Settings node with your
- Twitch client ID
- Twitch client secret
- Sub secret : a password (defined by the user) to validate the Twitch event signature
- Twitch channel
2021-08-28 01:05:19 +02:00
- Sub URI : your Node-RED server name or ngrok tunnel URL **WITHOUT** "HTTPS://" (Ex : your.domain.name or xxxxxxxxxxx.ngrok.io and admin:password@your.domain.name or admin:password@xxxxxxxxxxx.ngrok.io for a properly secured server)
2022-02-18 15:06:40 +01:00
- [Scopes](https://dev.twitch.tv/docs/authentication#scopes) (space-separated)
2022-02-21 16:37:15 +01:00
*Recommended Scopes*
2022-02-18 15:06:40 +01:00
> bits:read channel:manage:broadcast channel:manage:polls channel:manage:predictions channel:manage:redemptions channel:read:polls channel:read:predictions channel:read:redemptions channel:read:subscriptions moderation:read user:read:follows user:read:subscriptions channel:moderate channel:read:hype_train
2022-02-21 16:37:15 +01:00
*All scopes*
> analytics:read:extensions analytics:read:games bits:read channel:edit:commercial channel:manage:broadcast channel:manage:extensions channel:manage:polls channel:manage:predictions channel:manage:redemptions channel:manage:schedule channel:manage:videos channel:read:editors channel:read:goals channel:read:hype_train channel:read:polls channel:read:predictions channel:read:redemptions channel:read:stream_key channel:read:subscriptions clips:edit moderation:read moderator:manage:banned_users moderator:read:blocked_terms moderator:manage:blocked_terms moderator:manage:automod moderator:read:automod_settings moderator:manage:automod_settings moderator:read:chat_settings moderator:manage:chat_settings user:edit user:edit:follows user:manage:blocked_users user:read:blocked_users user:read:broadcast user:read:email user:read:follows user:read:subscriptions channel:moderate chat:edit chat:read whispers:read whispers:edit
2022-02-18 15:06:40 +01:00
### Tokens
<img src="https://github.com/n3odym3/Node-RED_Twitch_EventSub/blob/main/pictures/Auth.png" width="30%">
2022-02-18 14:03:53 +01:00
2021-08-27 01:09:58 +02:00
- Go to the Node-RED dashboard (https://your.domain.name/ui or https://xxxxxxxxxx.ngrok.io/ui)
2021-08-26 17:47:57 +02:00
- Generate an APP token and USER token by clicking on Auhtorize APP and Authorize USER (will requires to loggin with your Twitch account and accept the scopes)
2022-02-18 15:06:40 +01:00
- Optional : you can test the validity and expiration of the Token using "Validate" nodes on the Node-RED editor
2021-08-26 17:47:57 +02:00
2022-02-18 15:09:17 +01:00
*Note : The Authorize App and Authorize User buttons will appear when the API options are submitted*
2021-08-26 17:47:57 +02:00
## Subscribe
2022-02-18 15:06:40 +01:00
- Type the channel username
2021-08-26 17:47:57 +02:00
- Subscribe to an event by selecting the desired Event on the Node-RED GUI
- Clic on "Subscribe"
2022-02-18 15:06:40 +01:00
<img src="https://github.com/n3odym3/Node-RED_Twitch_EventSub/blob/main/pictures/Sub.png" width="50%">
2021-08-26 17:47:57 +02:00
## Unsubscribe
- Refresh the subscriptions
2022-02-18 15:06:40 +01:00
- Select the channel
2021-08-26 17:47:57 +02:00
- Select the event you want to unsubscribe
2021-08-26 21:17:34 +02:00
- Clic on "Unsubscribe"
2022-02-18 15:06:40 +01:00
<img src="https://github.com/n3odym3/Node-RED_Twitch_EventSub/blob/main/pictures/Unsub.png" width="30%">
2021-08-26 17:47:57 +02:00
## Events
2022-02-18 15:06:40 +01:00
If you subscribed to multiple channels you can separte the event by the broadcaster channel ID.
2021-08-26 17:47:57 +02:00
2022-02-18 15:06:40 +01:00
<img src="https://github.com/n3odym3/Node-RED_Twitch_EventSub/blob/main/pictures/Subfilter.png" width="25%">
2021-08-26 17:47:57 +02:00
2022-02-18 15:06:40 +01:00
- When an event is posted to /webhook the JSON will be validated using the "Sub secret" code and sent to the second flow "Reponse"
- The "Inject" node and "Fake event" function can be removes as they are only used for Testing/Debug purposes
2021-08-26 17:47:57 +02:00
- Retrieve and use the events informations by connectig your node/function to the annotated functions
2022-02-18 15:06:40 +01:00
<img src="https://github.com/n3odym3/Node-RED_Twitch_EventSub/blob/main/pictures/Responses.png" width="40%">
<img src="https://github.com/n3odym3/Node-RED_Twitch_EventSub/blob/main/pictures/Annotation.png" width="40%">
2021-08-26 17:47:57 +02:00
**HAVE FUN**