Skip to content
Advertisement

How to separate Slack blocks into a separate file

I’m working on a slack bot in JS, and using Slack’s “block kit” to format the messages. However, quite often I get a function that looks like this:

JavaScript
Most of the code is just formatting the block kit text, and it makes it difficult to navigate. Is there a common way to organize this code so the blocks aren’t taking up so much space? I tried making it into a separate file, but I ran into issues when trying to reference it in the main file, and I wasn’t convinced that’s the best way to do it. Any suggested would be much appreciated!

Advertisement

Answer

Usual method is that you can keep the block kit as separate json file. And read block from that file.

Please find sample code below:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement