Twitch Chatbot that provides a first user to chat after going live feature, and an automated question of the day using !qotd
.
Lots of features still to be developed and polished, this is still quite the Work In Progress.
Create a copy of of the environment variable template. You will add values to this new file as you proceed through these instructions.
If you already have a Twitch app that you can use, you may skip this step.
Follow the steps outlined at Registering Your App to register a new twitch app.
The quick and dirty way is to use a tool like https://twitchapps.com/tmi to create an OAuth token for the chatbot user. Otherwise, you'll need to follow a similar flow to below, with different chat related permissions. Twitch Authenticate Bot will get you started.
Add the username for the bot, and the OAuth token you generated to your .env
.
SOULXBOT_USER=
SOULXBOT_OAUTH=
Add your Client ID and Client Secret from your created Twitch App into .env
.
SOULXBOT_CLIENTID=
SOULXBOT_CLIENTSECRET=
In a browser goto the following, replacing the {client_id}
with your app's client_id
.
You will want to auth with the twitch channel you want to test with.
The channel:manage:predictions
is needed for the dice game predictions.
curl "https://id.twitch.tv/oauth2/authorize?client_id={client_id}&redirect_uri=http%3A%2F%2Flocalhost&response_type=code&scope=channel%3Amanage%3Apredictions"
This will redirect you to your app's redirect uri, and the redirect url will look similar to:
http://localhost/?code={user_code}&scope=channel%3Amanage%3Apredictions
Extract the {user_code}
the code that is returned. You will need it in the next step.
Send a POST
request to the URL below, replacing {client_id}
, {client_secret}
, and {user_code}
with the code you just obtained above.
curl -X POST "https://id.twitch.tv/oauth2/token?client_id={client_id}&client_secret={client_secret}&code={user_code}&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost"
You should get a response similar to:
{
"access_token": "abcd1234",
"expires_in": 14943,
"refresh_token": "123456789abcdefgh",
"scope": [ "channel:manage:predictions" ],
"token_type": "bearer"
}
Extract the access_token
and refresh_token
, then add them to your .env
file
SOULXBOT_AUTHTOKEN=
SOULXBOT_REFRESHTOKEN=
- Start the bot locally by running
go run .
- The bot has a web server running on port
8080
.- Use the
/register
endpoint, to register a user to have the bot join that stream's channel. This endpoint uses basic auth, the credentials are set with the environment variableSOULXBOT_BASICAUTH
which defaults tosoulxbot:123456
. Example:curl -H "Authorization: Basic c291bHhib3Q6MTIzNDU2" http://localhost:8080/register?username={stream_user}
This will return an API key that is used with the/golive
endpoint to inform the bot that the user has gone live. ⚠️ Currently, the bot will need to see the user say something in chat somewhere before it can successfully register them. (Bug 9/6/23)⚠️ After registering, you will need to restart the bot in order for it to join the newly registered user's channel. (Bug 9/6/23)- Inform the bot that a stream has gone live!
http://localhost:8080/golive?key={api_key}
with the API key returned from the/register
endpoint.
- Use the