slackapi / bolt-js

A framework to build Slack apps using JavaScript
https://tools.slack.dev/bolt-js/
MIT License
2.75k stars 393 forks source link

The error is not caught when trying to update a modal that has exceeded the number of characters. #1978

Closed suzuki-m07 closed 1 year ago

suzuki-m07 commented 1 year ago

An error was not caught when a modal was created with more than the maximum number of characters in the "mrkdwn" type text in the modal's section block.

How can I proceed to the catch clause?

Reproducible in:

The Slack SDK version

^3.14.0

Node.js runtime version

v18.17.0

OS info

Windows 10 Pro 22H2

Steps to reproduce:

1.Press the submit button for the modal 2.Create the next modal using "mrkdwn" in the section block (the text must be at least 3000 characters) 3.Pass the created modal as an argument to the ack function to update the modal

Expected result:

An error occurs and processing proceeds in the catch clause

Actual result:

The process does not go into the CATCH clause, and the process ends. The modal will say, "I can't seem to connect to Slack. Can you please retry?"

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. :bow:

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

misscoded commented 1 year ago

Hi @suzuki-m07! Can you provide a snippet of the code you've described in the issue?

suzuki-m07 commented 1 year ago

Thanks for your reply. The following is a simplified version of the relevant code.

app.view(callbackId, async ({ ack, body, client }) => {
  try {
    const metadataObject = {
      keyA: "string",
      keyB: metadataArrA,
      keyC: metadataArrB
    }

    //Convert a metadataObject to a String type (the length of the String must be at least 3000 characters)
    const metadata = JSON.stringify(metadataObject);

    const modal = {
      "response_action": "update",
      "view":
      {
        "private_metadata": metadata
        "callback_id": callbackId,
        "title": {
          "type": "plain_text",
          "text": "My App",
          "emoji": true
        },
        "submit": {
          "type": "plain_text",
          "text": "submit",
          "emoji": true
        },
        "type": "modal",
        "close": {
          "type": "plain_text",
          "text": "close",
          "emoji": true
        },
        "blocks": [
          {
            "block_id": "blockId",
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": "plain text"
            }
          },
          {
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": ArrA.join(`,`)
            }
          }
        ]
      }
    }
    await ack(modal);
  } catch (e) {
    await ack(makeErrorModal(e));
  }
});

When I paste the "modal" created in the above code into block kit builder, I get a character limit error in the private_metadata field. If private_metadata is removed from "modal", it is displayed correctly.

seratch commented 1 year ago

@suzuki-m07, thank you for providing the details. The ack() method transmits an HTTP response containing the specified JSON data. In the case of Socket Mode, it dispatches a WebSocket message. Hence, your Bolt app does not receive any result in response to the ack() method call. This is why no exception is thrown in this circumstance.

Unfortunately, there is no workaround to avoid the length limit as it is requirement. Thus, the only approach to deal with this situation is to include a reference to the long string data (e.g., only incorporating a primary key string for a database row in your modal view JSON data). I hope this offers some clarification.

suzuki-m07 commented 1 year ago

I see! I did not know that. Thank you for your answer.