I’m thinking about getting back into streaming, and I thought how fun it would be if viewers could use chat commands to trigger certain events that are controlled by KM. I’m not sure what I would have it do yet, but it would definitely open up a lot of possibilities. Any thoughts on if this is doable or maybe even how?
Not unless Twitch Chat has the means to send commands to the macOS – or has a means for the macOS to monitor it via AppleEvents.
Or so I think – since I don't use Twitch.
I use NightBot which uses some JavaScript to reaction to / commands in Twitch chat. It looks like the JS is limited though, but if I can get it to load a URL, then that should work as a trigger. The closest thing I’ve found is urlfetch, but I’m concerned it will give the viewers my KM trigger URL in the chat. Here’s a page on URL fetch: UrlFetch - Nightbot Docs
I can't tell from a quick scan through the docs, but I'm not very conversant with that sort of API.
If you're running this in-browser you might be able to write an extension to monitor the stream and react to "hidden" commands: