Helix API Chat requests?

Bare with me I am fairly new to IRC, APIs and chat bots.
I want to pull chat for a chat bot I’m building, but I’m not sure how to do it through the API (or if I can).
I’ve seen old posts saying to use tmi.twitch.tv or irc.twitch.tv but these are either unofficial or poorly implemented (having to regex the chat message out of a JSON puke is not ideal) and a more elegant JSON format would be better.

I have scripts for things like Slots or a Dice command but I want to implement them through the API and patching it in with the unofficial, and poorly documented IRC systems is not ideal. Anyone have any ideas or am I just misunderstanding how this all works and asking a dumb noob question here?
(writing in Python as its the language I am most comfortable with.)

IRC is official and documented here

Twitch Chat is not part of Helix or Kraken (v3/v5)

Just curious if there are plans to implement chat through the API? It’s a little frustrating to have to use two methods of getting data from twitch in one program. If I want my bot to be able to see certain aspects of my channel, not only do I need to sit in IRC to wait for commands, but I also need to poll the API for data as well. Makes it a little more complex than desired.

It is.

The API is called TMI which is Twitch Messaging Interface which is an API, that API provides an IRC “compatible” interface.

There are no plans to put it in Helix as a endpoint as that doesn’t really make sense for that much real time data/stream. Of course I don’t work for Twitch and that plan could change.

1 Like

Oh ok that makes sense. At the moment I need to regex a string to get Usernames, the message and the channel it was sent in. Is there a possibility I’m doing this wrong and there is an easier way where all this data is separate from one another and accessible by parsing a JSON object?

username = re.search(r'\w+', response).group(0)
        chat_msg = re.compile(r'^:\w+!\w+@\w+\.tmi\.twitch\.tv PRIVMSG #\w+ :')
        message = chat_msg.sub("", response).rstrip('\n')

Just use a IRC library suitable for your language of choice. (You’ve not mentioned which language you are working in)

It’ll save time and effort if you use the work of others. And most libraries have a relatively mature library for IRC.

Alternatively you can find a library for TwitchChat for most languages being actively developed.

You can join the Twitch libraries Chat discord via https://dev.twitch.tv/support/ for more advise from the community

1 Like

For example:

username = irc['username']
message = irc['message']
channel = irc['channel']

I am already using a library for my Bot, but my chat client I want to integrate does not. I suppose I should look into converting it to use the IRC library

In Conclusion, I’m dumb.
The IRC library turned my mess into exactly what I wanted (JSON that can be parsed for data). Thank you so much for your help and insight and sorry I asked such a silly question.
Snippet from my code:

    def on_pubmsg(self, c, e):

    # If a chat message starts with an exclamation point, try to run it as a command
    if e.arguments[0][:1] == '!':
        cmd = e.arguments[0].split(' ')[0][1:]
        print('Received command: ' + cmd)
        self.do_command(e, cmd)
    # If it is any other chat message, print the username and message to the console
    else:
        # Get message
        message = e.arguments[0]
        # Get Username from tags
        username = e.tags[2]['value']
        print(username + ': ' + message)
    return
2 Likes

No problem, the only silly question is the unasked one!

3 Likes

Have a nice day :slight_smile:
and thanks again!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.