slackapi / deno-slack-sdk

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

[QUERY] Define Default Value for Type Rich Text in OpenForm step #239

Open baycak opened 10 months ago

baycak commented 10 months ago

Hi,

For the context I have building a Slack App which can submit a form to Slack Channels, with a capability to do Edit for form which already being submitted. Then one of the fields I'm using is using type Schema.slack.types.rich_text.

The question is, is there any way to define default value for type Schema.slack.types.rich_text within a Workflow Form? Since value from type Rich Text is defined as Block Kit instead of plain text

Thank you!

filmaj commented 10 months ago

Yes, you should be able to define an initial_value on it. See the Rich Text Fields reference.

Does that solve your issue?

baycak commented 10 months ago

Is the initial_value are correct property to be define? Since I'm using Schema.slack.functions.OpenForm instead of Slack Modal. From the documentation itself is using default

The error I've got is attached below when I'm trying to define default value of type Rich Text

parameter_validation_failed - Validation for parameter `fields` failed: elements_param_validation_failed - form_input_types_validate_fail
filmaj commented 10 months ago

@baycak can you post your full OpenForm step configuration, including all the fields ?

baycak commented 10 months ago

Attached below @filmaj ,

Open snippet code here ```javascript /** * For collecting input from users, we recommend the * OpenForm Slack function as a first step. * https://api.slack.com/automation/functions#open-a-form */ const inputForm = UpdateRequestTestingWorkflow.addStep( Schema.slack.functions.OpenForm, { title: 'Update QA Testing Form', interactivity: prevInputForm.outputs.interactivity, submit_label: 'Update', fields: { elements: [ { name: 'title', title: 'Title', type: Schema.types.string, default: prevInputForm.outputs.title, }, { name: 'description', title: 'Description', type: Schema.slack.types.rich_text, description: 'Fill the description as detail as possible', default: prevInputForm.outputs.description, }, { name: 'mentioned_to', title: 'Mentioned to', type: Schema.types.array, items: { type: Schema.types.string, enum: [ 'dummy' ], }, description: 'A user groups which responsible to do a QA test', default: prevInputForm.outputs.mentioned_to, }, { name: 'ui_stage', title: 'UI Stage', type: Schema.types.string, description: 'Testing environment for UI', default: prevInputForm.outputs.ui_stage, }, { name: 'api_stage', title: 'API Stage', type: Schema.types.string, description: 'Testing environment for API', default: prevInputForm.outputs.api_stage, }, { name: 'priority', title: 'Priority', type: Schema.types.string, enum: ['Very High', 'High', 'Medium', 'Low', 'Very Low'], description: 'Testing priority', default: prevInputForm.outputs.priority, }, { name: 'estimated_release', title: 'Estimated Release', type: Schema.slack.types.date, description: 'Estimated release feature / enhancement / bugfix to Production', default: prevInputForm.outputs.estimated_release, }, { name: 'notion_link', title: 'Notion Reference', type: Schema.types.string, description: 'Fill if necessary', default: prevInputForm.outputs.notion_link, }, { name: 'jira_link', title: 'Jira Reference', type: Schema.types.string, description: 'Fill if necessary', default: prevInputForm.outputs.jira_link, }, { name: 'mr_gitlab', title: 'MR Gitlab', type: Schema.types.string, description: 'Fill if necessary', default: prevInputForm.outputs.mr_gitlab, }, { name: 'apk_build_link', title: 'APK Build Link', type: Schema.types.string, description: 'Fill if necessary', default: prevInputForm.outputs.apk_build_link, }, { name: 'device_type', title: 'Device Type', type: Schema.types.string, description: 'Fill if necessary', default: prevInputForm.outputs.device_type, }, { name: 'os_version', title: 'OS Version', type: Schema.types.string, description: 'Fill if necessary', default: prevInputForm.outputs.os_version, }, { name: 'cc', title: 'Cc', type: Schema.types.array, items: { type: Schema.slack.types.user_id, }, description: 'Let others know about the QA test request', default: prevInputForm.outputs.cc, }, ], required: [ 'title', 'description', 'ui_stage', 'api_stage', 'priority', 'mentioned_to', ], }, } ); ```
And for the value of description, can be seen here ```json [ { "type": "rich_text", "block_id": "GS0LV", "elements": [ { "type": "rich_text_section", "elements": [ { "text": "gasfgasdfasdf", "type": "text", "style": { "bold": true } }, { "text": "\n", "type": "text" } ] }, { "type": "rich_text_list", "style": "ordered", "border": 0, "indent": 0, "elements": [ { "type": "rich_text_section", "elements": [ { "text": "gasdfasdf", "type": "text", "style": { "bold": true } } ] }, { "type": "rich_text_section", "elements": [ { "text": "\\g", "type": "text", "style": { "bold": true } } ] }, { "type": "rich_text_section", "elements": [ { "text": "a", "type": "text", "style": { "bold": true } } ] }, { "type": "rich_text_section", "elements": [ { "text": "sdf", "type": "text", "style": { "bold": true } } ] }, { "type": "rich_text_section", "elements": [ { "text": "a", "type": "text", "style": { "bold": true } } ] } ] }, { "type": "rich_text_section", "elements": [ { "text": "\n", "type": "text" } ] }, { "type": "rich_text_list", "style": "bullet", "border": 0, "indent": 0, "elements": [ { "type": "rich_text_section", "elements": [ { "text": "gasdfasdf", "type": "text", "style": { "bold": true } } ] }, { "type": "rich_text_section", "elements": [ { "text": "asd", "type": "text", "style": { "bold": true } } ] }, { "type": "rich_text_section", "elements": [ { "text": "fa", "type": "text", "style": { "bold": true } } ] }, { "type": "rich_text_section", "elements": [ { "text": "sdf", "type": "text", "style": { "bold": true } } ] } ] }, { "type": "rich_text_section", "elements": [ { "text": "\n", "type": "text" } ] }, { "type": "rich_text_preformatted", "border": 0, "elements": [ { "text": "gadsfasdf", "type": "text" } ] } ] } ] ```
filmaj commented 10 months ago

