How to Connect to Twitch Chat IRC through Elixir + ExIrc

Roger Lam
2 min readFeb 7, 2016

--

When learning a new language, I have the most fun creating and tinkering so let’s get some instant gratification!

I’m going to assume you’ve installed Elixir and read through a couple sections in http://elixir-lang.org/getting-started/introduction.html. This post won’t be rigorous or expose many concepts of Elixir but will guide you through connecting to a Twitch chat room from your Terminal using Elixir in Interactive mode.

I’ll be using Erlang/OTP 18, Elixir 1.2.1, and ExIrc 0.9.2. https://github.com/bitwalker/exirc

  1. Clone https://github.com/bitwalker/exirc by running:
git clone git@github.com:bitwalker/exirc.git

2. Change into that directory and run mix deps.get to download dependencies.

cd exirc
mix deps.get

3. Run iex -S mix to run an Interactive Elixir terminal with the Mix project loaded.

iex -S mix

4. Follow this answer on SO to get started. A more detailed explanation and additional command can be found on the ExIrx README.

{:ok, client} = ExIrc.Client.start_link
{:ok, handler} = ExampleHandler.start_link(nil)
ExIrc.Client.add_handler(client, handler)

5. You’ll want to read up on how Twitch IRC works but the gist to connect is here:

The server name to connect to is: irc.twitch.tv.

The port to connect to is 6667

SSL is not currently supported for Twitch IRC

Your nickname must be your Twitch username in lowercase.

Your password should be an OAuth token authorized through our API with the chat_login scope.

The token must have the prefix of oauth:. For example, if you have the token abcd, you send oauth:abcd.

You can quickly get a token for your account with this helpful page (thanks to Andrew Bashore!).

You’ll need to generate an OAuth token from the link above for your password.

6. Connect to the Twitch IRC server

ExIrc.Client.connect!(client, "irc.twitch.tv", 6667)

7. Set up your user and password, login and join the channel of your choosing!

pass = "oauth:mysupersecretoauthtoken"
nick = "my_username_in_lowercase"
ExIrc.Client.logon(client, pass, nick, nick, nick)
ExIrc.Client.join(client, "#username_of_twitch_channel")

Warning: NSFW Language below. ¯\_(ツ)_/¯

As you can see, Twitch chat emotes such as 4Head and Keepo are logged in the console as their text strings. Storing the number of occurrences is the first step to generate the Kappa per minute in chat. My goal is to have a working dashboard by the Shanghai Majors main event on March 2nd.

I’ll likely be leveraging a version of Sliding Window as described in Michael Noll’s post and Storm’s starter tutorial Rolling Top Words.

Stay tuned!

--

--