New Twitch API: Follower Webhook Help (Helix)

Hi everyone!

I have been recent trying to get the Helix Follower Webhook up and running. Let me layout the process I have taken and where I have become stuck. (I am use node/express)

  1. Create body params
var hookParams = JSON.stringify({
      'hub.callback': userData.followHook,
      'hub.mode': 'subscribe',
      'hub.topic': `https://api.twitch.tv/helix/users/follows?first=1&to_id=${
        userData._id
      }`,
      'hub.lease_seconds': 864000
    });
  1. Setup POST request:
var request = https.request(
      {
        method: 'POST',
        hostname: apiBaseHostName,
        path: webhookPath,
        headers: {
          Authorization: `Bearer ${token}`,
          'Content-Type': 'application/json',
          'Content-Length': hookParams.length
        }
      },
      response => {
        response.on('error', error => {
          console.log(error);
        });

        response.on('data', data => {
          /* No data comes back, but this is required */
        });

        response.on('end', () => {
          if (response.statusCode === 202) {
            console.log(
              '[setupFollowerWebhook] Follower webhook is listening.'
            );
          } else {
            console.log('[setupFollowerWebhook] Follower webhook was denied.');
          }
        });
      }
    );

    // Request fanciness //
    request.on('error', error => {
      console.log(error);
    });
    request.write(hookParams);
    request.end();

apiBaseHostName = 'api.twitch.tv'
webhookPath = '/helix/webhooks/hub'

  1. Receive GET hub.challenge and send back as response:
server.get('/hook/:rand/follower/:partial', (request, response) => {
  console.log(request.query['hub.topic']);
  var challenge = request.query['hub.challenge'];
  console.log(challenge);
  response.status(200).send(challenge);
});
  1. Wait for alerts that never come :frowning: :
server.post('/hook/:rand/follower/:partial', (request, response) => {
  console.log('New Follower!');
  response.sendStatus(200);
});

I believe my flow is setup properly, but for some reason I never receive any payloads. Currently I am listening to Dr. Disrespect for any new follows on his account. Would really appreciate some help if anyone has any!!

Thanks so much in advance,
-Alec

You didn’t post any data…

Possible fix:

Also what was the response you did get?

When you say node/express what are you using to MAKE the POST request, since node/express won’t do that natively.

It may help to see ALL your code.

Hey @BarryCarlyon!
I appreciate the response :slight_smile:

I have just edited the original post with more verbose code.

I receive the GET request in my callback ('/hook/:rand/follower/:partial') which I then return the statusCode & challenge.

Good point about the node/express piece. I am using the https module, which is coupled with node.

Thanks again :metal:

To confirm you are getting the 202 in response to your POST request?

Perhaps add a

server.post('*', function(req, res) { console.log('got a post'); });

Or similar to see if there is a fault in your

userData.followHook

And if you could post in full rather than snipped, I can check the whole program, but I think the fault lies in your callback that you are passing. In your challenge response you should also be able to dump out the headers to confirm those with what you sent

“To confirm you are getting the 202 in response to your POST request?”
—> Correct! After that, I receive the GET request to my callback that should have the hub.challenge. (Which can be found in server.js)

I have checked all the header params and they match up to what is expected as well as the callback URL.

I have the latest code up on a Repo located here: https://github.com/PixelogicDev/SimpleAlerts/tree/release-1.0-twitch-hooks

I tried your suggest for server.post, but to no avail. No posts were received. I feel like Im missing something super small here…

Thanks again for your help. Its much appreciated.

UPDATE:

My implementation was fine, the module I was using to create a tunnel to the public web was not.

Rule of thumb, use ngrok if you plan on using localhost haha.

Thanks for the help @BarryCarlyon!

1 Like

Ah yes. I assumed you were already running things on “web accessible” box.

But yes, your webhook server needs to be reachable from the web.

Make sure to note the limitations of ngrok (about 20 inbound requests were minute iirc)

Thats the weird part, I was using: https://github.com/localtunnel/localtunnel. Was a much better solution for me as I could use APIs to generate these tunnels. For some reason it would not process the POST requests.

Yes I ran into that first thing haha. No biggy as its just for testing and get some data. Thanks again!

Check out the node module for ngrok. You can create a tunnel on the fly at express/node start. My v1 of my personal extension rig used to do that. Mal a ngrok tunnel at boot

1 Like

Added it into my project! Thanks for the advice.

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