theastropath / Astronomibot

A little Twitch bot I've been working on
3 stars 1 forks source link

Custom API interface #14

Closed theastropath closed 7 years ago

theastropath commented 7 years ago

Sometimes it would be nice to be able to have the bot turn a device on or off (Smoke machine? Popcorn maker?).

At its core, I see this as an interface where you would be able to make a call out to a URL and we would handle the response. In my case, with a Vera home automation system, you can access a URL that will trigger a scene. This means that you can set up the actual activity that should be happening within the realm of the home automation system, and merely trigger it from the bot.

The ideal way to implement this would likely be to have a configuration "command" that would result in replaceable strings that could be inserted into a regular CustomCmd. In other words: 1) Create an HA Interface: !Automate create popcorn

This would make "popcorn" a triggerable string that could be used in a custom command

2) Create a custom command that calls the triggerable string: !addcom !popcorn Time for popcorn! $AUTOMATE(popcorn)

3) Run the command: !popcorn responds with: "Time for popcorn!"

When the command is run, it encounters the triggerable string, strips it from the response, and calls the URL associated with the string.

theastropath commented 7 years ago

This can actually be extended to support custom APIs like Nightbot does. Instead of !automate, you could create an API interface by doing !api instead.

For the replaceable string in the custom command, there could be two now. One would access the URL and replace the string with the response from the URL (eg. $API(popcorn) ). The other would just access the URL and delete the replaceable string (eg. $SILENTAPI(popcorn) ).

The silent API replaceable string could still be used for automation as per the original description, but could also be used for other (unknown) purposes.

API creation would be restricted to mods and the broadcaster, for the sake of security.