Hey @baycak, we are looking into this. I believe it may be a bug on our end. Will keep you posted.

filmaj commented 10 months ago

@baycak I was able to get this to work by providing the default in an OpenForm rich text field as a string, e.g.:

const inputForm = GreetingWorkflow.addStep(
  Schema.slack.functions.OpenForm,
  {
    title: "Send a greeting",
    interactivity: GreetingWorkflow.inputs.interactivity,
    submit_label: "Send greeting",
    fields: {
      elements: [{
        name: "recipient",
        title: "Recipient",
        type: Schema.slack.types.user_id,
      }, {
        name: "channel",
        title: "Channel to send message to",
        type: Schema.slack.types.channel_id,
        default: GreetingWorkflow.inputs.channel,
      }, {
        name: "message",
        title: "Message to recipient",
        type: Schema.slack.types.rich_text,
        default: 'test',
      }],
      required: ["recipient", "channel", "message"],
    },
  },
);

My guess is that the prevInputForm.outputs.description you are using for the default value is not a string but maybe something else? Perhaps a more complex type?

baycak commented 10 months ago

Yes @filmaj, by providing value as a string there is no issue. The issue arrived when I'm trying to add default value from previous Form which the value of rich text is as I mentioned before

I believe value from rich text is defined as an array of object right not a string? CMIIW

filmaj commented 10 months ago

Correct, rich text ends up being an array with a variety of different objects within representing the various kinds of rich text, i.e. italic, bold, bullet points, so on.

I will keep this issue open but have informed the Block Kit team internally about this use case, as I think it is valid.

baycak commented 10 months ago

I see, well noted @filmaj

Thank you, will waiting for the updates!