This is the Twitch bot I use for https://twitch.tv/matthewdgroves. It’s a tool for making the channel more useful and enjoyable, but it’s also a tool for me to dogfood Couchbase Server (as well as ASP.NET/C# stuff).
Here’s a breakdown of each project
This project has a class MattsChatBotHostedService
. This implements IHostedService, which means it’s designed to be run as a hosted service in an ASP.NET Core project. However, MattsTwitchBot.Core is not, itself, an ASP.NET Core project.
MattsChatBotHostedService
uses the TwitchLib API to listen for incoming messages. A message will instantiate some Request object, which will then be given to Mediatr to handle.
What you need to know to get it to work: put your Twitch OAuth key and ApiClientId/Secret into appsettings.Development.json. I use my own Twitch user account as the bot, but it should still work fine if you are using a separate bot account.
This is an ASP.NET Core 3 project. It does up to three things:
-
Start and host the
MattsChatBotHostedService
service from the Core library. -
Provide a home page that will receive messages from a SignalR hub. This home page can be used from within your OBS setup. You can just open it directly in Chrome if you’d like (which is what I do for now). It is responsible for popups, sound effects, anything that I want to be seen/heard on the stream.
-
(Experimental) Receive notifications about documents being updated in Couchbase to the Couchbase Notify endpoint. This currently doesn’t do anything, it’s experimental, but it’s part of my dogfooding goals.
These are unit tests (and supporting fakes). Currently only testing the various handlers.
Create your own appsetting.Development.json file. You can just rename the sample appsetting.DevelopmentTemplate.json.
Put your various Twitch tokens, Couchbase connection/credentials information in here. Also enter a "bearer token" for authorization purposes. Only you will need to know this token. Make it something secure in production, something easy in development. Once the bearer token is validated, it will be put into a cookie, so you don’t need to use it with every single HTTP request.
Currently you still need to do some manual setup of the Couchbase node. You will need to setup the cluster (you only need the data service at this point, but you should probably add query/index, and you will need eventing for the experimental stuff).
Create a bucket called "twitchchat" (or change the name in Startup.cs if you want something different).
Right now, there are only two pages:
-
/
(home) - this is the page meant to be displayed on Twitch (put a url into OBS like http://foo/?token=mytoken) -
/profile/<twitchusername>`
- this is the page to edit a user profile (for instance https://foo/profile/calvinaallen?token=mytoken)