I have created a bot who works just fine. It’s an Overwatch assistant to check identity of players who participate to contests organised by streamers directly in Twitch chat.
It’s working like a charm on my account, now I would like to “add users” to this bot but I do not know how to enable this bot to others and add the bot to their channel.
I use tmi.js to make this work and I can see a “channels” in the settings.
I went to an idea : do I need to code a frontend to get users oauth-token and store it in a database of users (streamers here)?
I found many tutorials to code and deploy, but I can’t find examples to allow new users to use your bot.
The bot sends /join #channelname it’s then in that channel. So you need to figure out how/the best way for you to instruct your bot to do that
Correct. That is what I would build and have built.
Some people will use a web panel to allow people to login and add a bot.
Other people will let the bot be in the bots own channel, and casters can use !join to make the bot join their own channel.
I prefer the web panel approach since I have other bot controls in the same panel and need oauth permissions for various other things tied to the bot.
The bot at boot can load the channels to join from storage and away you go.
The bot will also need a way to be communciated with to join new channels without fully restarting the bot each time to add a new channel.
But that only handles joins at startup, not whilst the bot is running.
You don’t want to have to restart the whole bot every time someone new signs up to use your bot.
You might want to use the API for subscriber status, or the dashboard panel be used by moderators, so you’d need the broadcasters token to get moderator status from the API.
Or use EventSub to get stream online/offline status sent to your system automatically (for !uptime commands for example, why do an API call to get stream status if you already have the start time in your DB) and make the EventSub cost be 0.
Otherwise you are limited to 10k subscriptions. on eventsub, but auth’ed subscriptions are cost 0.
Okay if I understand well, my script is working fine as long as it does not crash or as long I don’t need to add someone else. So to add dynamically users, I do need to build an express server with a POST endpoint like https://my-bot-url.com/join.
So I have to create an application
To sum up
Build a basic front-end with auth (connected with Twitch API to get user’s access_token).
Store user’s oauth token in database and allow dashboard to streamer and moderators.
Add a classic button in dashboard to call the POST /join endpoint on server express (aka the bot) to add the bot to the streamer channel.
I went with Firebase for multiple reasons (but for discovery purpose mainly).
I managed to fetch my “streamers” collection when the bot start, I also made a specific account to my bot. I added a route /join an channel and another one /part to make the bot leave a channel and seems to work properly.
I’m just having some trouble to the connection because I get a permission error when I try to ban someone:
[16:58] info: [#carbow] You don't have permission to perform that action.
Error banning azehoss00313: no_permission
Do I have to use OAuth client credentials flow when bot login ? or can I pass manually the token in an .env file ? Which scope allow me to ban some ppl if it’s not channel:moderate (Perform moderation actions in a channel. The user requesting the scope must be a moderator in the channel)?
That is the part when my brain is breaking down haha
I’ve made a bot (which is an app technically) but act like a user and has the same auth code flow as a user. I’ve already implemented the OAuth Authorization code flow but with this GET http call (from the bot) but I get redirected and can not grab the access_token which is in url and it’s not in response body.
So I guess I have to
make a front-end
auth the user from the front-end with OAuth authorization code flow (wich is a HTTP GET call) and get redirected to the front-end (I do not know how to grab the token from url in the backend otherwise…).
The user click to a basic button to add the bot to his channel, making a call to my backend /join.
On the join I send this specific token generated by the user in the front to the back-end (bot) and create a client with this token for each user who is signing ?
The code is NOT an OAuth token, it must be exchanged for an Access Token and Refresh Token, which can only be done server-side, as Barry explained.
Once your bot has the users access token, you can then have your bot join the channel associated with that token. You can also periodically check the validity of that connection to your app by the user and if they have revoked access you can have your bot part their channel.