Quantcast
Channel: Preguntas activas con las etiquetas slack-api - Stack Overflow en español
Viewing all articles
Browse latest Browse all 8

¿Cómo puedo retornar el slash command de Slack en Apex Salesforce con el SDK de Slack en Apex?

$
0
0

estoy trabajando con el SDK de Slack en Salesforce con Apex para manejar los Slash Commands donde deseo que haya persistencia de lo que el usuario pregunta (/test create a new channel) esto quiero que se mantenga como un mensaje y posteriormente que el Bot/App responda a este mensaje por medio de hilo (el manejo del hilo ya lo tengo listo), pero según la documentación de Slack Slack Slash Interactivity hay un apartado que dice que el response_type debe ser in_channel pero dado que no manejo peticiones HTTP con este SDK no sé en que parte debo agregar esto para lograr mi objetivo, agradezco cualquier ayuda

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');        }    }}

}

Lo que hace esta parte de código es leer el comando y el texto y devolver en forma de mensaje a Slack, pero es el bot/app quien escribe el mensaje, y no el usuario. Slack Post Message


Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles





Latest Images