0
votes

I have created an endpoint to receive slack slash commands like so:

@PostMapping(value = "/slack", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public String incidentCommand(@RequestParam("token") String token,
                              @RequestParam("team_id") String teamId,
                              @RequestParam("team_domain") String teamDomain,
                              @RequestParam("channel_id") String channelId,
                              @RequestParam("channel_name") String channelName,
                              @RequestParam("user_id") String userId,
                              @RequestParam("user_name") String userName,
                              @RequestParam("command") String command,
                              @RequestParam("text") String text,
                              @RequestParam("response_url") String responseUrl) {


    if (command.equals(INCIDENT)) {
        incidentQueue.push(new Event(userId, token, text, responseUrl));
    } else if (command.equals(POSTMORTEM)) {
        postmortemQueue.push(new Event(userId, token, text, responseUrl));
    } else {
        return "no";
    }
}

The architecture would be like so:

  • Slack Controller receives HTTP request from slack
  • Request is placed on a queue
  • Request is handled
  • Response is sent back to slack (<500ms latency)

However when looking at the SlackClient in the Java SDK library, there doesn't appear to be anyway to use the response_url submitted by slack.

For example for sending a ChatPostMessage following does not have any property for response_url

sendMessage(ChatPostMessageParams.builder()
                .setText("Ping!")
                .setChannelId(channel)
                .setUsername(username)
                .build())

Does this mean I just need to construct my own HTTP client (using something like ApacheHTTPClient?) and directly call the response_url?

Also are there any DTOs or Domain objects for defining messages in the slack SDK?

1

1 Answers

1
votes

Yes you will need to do the call to the response_url manually using your preferred web client, this is because response_url is considered out of scope for the Web API as indicated here.

Note however that the functionality is available in Bolt SDK if you are using that.