question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Single Slack app to handle multiple workspaces (using Spring Boot, Java, Bolt).

See original GitHub issue

Hi, and I apologize for having to bother you with this.

So I’m using Spring Boot, Java, and Bolt to build a Slack bot. I’ve followed the instructions for making a Slack app bot that responds to a particular workspace. It works! However, it won’t respond when installed into other workspaces (or re-installed into the same workspace).

As my controller, I have

@WebServlet("/slack/events")
public class SlackAppController extends SlackAppServlet {
    public SlackAppController(App app) {
        super(app);
    }
}

And the configuration appears as follows (secrets/tokens redacted):

@Configuration
@RequiredArgsConstructor
public class SlackApp {

    @Bean
    public App initSlackApp() {
        String userToken = "xoxp-stuff";
        AppConfig config = AppConfig.builder()
            .signingSecret("a-signing-secret")
            .singleTeamBotToken("xoxb-other-stuff") // corresponding to the one workspace it responds to
            .build();

        App app = new App(config);

        app.command("/hello", (req, ctx) -> {
            return ctx.ack("What's up?");
        });
    
        // also other app.event calls that rely on the bot token and the user token
    }
}

Now, this server has access to a table which will have multiple rows, each row having a team id, bot token, user token, etc. which corresponds to the JSON that comes back at the completion of the OAuth process when a new user installs this Slack app. (I have a separate server that allows customers the ability to purchase access to the bot.)

What I don’t know is how to adapt the above beginning code to either (a) start up many Apps (one per table row) or (b) build one App that will respond to different requests from different workspaces. (I’m told I’m supposed to go with approach (b)).

As a start, I tried to override the doPost() method in the servlet in the controller, but that doesn’t seem to trigger at all when the bot is supposed to be responding.

Is there a guide somewhere that will help with this process (or otherwise, can you give some hints on how to proceed)?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
daxxycodescommented, Jun 30, 2022

Ah. Currently, my focus is on Events API patterns. For the situation I described above (line (2)), it is true that I can get a user which corresponds to the authed_user_id in the payload, but this value is actually not important to me. I simply need (in the context) ctx.getRequestUserId() to be not null so your highlighted block of code can populate the user token.

But, it’s good to know that it’s there for slash commands, at least. So, for now, for Events API patterns, it looks like I’ll go to the db for the token.

Thank you for taking the time to help me understand what’s going on with all this. It’s been really helpful. 😃

0reactions
seratchcommented, Jun 30, 2022

@daxxycodes ctx.getRequestUserId() value always exists for user interactions such as slash command invocation, button clicks, and modal data submission.

However, the property is always null for Events API request patterns. Since “message” events and so on have user ID, the framework may be able to set the property to some of the events in future updates. That being said, there are still many event patterns that do not provide user ID.

If you are talking about Events API patterns, please extract user ID from the event payload. If you found a null pattern for the rest of platform features, please let us know how to reproduce the situation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started with Bolt | Slack SDK for Java
Use bolt -jetty; Start the App with Two Env Variables; Enable /hello Command; OK, What about Spring Boot? Getting Started in Kotlin. Make...
Read more >
Building an app with Bolt for Java - Slack API
Bolt is a foundational framework that makes it easier to build Slack apps with the platform's latest features. This guide walks you through...
Read more >
How to Create a Slack Plugin in Java - Baeldung
Firstly, let's visit https://api.slack.com/apps. This is the base from where we manage our Slack apps. From here we can create a new app....
Read more >
Slack Bolt Java SDK - multiple app.message events with ...
I have a Slack Bolt Java SDK bot (based on Spring Boot) and am using the app.message() function. It is documented in the...
Read more >
Getting Started with Creating Slack Bots & Slack Apps
That way is to use Slack's events based system, through HTTP endpoints or WebSockets, to inform your application of the goings on of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found