Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing possible null type for value for PlainTextInputAction and StaticSelectAction types #1914

Closed
GovernmentHack opened this issue Jul 31, 2023 · 9 comments
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info semver:patch server-side-issue TypeScript-specific
Milestone

Comments

@GovernmentHack
Copy link
Contributor

GovernmentHack commented Jul 31, 2023

Reproducible in:

Using the block builder actions preview:

When triggering a block action event, some actions have a null value possible state. However, the Types defined in https://github.com/slackapi/bolt-js/blob/main/src/types/actions/block-action.ts do not accommodate possible null values.

For example, the PlainTextInputAction type can have a null value when you press enter to dispatch the action with nothing filled:
Screenshot 2023-07-31 at 4 07 34 PM

Or, the StaticSelectAction can have a null value if after a value is selected, the user selects "clear selection":
Screenshot 2023-07-31 at 4 08 50 PM
Screenshot 2023-07-31 at 4 08 59 PM

The Slack SDK version

"slack/bolt": "3.13.2",
"slack/logger": "^3.0.0",
"slack/oauth": "^2.6.1",
"slack/socket-mode": "^1.3.2",
"slack/types": "^2.8.0",
"slack/web-api": "^6.8.1",

Node.js runtime version

v18.12.1

OS info

ProductName: macOS
ProductVersion: 13.4.1
ProductVersionExtra: (c)
BuildVersion: 22F770820d
Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000

Steps to reproduce:

(Share the commands to run, source code, and project settings)

  1. Attempt to set a mock payload type action value to null (for example, in a test for a block action handler)

Expected result:

No error

Actual result:

Type error:
Screenshot 2023-07-31 at 4 12 39 PM

Requirements

For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. 🙇

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

@filmaj filmaj added bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch TypeScript-specific and removed untriaged labels Aug 2, 2023
@filmaj filmaj added this to the 3.13.3 milestone Aug 2, 2023
@filmaj
Copy link
Contributor

filmaj commented Aug 2, 2023

@GovernmentHack I'm trying to reproduce this issue in an actual app and not block kit builder.

For example, the PlainTextInputAction type can have a null value when you press enter to dispatch the action with nothing filled

I am unable to reproduce this, in either a modal or a message posted by the app. No block_action event is dispatched when I press enter into a plain text input (that has an action_id), regardless of its contents, either when the input is embedded as part of blocks in a message posted by the app, or as part of a modal opened by the app. The action_id of a plain text input, as described in the reference docs for this element, is only used as part of view_submission payloads, not as part of stand-alone actions.

Or, the StaticSelectAction can have a null value if after a value is selected, the user selects "clear selection":

Also unable to reproduce this mainly because there is no option to 'clear selection' in a static select menu, either embedded in a modal or in a message.

I think this may end up being an issue submission for block kit builder than for bolt 😄

Let me know what you think.

@GovernmentHack
Copy link
Contributor Author

No block_action event is dispatched when I press enter into a plain text input (that has an action_id), regardless of its contents,

And this is with dispatch_action === true? Since that needs to be true to trigger an event with an enter key press. like this element:
image

Also unable to reproduce this mainly because there is no option to 'clear selection' in a static select menu, either embedded in a modal or in a message.

hmmm, You are right, I went and tried to create in element and I'm not seeing the Clear Selection option either, like the Block Kit builder shows. So, that does seem to be a discrepancy between prod and the builder 😅 Woops.

Interestingly the Datepicker element blockAction type already has a | null type for it, but I'm good with not updating the StaticSelect type. I would like to confirm the text input though with dispatch_action === true:

{
	"dispatch_action": true,
	"type": "input",
	"element": {
		"type": "plain_text_input",
		"action_id": "plain_text_input-action"
	},
	"label": {
		"type": "plain_text",
		"text": "Label",
		"emoji": true
	}
}

@filmaj
Copy link
Contributor

filmaj commented Aug 2, 2023

And this is with dispatch_action === true? Since that needs to be true to trigger an event with an enter key press. like this element:

O geez, absolutely my bad, nope, I was testing without dispatch_action_config! I am just finishing up a release of the @slack/web-api package and will come back to this issue shortly to follow up on this again...

@filmaj
Copy link
Contributor

filmaj commented Aug 2, 2023

Interestingly the Datepicker element blockAction type already has a | null type for it, but I'm good with not updating the StaticSelect type.

I'll take a note to validate/reproduce the payloads with the DatePicker element and file an issue if there's a problem with that.

"dispatch_action": true,

