Twitch Chat is a simple IRC chat. For any serious development, there are multiple documents for it, including the most comprehensive and general ressource: http://ircdocs.horse/
IRC is a basic, plaintext based TCP protocol. Connecting to Twitch works just like any regular IRC service with a difference in authenticating:
Connection Initiation > Handshake > Usage
The handshake is regularly the hardest part to get right:
After building up the connection to the server, you are required to provide PASS
and then a NICK
, where PASS
is an OAuth-Token (which you can generate here) and USER
being the username to this OAuth token.
The handshake is then as following (<
being sent from client to server, >
being sent from server to client):
< PASS oauth:your_oauth_token
< NICK your_username
> :tmi.twitch.tv 001 your_username :connected to TMI
> :tmi.twitch.tv 002 your_username :your host is TMI
> :tmi.twitch.tv 003 your_username :this server is pretty new
> :tmi.twitch.tv 004 your_username tmi.twitch.tv 0.0.1 w n
> :tmi.twitch.tv 375 your_username :- tmi.twitch.tv Message of the day -
> :tmi.twitch.tv 372 your_username :- not much to say here
> :tmi.twitch.tv 376 your_username :End of /MOTD command
Once you received either any of these MODE
, 376
or 422
, you're good to go and can send the twitch server any commands, like:
> JOIN :#gamesdonequick
> PRIVMSG #gamesdonequick :Hello world!
A more throughout guide to client-server commands can be found here.
While Twitch uses a standard IRC service, there are some events seen on the IRC service which correlate to activity in a channel on the Twitch website. Examples here are slowmode being enabled or disabled, subscriber-only mode being enabled/disabled on a streamer's chat, hosting activity, and bits/cheer activity, among others.
Details on these Twitch-specific capabilities are listed in the GitHub documentation for Twitch IRC, which can be found here.