Create an Apex Handler

You can create an Apex class either via the Developer Console in your org or by creating the following files in the force-app/main/default/classes directory in your SFDX project.

  • YourClassName.cls: The Apex class
  • YourClassName.cls-meta.xml: Apex class metadata

For more information, see Create an Apex Class.

Extend the dispatcher based on the type of operation you're handling.

  1. Pass in your Slack parameters and context and return a Slack.ActionHandler instance.

    Slack.ActionHandler has a number of methods to help you structure your handler and enable you to work with modals.

  2. Create a handler that is passed as an argument to Slack.ActionHandler using the ModalHandler interface.

Handlers can implement Slack.ModalHandler or Slack.RunnableHandler.

  1. Implement the required methods for the interface using call().

Use these examples to implement your Apex handlers.

This example creates a handler for a slash command, returns the ack() method to avoid the 3-second timeout, and runs a callback method.

This example handles a slash command and returns a view definition that contains a modal.

This example handles a global shortcut by acknowledging the request.