Node JS Automatically get update when a user goes live

Hello!
So I’m working on a discord chat bot, and one of the things I would love to add twitch stream announcements. I have seen some other bots do it, and was wondering where in the docs I should be looking.

Thanks

Check streams

Is there a simple way to automatically check the live status? I know ith beam, they have a system where you “subscribe” to a channel list, and when someone on the list goes live, the bot automatically can send out its message. Any twitch alternative?

No, you need to poll the API every few minutes.

Ok, is there a rate limit on how often I can poll the api?

No, but you shouldn’t check more than once every few minutes due to server-side caching.

Could I poll for every 2 min, and check the “created_at” stat and compare it to local time? If it was made within the last 2 min, run code?

Sounds like a good plan

@ComixsYT that’s basically the same method my bot follows

If you don’t mind, may I see the portion of code that runs the check?

Yeah, on my phone ow, but I’ll post it to a Gist when I get home from work… it’s going to be in Java, but the concept will be the same in NodeJS

But in the meantime, I would take a look at converting the returned datetime into a Unix timestamp and taking the difference to see if it matches the constraints on your timed execution…

I’ll look into it as soon as I get home, thanks!

Hey, I apologize for my long delay in response… have you figured out how to make this happen on your own already?

Hey Ague – If i am understanding your problem correctly you can actually use the pubsub system to get an update when the user goes live. This little package sets everything up for you fairly well.

The docs are pretty bad, but if you have any questions about it I can probably help you.

Simply subscribe to whatever channels you want to follow:
(You can listen to new channels too without having to restart the node program)

// Change Bajheera to whatever channel you want to listen too
var realtime = new Realtime({defaultTopics:[“video-playback.bajheera”]});

realtime.on(‘bits’, (data) => {
// Do something with the data
});

I want to make sure to note that the video-playback PubSub topic is not supported for third party use. It can stop working or be removed at any time.

1 Like

Well, to be honest, I don’t have any problems with the api… I was trying to help out the OP… thanks though…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.