0

I have a slash command that when called, prints a list of teams (which are stored in a List) with checkboxes next to them. I have no problem creating the checkboxes with a team name next to them, but only when the team name is hardcoded in. How can I iterate through the list and create an unknown amount of checkboxes?

app.command("/message", (req, ctx) -> {
  ctx.respond(res -> res
    .responseType("in_channel") // or "in_channnel"
    .blocks(asBlocks(
      section(section -> section.text(markdownText("Select channels to receive message")).accessory(
        checkboxes(checkboxes -> checkboxes
          .options(asOptions(
            option(option -> option.value("0").text(markdownText("some-team")))
            option(option -> option.value("1").text(markdownText("another-team")))
          ))
        )
      )),
      actions(actions -> actions
        .elements(asElements(
          button(b -> b.actionId("submit").text(plainText
            (pt -> pt.emoji(true).text("Submit"))).style("primary").value("submit"))
        ))
      )
    ))
  );
  return ctx.ack();
});
Reporter
  • 3,897
  • 5
  • 33
  • 47
Dani Trevino
  • 21
  • 1
  • 4

1 Answers1

0

Assuming you are familiar with working with block kit / block kit builder.

You can create the complete set of blocks as text
and can then assign it using blocksAsString(String) method.
https://slack.dev/java-slack-sdk/guides/composing-messages :

Building Blocks for Rich Message Layouts

Block Kit is a UI framework for Slack apps that offers a balance of control and flexibility when building experiences in messages and other surfaces.

It may not be so easy to compose a large JSON data structure in Java code. So, we offer setter methods like blocksAsString(String) that accept a whole blocks part as a single string value. Such method is supposed to be used with loaded external file data or outcomes by template engines.

ChatPostMessageResponse response = slack.methods(token).chatPostMessage(req -> req
  .channel("C1234567")
  .blocksAsString("[{\"type\": \"divider\"}]")
);
Reporter
  • 3,897
  • 5
  • 33
  • 47
Suyash Gaur
  • 2,481
  • 2
  • 9
  • 22