Single Slack app to handle multiple workspaces (using Spring Boot, Java, Bolt).
See original GitHub issueHi, 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 App
s (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:
- Created a year ago
- Comments:6 (3 by maintainers)
Ah. Currently, my focus is on Events API patterns. For the situation I described above (line
(2)
), it is true that I can get auser
which corresponds to theauthed_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. 😃
@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.