slapdash / platform

Docs, tools & examples for extending Slapdash.
https://slapdash.com/developers
29 stars 11 forks source link

Execute a command only when an option is selected #20

Closed Glyphack closed 1 year ago

Glyphack commented 1 year ago

I'm developing an app that lets users manage AWS infrastructure, and I want to implement an action that triggers a command only when it's selected. To give an example, I want to have this option:

{
    type : "some-action",
    action: resource.destroy()
}

The issue is with the way slapdash is working now. I cannot run resources.destroy() command only when the option is selected. It always gets executed when rendering the response.

This is more of a question than an issue. Is it intended to use slapdash like this?

I was thinking of finding a way to implement a hook mechanism to execute a command inside the program when the copy action is called.

oleg-slapdash commented 1 year ago

@Glyphack, Slapdash does not share the same execution environment as the script/API endpoint. As a result, we cannot call a function that is referenced somewhere in 3rd party code (in this case resource.destroy()).

However, Slapdash can tell 3rd party script to do something. What - depends on the script/API endpoint. The way how we "tell" is by sending parameters to the script/API Endpoint. How Slapdash knows to send parameters? We have an "action" property for each option which is triggered when user selects it. Doc: https://platform.slapdash.com/reference/command-response-action

One of these actions is to add a parameter. When that happens, the script/api endpoint will be called again with the new parameter and at that point you can detect it and call a function.

I hope that answers your question!

Glyphack commented 1 year ago

Thanks for the detailed answer @oleg-slapdash. The move action is really nice, I've used it to enable users to specify the resource to interact with but it's mentioned that only one move action is supported at the moment.

I'm moving forward with read-only commands right now, and this can be left as an improvement once it's possible. I'm closing the issue.