Twitch bots can be a whole lot of fun, they respond to key words, commands like !shoutout and common actions like users joining chat. However, what if they could be smarter? Have a conversation? Chime in on conversations happening in stream? That’s what I tried to make possible with my Dialogflow Twitch Bot Bridge — available for free on GitHub.
Dialogflow is a fantastic way to create a virtual assistant which can understand a range of sentences and contexts. It also works across a range of platforms from Google Home to Facebook Messenger. I’ve even got a whole online course coming soon with articles teaching people how they can build their own virtual assistant/chatbot with the platform. However, up until now, there wasn’t any clear way of getting it to work with Twitch. So, I built a way!
It is still early days and I’m certainly going to add more features to it over time, but it does indeed work! It is a Node server that I’ve run on my PC (and my Mac) to successfully have a bot regularly hanging out in Twitch streams! You can find the code for it on the Dialogflow Twitch Bot Bridge GitHub page. It’s free to use, and if you use it, I’d love for you to tweet me some examples at @thatpatrickguy!
https://github.com/patcat/DialogflowTwitchBotBridge
git clone https://github.com/patcat/DialogflowTwitchBotBridge.git
server.js
and change dialogflowClientAccessToken
to your own access token from Dialogflow.dialogflowClientAccessToken = "YOURTOKENHERE",
genericIntents
to list which intents in your Dialogflow agent should apply to the general chat in the room (e.g. run them even if your bot isn’t mentioned directly in the message):genericIntents = [{
intent: "smalltalk.greetings.hello",
freq: 0.5
},
{
intent: "smalltalk.greetings.bye",
freq: 0.5
}],
You can change the frequency they’re run too. For things like hello and goodbye… the bot will be watching out for those all the time — so if everyone is saying the word “Hello”, your bot would theoretically try to respond to that every time. freq: 0.5
adds a bit of randomness to it and sets up a 50% chance it’ll actually respond instead. Use this to prevent your bot from constantly triggering generic responses, while also letting it get involved in chat occasionally.
// Twitch settings
twitchChannel = '#devdiner',
twitchBotName = 'PatCatTwitchBot',
twitchPassword
field:twitchPassword = 'oauth:YOUROAUTHHERE',
@YourBotUsername
constantly. That’s not really pronounceable or what Dialogflow expects. So instead, we set a name that isn’t the username to replace any instances of the username with (e.g. you could use say “Barry” for @BarryAllenRunBarryRun
as an example):genericName = 'Barry',
typicalDelayBeforeResponding = 1000,
charactersPerMinute = 300,
keepQuietOnFallback = true;
npm install
node server.js
With that, you should have a successful Dialogflow Twitch bot! Enjoy and don’t forget to send me examples of what you create with this to my Twitter at @thatpatrickguy! I’d love to see what you create!
Know other emerging tech enthusiasts who might want to read this too? Please like and share this post with them!