Getting Java to talk variables with C# for Twitch Integration

So, yeah. I’m well aware that this is a complex thing for where I’m at, but for the sake of the project we’re working on, I’d really like to get twitch integration for the success of the game, and the sooner I learn, the better. As far as I can tell, Twitch Chat only likes to talk Java to me.

I just want to present Twitch chat with a vote option randomly from a list of variables, then have it send a variable for C# to pick up.

Does anyone have experience in the matter? Or at the very least can explain enough Java to get me started?

Are you talking about the Twitch web api?
https://dev.twitch.tv/docs/v5/guides/using-the-twitch-api

This is a fairly standard web-api that prefers sending messages as json.

It doesn’t “talk Java” at all (and I believe there’s a hint of mixing up java and javascript in that statement as well… since the web-api implies browser integration which is often written with javascript, not java).

C# is fully capable of sending and receiving http requests that include json as the message format.

Furthermore, people have written C# libraries that wrap around the web-api for easier integration:
https://github.com/swiftyspiffy/TwitchLib

Thanks. When looking at Twitch’s downloads, it only appeared to be offering everything in very specific formats; Java, Javascript, and Python as seen here: https://dev.twitch.tv/get-started

Java/ Javascript is not something I’ve touched on much at all, so it’s a bit foreign to me, so it’s good to know that it’s more JSON based.

I really appreciate the help! Again, well aware that this is a bit above my level of complexity, but the sooner I understand it, the more I’ll understand in general.

Ok, yeah, so that’s just example code showing you how to use it.

But really… the api is just a simple http web interface. As you can see from the examples they’re using very basic web sockets to access it:
https://github.com/twitchdev/chat-samples/blob/master/javascript/chatbot.js

C# has several classes to help with communicating similarly.

Really you can use any language out there to communicate with it, as long as you can write some manner of sending http requests. Of course the libraries for some languages have built in tools that make it easier than with others. The examples supplied just go with popular languages… Java, Javascript, and python are like the top dogs when it comes to such development. Javascript because it’s the defacto web-centric language, python because it’s the popular go to all-purpose cross-platform language, and Java because it’s one of the most widely used enterprise languages.

Googling for “C# twitch example” came up with several starter tutorials to get you going.

Here’s one that uses the TcpClient to create a chatbot (built in C# class, as opposed to any 3rd party library):

The general process of how they’re communicating with the web interface is straight forward. Basically the client connects to a web address, and you send it messages. Each web address is a different feature from the api, and the message you send is formatted the way it expects it to be.

When you go through the Twitch API documentation (linked earlier in my previous post), it’ll tell you the web address that functionality is located at, and the format of the messages to send, and the format of the messages you’ll receive.

You take care of the rest. Parse that json as needed.

Thanks again. I guess I kept searching the wrong terms, probably because I still thought there was some need for conversion.

Hm. Even following that tutorial to the letter, I’m getting a fair amount of errors. I’m following every step of the tutorial, trying it out both in Unity and in the standalone Visual Studio and neither one likes what I’m trying to do.

I’m not sure if the tutorial is out of date or he glossed over some part of the setup.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.IO;


namespace TwitchBot
{
    class IrcClient
    {
        private TcpClient tcpClient;
        private StreamReader inputStream;
        private StreamWriter outputStream;

        public IrcClient(string ip, int port)
        {
            tcpClient = new TcpClient(ip, port);
            inputStream = new StreamReader(tcpClient.GetStream());
            outputStream = new StreamWriter(tcpClient.GetStream());

            outputStream.WriteLine("PASS " + password);
            outputStream.WriteLine("NICK " + userName);
            outputStream.WriteLine("USER" + userName + " 8 * :" + userName);
        }
    }
}

By this point, Unity wants me to get rid of everything except “using System.Net.Sockets;” saying everything else is not needed. And doing so creates quite a few more errors.

Standalone Visual Studio just doesn’t like it. I ran the exact same setup as far as I can tell, creating a new project under the name TwitchBot, then adding the item “IrcClient” and it’s still not playing nice. Any advice?


Actually, pardon me, I just realized the problem that was right in front of my eyes. This is embarrassing.