0

I am working with the Slack SDK in Salesforce with Apex to handle Slash Commands where I want there to be persistence of what the user asks (/test create a new channel) this I want to keep as a message and later the Bot/App responds to this message via thread (the thread handling I already have ready), but according to the Slack Slash Interactivity documentation there is a section that says that the response_type should be in_channel but since I don't handle HTTP requests with this SDK I don't know where I should add this to achieve my goal, I appreciate any help.

public class SlashCommandCall extends Slack.SlashCommandDispatcher {

  public override Slack.ActionHandler invoke(Slack.SlashCommandParameters parameters, Slack.RequestContext context) {
    return Slack.ActionHandler.ack(new Handler(parameters, context));
  }

  public class Handler implements Slack.RunnableHandler {
Slack.SlashCommandParameters parameters;
Slack.RequestContext context;

  public Handler(Slack.SlashCommandParameters parameters, Slack.RequestContext context){
    this.parameters = parameters;
    this.context = context;
  }

  public void run () {
    System.debug(context);
    System.debug(parameters);
    Slack.App app = Slack.App.App.get();
    Slack.BotClient botClient = app.getBotClientForTeam(this.context.getTeamId());
    String channel = context.getChannelId();
    String slashCommandParameterValue = parameters.getText();

    Slack.ChatPostMessageResponse response = botClient.chatPostMessage(
            Slack.ChatPostMessageRequest.builder().channel(channel).text('*' + parameters.getCommand() + '* ' + slashCommandParameterValue).build()
    );

    String animalName = APICalls.getAnimalNameById(Integer.valueOf(slashCommandParameterValue));

    String postMessageThreadTs = response.getTs();
    botClient.chatPostMessage(
            Slack.ChatPostMessageRequest.builder().channel(channel).text(animalName).threadTs(postMessageThreadTs).build()
    );


    if (response.getError() != null) {
        System.debug(response.getError());
    } else {
        System.debug('success');
    }
}

}

What this piece of code does is read the command and text and return in the form of a message to Slack, but it is the bot/app that writes the message, not the user. Slack Post Message

0

You must log in to answer this question.

Browse other questions tagged .