I created a chat bot using the documentation here.
I would like to add a follower notification too like other bots do such as WizeBot. From my understanding, I need to poll the API here for a list of followers and then post the message myself? Is this the current way to do this or is there a better solution that doesn’t involve polling the API?
I tried following all the documentation I still can’t get this to work. I tried just the curl example with my endpoint but it’s not sending anything to my callback.
Have you set up whatever web server you’re using to handle the callback? You need 2 handlers, 1 for the GET request Twitch will send, which is to test your server is reachable and you have to reply the challenge that is set, and 1 handler for the POST requests which are the actual notifications for the topic you subscribed to.
I’m not sure what you’re actually requesting, the first link you’ve posted shows you’ve got a GET request from Twitch containing the hub.challenge, have you sent that back with a 200 status?
The reason I’m a little confused is your CURL command differs from the first URL you posted, as the CURL only has a 0 second lease, so will expire the moment it is created anyway and wouldn’t receive any response from Twitch after the hub.challenge stage of the subscription process.
Without seeing how you’ve set up your requests/routes/handlers, my advice would be to log ‘all the things’.
eg, what’s the reply you’re getting from your initial request to Twitch, you should be getting a 202 back, if not you should be getting an error in the body of the response.
If your subscription request was successful, you should then have a GET request to your callback url. If you’re not getting anything, either it’s not reachable or your handler isn’t configured correctly. If you’re getting a request, it should contain the hub.callback which you respond with, along with a 200 status code.
At this point, assuming you did everything right and your lease is > 0 seconds, you could be able to call the webhook subscriptions endpoint and verify that the webhook has been created. If it has then you should be receiving POST requests to your callback url, if you’re not getting any then it’s likely an error in the configuration of your POST route handler.
If you’re getting a 202 then at least you know the initial request works, at which point Twitch will be performing their GET request on your callback URL for you to respond to.
Ok, thank you! I think I have it working now. It’s sending me verification request when I subscribe but I’m not getting the follower alerts. Do these only happen when the stream is live? I tried testing by following and unfollowing with a 2nd account but I’m not receiving any notifications.
For the followers topic it doesn’t matter if the stream is live or not.
If you’re not getting notifications it means either your subscription has expired/wasn’t created (you can check this by using the endpoint I previously mentioned), or the channel you’re testing follows on differs from that of the topic, or notifications are being sent but either your route or your handler isn’t correctly handling the POST requests.
Also keep in mind that webhooks rely on the underlying API, so there is a delay due to caching and waiting for all servers to reach a consistent state. One thing you can do is send a request directly to the topic, as a normal API request, if you see that there’s a change in followers there, then a notification should be sent out shortly after.
I think the reasoning behind the webhooks subscriptions endpoint requiring an App Access Token, is that a Client-ID is potentially public, so by requiring a token it means only you will be able to access it and which will help reduce the chance of your callback URL being made public, and more generally stops random people being able to see what webhook topics you’re subscribed to.