slackapi / java-slack-sdk

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

ImageElement.setImageBytes(Integer) #1321

Closed RovoMe closed 1 month ago

RovoMe commented 1 month ago

As part of a link unfurling strategy we want to add custom images for various links. We therefore use

SectionBlock.builder()
    .text(...)
    .accessory(ImageElement.builder()
        .imageUrl("...")
        .altText("...")
        .build())
    .build()
);

so far to achieve this. We noticed that you can also use imageBytes(Integer) instead but I couldn't find any more specific documentation of what that Integer argument exactly is. I assume this is some kind of ID but then again the ID used by slack_file's is a String. The reference documentation on Slack native image elements here also seem to only know of image_url.

From the name of the method I'd expect that a byte array holding the various RBGA values that form images should be passed. But then again this method unfortunately only accepts an Integer value. So is this method even intended for such cases or is there a utility class available which transcodes byte array images to Integer somehow? Or has the upload to be done via i.e. FilesUploadV2Request.builder()... beforehand which then might return an ID that can be used with this method?

seratch commented 1 month ago

Hi @RovoMe, thanks for writing in. The property can be set only by the Slack API server, so you cannot utilize the property for any purpose. The reason why this SDK provides a setter method for it is to maintain compatibility with JSON serialization/deserialization. Perhaps we as this project maintainers can improve the code comment to eliminate this type of confusion in the future.

To embed image data in a block, please upload the file first and then use the slack_file's URL property instead. Is everything clear now?

RovoMe commented 1 month ago

Thanks for the information. I think uploading it to a public space and then using the URL to that resource directly, as we do now already, is the less "painful" way.