In order to develop a more long-term solution, I began looking into WebSockets and how to establish my own connection to an existing WebSocket server.
My first step was to use the Network tab on Chrome’s developer tools to monitor the WebSocket connection that was established. I made notes of all the data exchanged, the fields included, and the frequency of the messages. As a result, I was able to draft some mock messages to send to the server.
One key behaviour I was attempting to emulate was the heartbeat message that was sent to and from the server every 30 seconds.
Once I had the correct message format, I created a C# Console App and used a WebSocket library in order to establish a connection to the server. I was then able to send all the mock messages I had written before to surprising success.
I then wrote code to handle receiving messages.
Each message from the server had a different numerical ID, which made differentiating between them easy. This particular approach of simply checking if the overall string contains the ID is not secure, as if a user sent a message to the chat containing that ID, the code would pick it up, but since this was a personal project and the risk was minimal, I took this approach.
One challenge with this was that in the WebSocket messages, a user’s country is represented by a 2 letter code, and while it mostly conforms with the ISO 3166 country codes, HelloTalk for whatever reason chose to vary this slightly. One example is instead of using “GB” to represent the United Kingdom, “UK” is used.
For most country codes, I was able to use System.Globalization to convert the country code into the country name for display, but due to the quirk of the name differences I had to write some special cases to counteract this.