Node js webhook

i wanna create a subscribe to a specific channel,and if someone follow this channel or start stream with specific game,i wanna get notification that someone go online or follow me …

i already create the subscribe request with c# in unity

   public IEnumerator GetNotification()
    // POST

    string _link = "";

    _link += "?hub.topic=";
    _link += "&hub.lease_seconds=86400";
    _link += "&hub.callback=http://test/webhook/TwitchWebhook.js";
    _link += "&hub.mode=subscribe";
    _link += "&hub.secret=123456789";

    UnityWebRequest request = new UnityWebRequest(_link, "POST");
    request.SetRequestHeader("Authorization", "Bearer 7xaxy9dkaahitq6mt4uuylnzo72j5v");

    while (!request.isDone)
        yield return null;

    Debug.Log("Response code :" + request.responseCode);

i get 202 response ,but i don’t know how to menage the POST request that i get from twitch if my condition in already true … i wanna create this server with node JS … someone help me !!!

When you make the POST request to create the subscription you get a 202.

Twitch will then send a GET request to your callback.
You need to echo back the hub.callback from the query string.

Once that is done will will get POST requests containing a JSON payload in the body when data occurs/needs to be sent
Parse the payload.

Those of us working in NodeJS are doing this in Express. There are numerous samples on the forum for this (most of them deal with callback paths and verifying the payloads)

This isn’t a NodeJS support forum, it’s the Twitch API support forum. And giving you the answer won’t help you in the long run.

You can a library like express to create a Web Server to listen and respond to requests.
Then a library like got to perform the creating of webhook subscriptions.


    .get((req,res) => { res.send(req.query['hub.callback']; })
    .post(bodyparser(), (req,res) => {
        //do stuff with req.body
        var payload = JSON.parse(req.body);

This isn’t right it’s just off the top of my head

thank you barryCarlyon

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