Connect to IRC without User Access Token

I’m making a simple bot that reads chat and stores messages that contain certain substring in a database

It seems that I don’t have any options but connecting to IRC. I don’t want to manually generate Access Token every time the old one got expired, I’d like to automize getting the code since all I need is to read chat.

My code is executed on backend so at first I was trying to use Client credentials grant flow. I’m able to get App Access Token using that flow, but IRC resopnds with “Login unsuccessful” error. I guess it’s because App Access Tokes doesn’t have any scopes.

Then I created a twitch user specially for my bot (I’ll call it bot-user) and tried Authorization code grant flow, but as I can see there is unskipabble step of navigating to an authorization page to get authorization code. I’ve authorized my bot-user (by going to that page manually and clicking ‘Authorize’ button) and it seems that I don’t have to click the button every time, but I still can’t figure out how to automize getting the code.

All I want to do is to read a chat on a certain steram, since I can see the chat even if I don’t have a twitch account I assume it’s possible, so basically there are two questions:

twitchSocket = new WebSocket(“wss://irc-ws.chat.twitch.tv:443”);

twitchSocket.addEventListener(‘open’, () => {
twitchSocket.send(PASS oauth:${oAuth});
twitchSocket.send(NICK ${nick});
twitchSocket.send(JOIN #${channel});
});

How do I get oAuth token with chat:read scope without authorization?

or

const postData = {
client_id: “myclientid”,
client_secret: “myclientsecret”,
code: “HOW DO I GET IT WITHOUT MANUAL AUTHORIZATION”,
grant_type: “authorization_code”,
redirect_uri: “http://localhost.”
};

const requestOAuth = await axios.post('https://id.twitch.tv/oauth2/token',postData);
oAuth = requestOAuth.data.access_token;

How do I get authorization code withong going manualy to authorization page? I’ve got my bot-user, can I use it to authorize automatically?

Oh, and I was trying to figure out how to refresh a token, it seems like it can be revoked by twitch and I can’t say it’s clear to me under what circumstances it can happen :smiley: and in that case I’ll have to regenerate it maually again, so I guess it’s not thae way to go. Am I right?

And thanks for any help <3

Client Credentials/app access tokens do not represent a user.

Hence the login fail

Yes that is how oAuth works

Basically you can’t if/when you need to give it new keys it’s manual

You don’t it requires manual steps

In theory you will only need to do it once.
And then use the refresh token to get a new user token, ad infinatum.

Additionally for chat the user token only needs to be valid when the bot (re)connects to the chat socket. as when the token ties you do not get DC’ed

That is unless the refresh token dies and then you need to reseed the system with a new keyset.

Thanks. I figured out what concept of refreshing token is about. It’s what I was looking for.

It’s still strange that I need a user to read the chat that web client can see even if I dont’ have a twitch account, but my looking bot works now without manual actions <3

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