App Access Token with Scopes?

Hi there.
I am working on a chatbot, and I expect it to have a lot of users so I wanna move away from IRC and over to the eventsub architecture.
I’m reading the Twitch API docs and I see the following for the Send Chat Message endpoint:

Requires an app access token or user access token that includes the user:write:chat scope. If app access token used, then additionally requires user:bot scope from chatting user, and either channel:bot scope from broadcaster or moderator status.

However. I do not understand how I am meant to add a scope to an app access token when using OAuth Client Credentials Grant Flow?

Any explanation and/or help is much appreciated.

You don’t, the documentation is a little mis worded, as it’s kinda complicated:

What you do is

  • generate a user access token with the needed scopes for your bot
  • generate a user access token with the needed scopes forthe channel(s) you want to read/write to
  • store the tokens if you want for API calls
  • generatea client credentials/app access token
  • create aubscriptions on eventsub for those channels

Notes by transport type: twitch_misc/eventsub/websockets/web/chat at main · BarryCarlyon/twitch_misc · GitHub

1 Like

I see. So if I understand correctly.

  • I use the user access token for the bot with the scope user:bot (and chatting) to chat in channels.
  • I use the user access token for each user with the scope channel:bot.

But then what do I use the app access token for?
This is all very confusing :joy:
I have a decent understanding of all the other aspects, but this is pretty confusing to me.

EventSub over webhooks or conduits.

The Chat Send API also supports using an app access token.

An example:

To connect bot foo to freds channel in read/write mode

  • Generate a user access token for foo with user:read:chat and user:write:chat and user:bot
  • Ask fred to authenticate, generating a user access token with channel:bot

Once thats both done foo can read/write to freds channel using the app access token on a webhook or a conduit. And use the same app access token to send on the API

Generally in my opinion Chat Bots will use a conduit where the shard(s) are attached to a websocket.

So a conduit will require an app access token.
The Send Chat Endpoint supports both token types, as it means that your bot doesn’t have to handle multiple tokens, just the app access token to sending messages with and assigning shard to a websocket via the conduit API’s which need an app access token.

Sure you’ll still need the bot’s own user token if your bot is doing moderation actions but thats a different discussion

1 Like

Ah okay. I see.

Thank you! :smiling_face_with_three_hearts: