slackapi / deno-slack-sdk

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

[QUERY] Custom Workflow Steps - Checkboxes #339

Closed mcsescott closed 1 month ago

mcsescott commented 1 month ago

I'm building a custom workflow step (done many of them), and now trying to add some checkboxes to the modal/form/configuration step.

According to the documentation when specifying an array, I can have a display_type of checkboxes, however I can't get it to work. No errors when doing a slack run, it just doesn't show it as checkboxes. It still shows it as a dropdown. I'm not trying anything fancy, just using the sample array definition from the example provided.

export const datefunctions_FunctionDef = DefineFunction({
  callback_id: "date_functions_function",
  source_file: "functions/date_functions.ts",
  title: "Date Functions",
  description: "Hi filmaj",

  input_parameters: {
    properties: {
      "departments": {
        "title": "Your department",
        "type": "array",
        "items": {
          "type": "string",
          "enum": [
            "marketing",
            "design",
            "sales",
            "engineering",
          ],
        },
      },
      "departments_with_checkboxes": {
        "title": "Your department (this should be checkboxes)",
        "type": "array",
        "items": {
          "type": "string",
          "enum": [
            "marketing",
            "design",
            "sales",
            "engineering",
          ],
        },
        minItems: 2,
        display_type: "checkboxes",
      },
    },
    required: [],
  },
//...

image

I've even tried the following, and this doesn't work either:

      inputstring: {
        type: Schema.types.array,
        title: "Your input expression", //The variable used for subsequent steps
        items: {
          type: Schema.types.string,
          enum: ["marketing", "design", "sales", "engineering"],
        },
        display_type: "checkboxes",
      },

So... How to add checkboxes in a custom workflow configuration step, or am I reading the documentation wrong and it isn't supported?

filmaj commented 1 month ago

Hey @mcsescott 👋 I am still investigating this, but I believe this parameter should not be documented for coded workflow builders. I am still getting confirmation but I believe this parameter is only used by the Workflow Builder UI. It doesn't make sense to me that a custom function in a coded workflow context has any concept of 'appearance', as coded workflow custom steps are UI-less.

filmaj commented 1 month ago

I have confirmed that custom functions should not be setting display_type on their input parameters. It's a bit of convoluted problem, but essentially display_type should be used in OpenForm steps. You can create a form to collect input via OpenForm, and you can specify different input fields to include in the form. You can specify an Array-type input field for the form, and it is with certain kinds of array OpenForm input elements that you can specify display_type. For example, with this workflow step:

SampleWorkflow.addStep(Schema.slack.functions.OpenForm, {
    title: "Give someone kudos",
    interactivity: SampleWorkflow.inputs.interactivity,
    description: "Continue the positive energy through your written word",
    fields: {
      elements: [{
        name: "doer_of_good_deeds",
        title: "Whose deeds are deemed worthy of a kudo?",
        description: "Recognizing such deeds is dazzlingly desirable of you!",
        type: Schema.types.array,
        items: {
          type: Schema.types.string,
          enum: ["one", "two", "three"],
        },
        display_type: "checkboxes",
      }],
      required: ["doer_of_good_deeds"],
    },
  }
);

... you would get this kind of form rendering:

Screenshot 2024-07-18 at 2 39 36 PM

I'm still following up to figure out what other kinds of array types can be used w/ display_type. I tried with, for example, an array of plain string, but would get an invalid_form_inputs error at runtime. This makes sense: an array of generic strings can't be explicitly enumerated into checkboxes, but an array of string enums can. So this tells me this display_type property on OpenForm can't apply to any type.

filmaj commented 1 month ago

OK, did more digging through this code, I am 99% certain display_type only applies to:

... just like the example I posted in my last message.

Docs are being updated as I type this!

Apologies for the confusion and the wait 🙇

mcsescott commented 1 month ago

Thanks for checking and the follow-up. I'm all about workflows and custom steps, so just wish they had a bit more flexibility on things that we can do with regular modals.

lukegalbraithrussell commented 1 month ago

Hey @mcsescott, docs are officially updated. I'm going to close this issue, but feel free to reopen or open a new issue if needed!

mcsescott commented 1 month ago

Thanks; I see the updated documentation, Please realize this is for a custom step with Workflow builder, not for an OpenForm step.

Consequently, this has always been an issue with Slack's documentation - the options for custom steps in Workflow Builder (both legacy and NextGen) have always been poorly documented, as some things just don't work.