You can create an Apex class either via the Developer Console in your org or by creating these files in the force-app/main/default/classes directory in your SFDX project.
1public class Handler implements Slack.ModalHandler{2 public Handler(Slack.SlashCommandParameters parameters,3 Slack.RequestContext context){4}5}
Implement the required methods for the interface by using call().
1public Slack.ModalView call(){2 Slack.ModalView modalView = new Slack.ModalView.builder().build();3 return modalView;4}
Examples
Use these examples to implement your Apex handlers.
Basic Slash Command
This example creates a handler for a slash command, returns the ack() method to avoid the 3-second timeout, and runs a callback method.
1public class MySlashCommandDispatcher extends Slack.SlashCommandDispatcher{23 public override Slack.ActionHandler invoke(Slack.SlashCommandParameters parameters, Slack.RequestContext context){4 return Slack.ActionHandler.ack(new Handler());5}67 public class Handler implements Slack.RunnableHandler{8 public void run(){9 System.debug('Ack Callback');10}11}12}
Slash Command Returning a Modal View
This example handles a slash command and returns a view definition that contains a modal.
1public class MySlashCommandDispatcher extends Slack.SlashCommandDispatcher{23 public override Slack.ActionHandler invoke(Slack.SlashCommandParameters parameters, Slack.RequestContext context){4 return Slack.ActionHandler.modal(new Handler(parameters, context), 'my custom modal title');5}67 public class Handler implements Slack.ModalHandler{89 Slack.SlashCommandParameters parameters;10 Slack.RequestContext context;1112 public Handler(Slack.SlashCommandParameters parameters, Slack.RequestContext context){13 this.parameters = parameters;14 this.context = context;15}1617 public Slack.ModalView call(){1819 Slack.ViewReference viewReference = Slack.View.example_view.get();20 viewReference.setParameter('title', 'Apex Modal!');21 viewReference.setParameter('message', context.getAppId() + ' ' + parameters.getText());2223 Slack.ModalView modalView = new Slack.ModalView.builder()24 .viewReference(viewReference)25 .build();2627 return modalView;2829}30}3132}
Global Shortcut Acknowledging Request
This example handles a global shortcut by acknowledging the request.
1public class ExampleShortcutDispatcher extends Slack.ShortcutDispatcher{23 public override Slack.ActionHandler invoke(Slack.ShortcutParameters parameters, Slack.RequestContext context){4 return Slack.ActionHandler.ack(new Handler(parameters, context));5}67 public class Handler implements Slack.RunnableHandler{89 Slack.ShortcutParameters parameters;10 Slack.RequestContext context;1112 public Handler(Slack.ShortcutParameters parameters, Slack.RequestContext context){13 this.parameters = parameters;14 this.context = context;15}1617 public void run(){18 System.debug('Ack Callback');19}2021}22}
Shortcut Returning a Modal View
1public class CreateRecordShortcutDispatcher extends Slack.ShortcutDispatcher{23 public override Slack.ActionHandler invoke(Slack.ShortcutParameters parameters, Slack.RequestContext context){4 return Slack.ActionHandler.modal(new Handler(parameters, context), 'Create Record');5}67 public class Handler implements Slack.ModalHandler{89 Slack.ShortcutParameters parameters;10 Slack.RequestContext context;1112 public Handler(Slack.ShortcutParameters parameters, Slack.RequestContext context){13 this.parameters = parameters;14 this.context = context;15}1617 public Slack.ModalView call(){18 Slack.ViewReference viewReference = Slack.View.create_record.get();19 Slack.ModalView modalView = new Slack.ModalView.builder()20 .viewReference(viewReference)21 .build();22 return modalView;23}24}25}
Beta Feature
This feature is not generally available. It is not part of your purchased Services. This feature is subject to change, may be discontinued with no notice at any time in SFDC’s sole discretion, and SFDC may never make this feature generally available. Make your purchase decisions only on the basis of generally available products and features. This feature is made available on an AS IS basis and use of this feature is at your sole risk.