Hey, I was looking to develope a widget to show directly on stream the Twitch Hype Train progression, so I looked up to Twitch APIs documentation and the only thing I found is Get Hype Train Events.
I’m confused, how should I use it? I was expecting some sort of WebSocket spreading events in real-time, but seems like the only avaible method is an API Endpoint. How can I can retrieve Hype progress in real-time? Is this something doable? Am I missing something?
The only way I can think of is doing requests to that endpoint, but I’m worried about how many I can do and also how fast I can trigger it.
If you want real time alerts you can use EventSub. It has begin, progress, and end events.
Thanks. Do you know if this can be done withing Streamelements custom coded widget? I already worked with PubSub but I’m worried this time I will need a middle server from where to subscribe to the event and then send data to SE’s widget.
At this time EventSub only offers a Webhook Transport
EventSub over sockets is in Closed Beta testing, and basically replaces PubSub.
However there is no timeline on general availability.
You are doing yourself a disservice by limiting yourserlve to SE Custom Coded Widgets. This forum is unlikely to know what SE can or cannot do, since most of use will not limit ourself to the limitations of SE.
As it stands to consume HypeTrain data “sanely” you need a middle man server to consume the EventSub information.
Ok, that’s not the first time I face this situation. Let’s say I never worded with a middle man server.
From where should I start? Can you share with me any guide on how to get started? Worth mentioning that my goal is to have a service that could be used by multiple streamers, so storing sensitive data has to be mentioned somehow.
You just need a server side script
That is behind SSL
That server side script needs to be able to recieve POST requests.
Like a “login form to a website” would.
Twitch will be POST-ing to you JSON formatted data in the POST.
You can probably find exmaples and/or libraries over on Community Resources | Twitch Developers
Or you can check my Github where there is filed a PHP and a NodeJS example for consuming Webhook Transport EventSub https://github.com/BarryCarlyon/twitch_misc/tree/main/eventsub/handlers
You’ll also need a public web page that streamers would go to, in order to authorise your ability to read hype train data. So you’ll need a user oAuth web page.
You can then store or discard that user oAuth token as EventSub Webhooks uses an App Access Token to create Subscriptions to data feeds.
You would usually retain that token for “catch up” if you need to restart your system or experience any down time.
The “Handling Webhhook Events” guide is relatively comprehensive Handling Events | Twitch Developers
Thanks, that will help me for sure! I’m a bit worried about storing secrets/access_tokens etc on my server, is there any specific guide on how to store these sensitive data?
People often store client secrets in .env and config files and generally you don’t expose these in client facing code.
As for tokens, they are basically passwords so handle them the same way you handle user passwords if your website/tool has a login form.
I’m pretty sure this question is very well related to this topic, how can I test such Hype Train events?
You can use the TwitchCLI to test EventSub sample messages against your endpoint
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.