slackapi / deno-slack-sdk

SDK for building Run on Slack apps using Deno
https://api.slack.com/automation
MIT License
165 stars 27 forks source link

[FEATURE] Dynamic options in OpenForm step fields #355

Open ynkze opened 2 months ago

ynkze commented 2 months ago

Question

For instance, typically you provide some enum values in the form options:

        name: "team2",
        title: "Team 2",
        type: Schema.types.array,
        items: {
          type: Schema.types.string,
          enum: ["one", "two", "three"],
        },

Instead of ["one", "two", "three"], I have a fetchName from datastore function to get an array of names because the names might change so I do not want hardcoded enums. However for Workflow I am not allowed to add a step before OpenForm because of the following problem:

Interactivity at step 2 needs to be mapped to an interactivity in step 1's output (invalid_interactivity_pointer)

This means that I can't invoke any function via addStep prior to the form, is there a workaround?

filmaj commented 2 months ago

I am trying to understand what you are trying to accomplish, is the following correct?

  1. Run some custom step to retrieve data from a datastore
  2. Use the output of the custom step as a means of constraining the possible values for a particular OpenForm step's field's dropdown options

If the above is accurate, that's not possible at this time (at least not in the "nice" way you've described it) - though we are actively planning on adding support for this feature in the coming months. The main reason is that Workflow configurations are static and resolved at deploy-time. That is, the specific setup for the OpenForm step is defined statically and in whole via the app manifest. If you run slack manifest and inspect the contents of the workflows property in the outputted JSON, you will see the entire workflow configuration defined there.

A workaround in the mean time is to build your own form using the available interactivity features in the deno SDK. You can build a full interactive modal yourself, using all Block Kit elements available within Modals (specifically the Input block). There is one Block Kit element in particular, the externally-sourced select menu, that you can build a form in a modal with that should meet the use case you describe. Custom steps can register a 'block kit suggestion handler' to run some code at runtime whenever the externally-sourced select menu is typed into.

I have a sample app on GitHub that shows off building a full interactive modal flow using the deno-slack-sdk: https://github.com/filmaj/interactive-approval

It's an example 'approval flow' app that posts a message with an approve and a deny button. If the end-user clicks deny, it will open a fully-featured modal and implements its own form. One of these form fields is an externally-sourced select menu; in this example app it reads from a bundled .csv file to provide dynamic options in this select menu.

Hope that helps!

ynkze commented 2 months ago

Thanks for the detailed reply! What you described is exactly what I need to work with, specifically I didn't know that workflows does not have the ability to resolve dynamic values, so the interactive modal looks like a good workaround. If this feature gets implemented that's great, but in the meantime I will try the interactive modal.