Badge Chat Bot and oauth flux

Hello,

I am still working on building my bot, and it is currently functioning very well. However, I would like to add some new features, and I’ve hit a roadblock with one of them: the “chatbot” badge. I am currently using a library (TMI.js), but I would like to move away from it and handle everything myself.

The issue isn’t with reading or sending messages—I have that part working—but I’ve noticed that my bot doesn’t display the “chatbot” badge. I’ve tried various authorization methods and approaches, but nothing seems to work.

For context, my bot has its own clientId, token, and refresh_token (obtained via the OAuth flow).

As I understand it, the OAuth flow needs to be authenticated using the streamer’s account—which, if I’m not mistaken, grants the channel:bot permission and ensures proper authentication. The problem is that if I do this, it feels like I’m no longer acting on behalf of my bot, but rather on behalf of the streamer… since the sender_id must correspond to the account that generated the token.

So, my question is: how should I correctly execute the OAuth flow?

Thanks in advance! :slight_smile:

For the Send Chat Message endpoint with an App token, you can go through the OAuth process twice, first with the user you wish to send messages as (ie, your bot account) with the user:write:chatand user:bot scopes, and then the channel you wish to send messages in goes through the OAuth process and grants your app the channel:bot scope.

Once those accounts have authed with your app, your app can then use the Client Credentials OAuth flow to get an App token which can then be used on that Send Chat Message endpoint with the broadcaster_id set to the channel you wish to send messages in, and sender_id set to the ID of your bot account.

For refernece TMI.js send/recieves over IRC and needs the user token to run with, hence the roadblock.

And to cite notes/docs

My notes are here: twitch_misc/eventsub/websockets/web/chat at main · BarryCarlyon/twitch_misc · GitHub

Twitch Docs here: Authenticating and Setting up EventSub | Twitch Developers

Whic describes as well the triple legged approach Dist covered

Things are looking pretty good. I had misunderstood a subtle point, which resulted in me having two applications instead of one.

So, I’ve now consolidated this into a single application, with one token for the user side and another for the broadcast side.

However, I’m running into an issue with two subscriptions: channel.chat.notification and channel.chat.message.

When I attempt to subscribe, I receive a 403 error: message: 'subscription missing proper authorization'.

I’m struggling to see where the problem lies. I have the user:read:chat and user:bot scopes for the bot side, and the channel:bot scope for the broadcast side. Yet, whether I use the bot token, the broadcast token, or an app-access token (obtained via grant_type: 'client_credentials'), it still doesn’t work.

Additionally, when I send a message via the API, the bot is correctly identified as a “Bot,” but it doesn’t appear within the community.

Thanks in advance for your help!

  1. When logged into bot account bottymcbotface of ID 123123 click a link of clientID foo with the scopes user:read:chat and user:bot.
  2. Send the broadcaster someBroadcaster of ID 696969 a link of clientID foo with the scopes channel:bot
  3. You now have two user tokens, you don’t need to hold on to these in this example but may if you get other scopes for endpoints that need User Tokens
  4. Using Client Crednetials flow, create a token with no scopes for clientID foo here generated as ClientCredentialsToken
  5. Create a subscription using

URL/Docs: Reference | Twitch Developers

Headers:

Client-ID: foo
Authorization: Bearer ClientCredentialsToken

Body:

{
    "type": "channel.chat.message",
    "version": "1",
    "condition": {
        "broadcaster_user_id": "696969",
        "user_id": "123123"
    },
    "transport": {
OMMITTED
     }
}

Where the transport is either a webhook or a conduit. The format of the payload condition is the same for channel.chat.notification

The usual mistake here is that the userID’s in the conditions are wrong.

Bonus:

Using: Reference | Twitch Developers

GET https://api.twitch.tv/helix/authorization/users?user_id=696969&user_id=123123

Headers:

Client-ID: foo
Authorization: Bearer ClientCredentialsToken

And you cna spot check easily what permissions you have on that clientID for both users in your condition

So, if I understand the approach correctly: since I am using the credential flow for the app token, I can no longer use the websocket for this part—instead, according to the documentation, I must use the webhook. Is that right?

Not quite: and referenced in my notes: twitch_misc/eventsub/websockets/web/chat at main · BarryCarlyon/twitch_misc · GitHub

requires topic to be created with user access and won’t have user_id in the condition in the bot list

  • Straight websockets - no

requires topic to be created with app access and will have user_id in the condition in the bot list

  • Straight webhooks - yes
  • Conduits websocket shard(s) - yes
  • Conduits webhooks shard(s) - yes

Given that a conduit can have more than 1 shard (I don’t atm) and shards on a conduit can be a mix of transport types or all the same.