Wait.. is it dispatch_action or dispatch_action_config? The docs state the latter.. let's see... nope I get an invalid_blocks error if I try dispatch_action, but my message posts fine if I use:

    {
      "type": "input",
      "label": {
        "type": "plain_text",
        "text": "plain text input"
      },
      "element": {
        "type": "plain_text_input",
        "action_id": "pti",
        "dispatch_action_config": {
          "trigger_actions_on": ["on_enter_pressed", "on_character_entered"]
        },
      }
    }

The bad news is that with the input either embedded in the blocks of a message OR in a modal, with the above, neither of the events get dispatched 😬 I will file this with the API team in charge...

@GovernmentHack
Copy link
Contributor Author

The code snippet I copied was from the block kit builder. I also confirmed that for block text input elements that is how I was generating text input elements to return values with an enter key press. That is to say: adding dispatch_action: true to the JOSN payload at the same level as type and label like in my example.

Here is a screenshot of a field I rendered with that dispatch_action config in a staging instance:
Screenshot 2023-08-02 at 10 02 04 AM

@filmaj filmaj added needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info server-side-issue labels Aug 2, 2023
@GovernmentHack
Copy link
Contributor Author

Here is the output of my screenshotted element using the Slack dev tools:

{
  "bot_id": "<REDACTED>",
  "type": "message",
  "text": "Testing Message content <REDACTED> slack ",
  "user": "<REDACTED>",
  "ts": "1690469581.860159",
  "metadata": {
    "event_type": "<REDACTED>",
    "event_payload": {}
  },
  "app_id": "<REDACTED>",
  "blocks": [
    {
      "type": "section",
      "block_id": "reply_message",
      "text": {
        "type": "mrkdwn",
        "text": "Testing Message content <REDACTED> slack\n",
        "verbatim": false
      }
    },
    {
      "type": "input",
      "block_id": "<REDACTED>",
      "label": {
        "type": "plain_text",
        "text": "Move from",
        "emoji": true
      },
      "optional": false,
      "dispatch_action": true,
      "element": {
        "type": "plain_text_input",
        "action_id": "<REDACTED>",
        "placeholder": {
          "type": "plain_text",
          "text": "Write something",
          "emoji": true
        },
        "dispatch_action_config": {
          "trigger_actions_on": [
            "on_enter_pressed"
          ]
        }
      }
    }
  ],
  "team": "<REDACTED>",
  "bot_profile": {
    "id": "<REDACTED>",
    "deleted": false,
    "name": "<REDACTED> Staging Slack App",
    "updated": 1683521047,
    "app_id": "<REDACTED>",
    "icons": {
      "image_36": "<REDACTED>",
      "image_48": "<REDACTED>",
      "image_72": "<REDACTED>"
    },
    "team_id": "<REDACTED>"
  },
  "thread_ts": "1690405013.555419",
  "parent_user_id": "<REDACTED>"
}

Interestingly the block contains both dispatch action configs. But, I definitely only sent the dispatch_action: true config in my payload to post the message.

@filmaj
Copy link
Contributor

filmaj commented Aug 2, 2023

Oh wow that is confusing as heck haha.

So I commented out the element-level dispatch_action_config property and instead added dispatch_action at the block level. That works to dispatch the action, so that is good. I then re-added the dispatch_action_config and was able to configure the specific events my app should receive. So it works.. but the configuration at different block levels (block vs element level) is definitely confusing. I just followed up with the Block Kit team and I've got an issue filed with them to simplify the configuration here. In particular, I suggested that, if any element within a block defines dispatch_action_config, then Slack should assume the entire block has an implicit dispatch_action: true configuration.

However, back to your original issue: pressing enter on an empty input doesn't dispatch an action and in fact the client will render a red outline on the input with a "Please complete this required field." error. Therefore, it seems to me like null value (i.e. empty) plain text input block_actions dispatches can never happen in production apps. Let me know if you disagree (you have proven me wrong multiple times in this issue already so I'm hedging my bet here 😆 ). Assuming my previous statement is true, then I think the last follow-up here is to get Block Kit builder updated.

@GovernmentHack
Copy link
Contributor Author

Nope, that sounds good to me. I appreciate the help testing this!

I guess next steps are to file an issue with the block kit builder app to remove the "Clear Action" and remove the ability to send null values 😅

Thanks for the help with this!

@filmaj
Copy link
Contributor

filmaj commented Aug 2, 2023

Indeed, I've filed two more issues with the Block Kit team to address the two Block Kit Builder issues we've identified.

Happy to help! I am appreciative of your patience, responsiveness and for correcting my mistakes as we worked through this.

I will close this issue down now but if there's anything else, feel free to re-open or to file another issue.

@filmaj filmaj closed this as completed Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info semver:patch server-side-issue TypeScript-specific
Projects
None yet
Development

No branches or pull requests

2 participants