java-slack-sdk icon indicating copy to clipboard operation
java-slack-sdk copied to clipboard

Question about how to parse blocks in a message easily

Open victormarcus opened this issue 6 years ago • 2 comments

The complexity of getting messages' text and type using java sdk is high . I want to get the type and text that are in the blocks key. Is there any sample code to do it using SDK. I tried below but I believe this isn't a feasible apporach.

code

victormarcus avatar May 13 '20 12:05 victormarcus

Hi, the rich_text type blocks were added for Slack's WYSIWYG editor support. So, for most 3rd party apps, they are not useful. Refer to the following guide if you're interested in the details of rick_text blocks. https://api.slack.com/changelog/2019-09-what-they-see-is-what-you-get-and-more-and-less

From a 3rd party app perspective, using text field (message.getText() in your code) would be an easier and more relevant approach for reacting incoming messages.

If your app composes a message with common types of blocks you can find here, you may check what the blocks in a message are. For such use cases, there is no way to parse them without checking their types and casting to their concrete types as you're doing.

seratch avatar May 13 '20 12:05 seratch

Thanks

victormarcus avatar May 13 '20 16:05 victormarcus