slackapi / java-slack-sdk

Slack Developer Kit (including Bolt for Java) for any JVM language
https://tools.slack.dev/java-slack-sdk/
MIT License
577 stars 214 forks source link

Rich Text Block Mismatch in Java Class and Json Version #1336

Closed Falit closed 3 months ago

Falit commented 3 months ago

We are trying to utilise Rich Text Block as Input , the user can add some placeholder ( we are using something like ${current}) and we would replace it with mentioning user.

We are facing issues wrt Rich Text Block and subsequent json format

  1. In case the input contains the user mention, then then rich text type is "user". However, on converting to json, it shows as :
{
  "type": "user",
  "user_id": "U03G3J3UGKU",
  "style": {
    "bold": true,
    "italic": false,
    "strike": false,
    "code": false
  }
}

Now, when we try to paste this in block kit builder or try sending this on UI, then it says "invalid additional property code".

On checking the commits : We think this commit is the issue , since the User object -> style object shouldn't have code attribute as mentioned here](https://api.slack.com/reference/block-kit/blocks#user-element-type)

Are there inconsistencies in Rich text block Java class and Rich text block json version?

Reproducible in:

<dependency>
    <groupId>com.slack.api</groupId>
    <artifactId>bolt-servlet</artifactId>
    <version>1.39.0</version>
</dependency>
mvn dependency:tree | grep com.slack.api
gradle dependencies | grep com.slack.api
java -version 
sw_vers && uname -v # or `ver`

The Slack SDK version

<dependency>
    <groupId>com.slack.api</groupId>
    <artifactId>bolt-servlet</artifactId>
    <version>1.39.0</version>
</dependency>

(Paste the output of mvn dependency:tree | grep com.slack.api or gradle dependencies | grep com.slack.api)

Java Runtime version

(Paste the output of java -version) java 11.0.16 2022-07-19 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.16+11-LTS-199) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.16+11-LTS-199, mixed mode)

OS info

Mac Os ProductName: macOS ProductVersion: 12.0.1 BuildVersion: 21A559 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:01 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T6000

Steps to reproduce:

(Share the commands to run, source code, and project settings (e.g., pom.xml/build.gradle))

  1. Create a Rich text block input.
  2. Add a user mention in the input
  3. Read the user input using Slack bolt. -> You can see style properties being added like code, block etc.
  4. Convert the user input to json
  5. Paste this in block kit builder and see error : invalid additional property code

Expected result:

{
  "type": "user",
  "user_id": "U03G3J3UGKU",
  "style": {
    "bold": true,
    "italic": false,
    "strike": false,
    "code": false
  }
}

Actual result:

error : invalid additional property code

On checking the commits : We think this commit is the issue , since the User object -> style object shouldn't have code attribute as mentioned here](https://api.slack.com/reference/block-kit/blocks#user-element-type)

Screenshot 2024-07-15 at 8 45 34 PM
WilliamBergamin commented 3 months ago

Hi @Falit thanks for writing in!

It does seem like some of the models in RichTextSectionElement.java do not match their documented definition from Rich text element types

From what I can understand changing these models may be a breaking change, @seratch not sure how we want to address this, maybe we could strip non existing fields when converting java -> json 🤔

seratch commented 3 months ago

Hi @Falit, thank you so much for taking the time to report this!

@WilliamBergamin I don't think this is a breaking change because currently working code customers rely on should not use the code property for those block elements. This is a bug fix, which resolves an existing issue.

While checking this, I found that a few other properties, which did not exist when we initially added these classes, are missing in the class definition. I've resolved the issue too in #1337 pull request.