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 Twitch Bot Bridge

Dialogflow and Twitch together at last!

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!

Where do I get it?

How do I use it?

  1. Clone the Dialogflow Twitch Bot Bridge GitHub repo somewhere where you’ll want to run a Node server (I’ve typically just run it locally on my PC/Mac). Cloning should be as simple as:
git clone
  1. Open up server.js and change dialogflowClientAccessToken to your own access token from Dialogflow.
dialogflowClientAccessToken = "YOURTOKENHERE",
  1. Change 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.

  1. Add in your Twitch channel you’d like the bot to be chatting in:
// Twitch settings
twitchChannel = '#devdiner',
  1. Add in the bot’s name (needs to be an actual account you’ve got access to!):
twitchBotName = 'PatCatTwitchBot',
  1. You’ll need a token that’ll allow you to post on that account’s behalf. Grab one from if you don’t already have one. Then put it into the twitchPassword field:
twitchPassword = 'oauth:YOUROAUTHHERE',
  1. When it comes to training up your bot, it can be a bit awkward for the messages in Dialogflow to all have @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',
  1. You could want your bot to respond instantly to anything, but that can be off-putting. People don’t respond instantly, they take time to read a message. Let’s not show just how speedy and superior our bot is to its fellow Twitch humans by adding in a delay to mimic them reading the message first. The delay is in milliseconds:
typicalDelayBeforeResponding = 1000,
  1. Humans also take time to type a message. That time is different depending on how long that message was. The Dialogflow Twitch Bot Bridge can mimic that too! You can decide how many characters per minute your bot can type and the Dialogflow Twitch Bot Bridge will delay its responses accordingly:
charactersPerMinute = 300,
  1. Finally, Dialogflow has a fallback for when it doesn’t understand something. If someone @ mentions your Twitch bot, you can decide whether it should respond or not if it doesn’t know what they mean. If your bot isn’t quite smart enough yet to respond to everything — and you don’t want your chat spammed with “I didn’t understand” type messages — you can tell the Dialogflow Twitch Bot Bridge to just not respond if it doesn’t understand instead.
keepQuietOnFallback = true;
  1. Once all is updated, run the following from root of your cloned folder to install all dependencies:
npm install
  1. Then run it like so:
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!

Would you like to republish this article in your own publication?
Contact Dev Diner to request official republication of this article.

Leave a Reply

Your email address will not be published. Required fields are marked *

Want more?