lichess-org / api

Lichess API documentation and examples
https://lichess.org/api
GNU Affero General Public License v3.0
444 stars 148 forks source link

Plaintext API results #72

Closed skrewz07 closed 3 years ago

skrewz07 commented 3 years ago

I'm a mod for a lichess streamer who uses Streamlabs' Cloudbot on Twitch, and would like to add a command that could automatically fetch the score of the current match. Unfortunately, the bot cannot parse JSON, and so cannot access any of the data within the crosstable API endpoint. Would it be possible to add some endpoints that return specific values in plaintext? Something like "https://lichess.org/api/crosstable/{user1}/{user2}/matchup/{user1}" to return the score of the first user in the current match as a plain string, and similarly with the other values. That would be greatly appreciated!

niklasf commented 3 years ago

Which programming language is the bot written in?

skrewz07 commented 3 years ago

I'm afraid I'm not entirely sure. Cloudbot is provided by Streamlabs (some info is provided here: https://streamlabs.com/cloudbot), and I don't have access to any of the bot's own code. I can add commands through the Streamlabs dashboard, but this essentially only allows me to specified what text should be returned when a command is triggered.

There is a "{readapi.}" variable that allows the bot to make API calls, and "replaces {readapi.} variable with the data from the API endpoint." Unfortunately, though, there is no way I can do any post-processing of the API data, so I cannot extract the relevant values from the JSON output of the crosstable API. I've also made a request to Streamlabs to see if they can add more functionality to Cloudbot that would allow me to process JSON data, but thought it might be worth making this request here as well.

I must admit, I do not know much about API servers, so apologies if this is unreasonable!

niklasf commented 3 years ago

Ah, ok, yeah, I think it's a bit unreasonable for API consumers not to be able to parse JSON, that's why I was asking about the programming language.

The solution would proabably be to host your own web application at some cheap or free provider, which does a request to Lichess, parses it, and produces custom output. That will also be much more flexible, both in output formats, and any custom logic you might add.