Send Chat message

The initial token is always manual

If using code flow you’ll get a token and a refresh token
You can use the refresh token to get a new token.

But if the refresh token becomes invalid you’ll need to manually provide a token/refresh token pair

how can the refresh token can get invalid ?

Various reasons

  • it expires
  • it was revoked
  • user changed password
  • user revoked link between them and clientID

are just a few possible reasons off the top of my head

i think the first two are the criticle one. Because its my account.Do you know whats the usal time the refresh token expires ?

at time of writing Tiwtch refresh tokens do not have a published expiration.

But oAuth tokens/refresh tokens in general do have expirations

ok thanks :slight_smile: so best way is to refresh the tokens on a weekly schedule

No.

If you are using a code flow set of keys the access token expires after around 4 hours.

But for a chat bot to send messages the token only needs to be valid when the bot connects to chat. So I tend to refresh then, but my bots need valid tokens to run moderator actions so I refresh at boot and when the token expires

However if you are using the extension chat API you’ll likely need a fresh JWT every call since you shouldn’t make a JWT with am assive expiration, I tend to use 4 (up to 60) seconds when I generate a JWT and discard it after use.

I decided to use the irc. I refresh the token before every message right now which works fine.