Chatbot, Oauth2, curl requests?

So i’m working with NodeJS and have written a basic chatbot based on the tutorial that was given using tmi.js and dice rolling thing.

My purpose of the bot is to just host the api calls locally and only have it interact with my twitch account and my bot account. So what would you suggest are the workflows i should use since I am a bit confused by the oauth2.

I understand the basic principle is to request an access token valid for a certain time, with which the api request can be called and the access token needs to be refreshed. Can this process be done using a middleware of my own or is it better to use something like Passport? I don’t intend for this bot to be used by the public mostly building it to understand more coding practices etc.

I noticed most of documentation for twitch is in curl, can it be convered to a “regular” GET / POST request using something like Express or does it require a specific package.

I don’t use passport myself. I wrote my own stuff to handle token refresment.

Passport from a loose reading feels more like it’s for user session management for a website, not key management for a chat bot

cURL is universal, an example cURL call can be converted to be used in any cURL helper function that exists in the language you are working in.

Express is for serving websites, not making HTTP/cURL requests

For Node, you are looking at using fetch, got or similar cURL/HTTP fetching library

1 Like

Could you provide me with an example ? or perphaps a guide that i could follow, I feel a bit lost atm :x

Example, how to get some live streams

Docs

cURL example

curl -H 'Client-ID: uo6dggojyb8d6soh92zknwmi5ej1q2' \
-X GET 'https://api.twitch.tv/helix/streams?first=20'

NodeJS example using got

const got = require('got');

got({
    url: 'https://api.twitch.tv/helix/streams?first=20',
    method: 'GET',
    headers: {
        'Client-ID': 'uo6dggojyb8d6soh92zknwmi5ej1q2'
    },
    responseType: 'json'
})
.then(resp => {
    if (resp.data && resp.data.length > 0) {
        for (var x=0;x<res.data.length;x++) {
            console.log(res.data[x].user_name, 'is live', res.data[x].title);
        }
    } else {
        console.log('No Streams');
    }
})
.catch(err => {
    console.log(err, err.response.body);
});

Theress nothing to it, each documentation item, tells you the URL to call, the METHOD to use, any optional query strings, and JSON body stuff (for updating things).

So no really sure what you are after for a guide to follow, to convert documentation into code?!

1 Like

i couldn’t understand some of the requests but your example makes it clear, ty.

I was not able to understand how to write the options. for something like fetch / got library.

Thanks again Barry.

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