1

I'm building a Slack bot app. I want every time a user opens the dialogue with the bot, the bot will automatically say something like "Hello! Please ask me a question". I think I should use the event API: https://api.slack.com/events to listen to the user action, but which event I should capture?

Rachel Dong
  • 179
  • 1
  • 3
  • 11

1 Answers1

0

Use AppHomeOpenedEvent Class .

When you click on your bot or App in the Apps Section of Slack . The Moment You Click on Home tab , below code in come in action

Below is the Sample Code In Slack Bolt SDK Java

app.event(AppHomeOpenedEvent.class, (req, ctx) -> {
        var logger = ctx.logger;
        var userId = req.getEvent().getUser();
        try {
            // Call the conversations.create method using the built-in WebClient
            var modalView = view(v -> v
                    .type("home")
                    .blocks(asBlocks(
                            section(s -> s.text(markdownText(mt ->
                                    mt.text("*Welcome home, <@" + userId + "> :house:*")))),
                            section(s -> s.text(markdownText(mt ->
                                    mt.text("About the simplest modal you could conceive of :smile:\\n\\nMaybe <https://api.slack.com/reference/block-kit/interactive-components|*make the modal interactive*> or <https://api.slack.com/surfaces/modals/using#modifying|*learn more advanced modal use cases*>.")))),
                            divider(),
                            context(c -> c.elements(asContextElements(
                                    markdownText("Psssst this modal was designed using <https://api.slack.com/tools/block-kit-builder|*Block Kit Builder*>")
                            )))
                    ))
            );
            var result = ctx.client().viewsPublish(r -> r
                    // The token you used to initialize your app
                    .token(AppConfigLoader.load().getSingleTeamBotToken())
                    .userId(userId)
                    .view(modalView)
            );

            // Print result
            logger.info("result: {}", result);
        } catch (IOException | SlackApiException e) {
            logger.error("error: {}", e.getMessage(), e);
        }
        return ctx.ack();
    });
LearnerForLife
  • 147
  • 1
  • 12