Define an App
Define your app using the SlackApp metadata type. In your SFDX project, create the app definition in the slackapps folder.
1|_ slackapps/
2 |_ MySlackApp.slackapp
3 |_ MySlackApp.slackapp-meta.xmlAn app definition includes:
<appname>.slackapp: The configuration file that contains the app handlers for slash commands, shortcuts, and event handlers in YAML format<appname>.slackapp-meta.xml: The metadata file that contains connection settings to communicate with Slack
Define App Metadata
Bind an action to handle each command, shortcut, and event in your app.
An action executes when a Slack request is received. Actions are assigned to hooks in app metadata and events in a view.
This example app configuration binds actions to several commands, a global shortcut, a message shortcut, and an event.
1description: Example Apex SDK for Slack App
2commands:
3 /apex-create-record:
4 action:
5 definition: apex__action__CreateRecordCommandDispatcher
6 title: Create Record Command
7 description: Create a record using a slack command.
8 /apex-view-record:
9 action:
10 definition: apex__action__ViewRecordCommandDispatcher
11 title: View Record Command
12 description: View record details by objectApiName and recordId.
13globalShortcuts:
14 apex-create-record-global:
15 action:
16 definition: apex__action__CreateRecordShortcutDispatcher
17 title: Create Record Global Shortcut
18 description: Create a record using a slack global shortcut.
19messageShortcuts:
20 apex-create-record-message:
21 action:
22 definition: apex__action__CreateRecordShortcutDispatcher
23 title: Create Record Message Shortcut
24 description: Create a record using a slack message shortcut.
25events:
26 app_home_opened:
27 action:
28 definition: apex__action__AppHomeOpened
29 title: Example event handler for app_home_opened
30 description: event fires when a user opens the home tab.App Configuration Keys
The app configuration includes the following keys.
| Key | Type | Required | Description |
|---|---|---|---|
description | String | No | A description of the app. Not used in code. |
commands | Object | No | A map of slash command keys to action bindings that handle the slash commands. Define a key for each slash command that you defined in your Slack app at api.slack.com/apps. A slash command must start with /. |
globalShortcuts | Object | No | A map of global shortcut callback ID keys to action bindings that handle the global shortcuts. Define a key for each global shortcut that you defined in your Slack app at api.slack.com/apps. |
messageShortcuts | Object | No | A map of message shortcut callback ID keys to action bindings that handle the message shortcuts. Define a key for every message shortcut that you defined in your Slack app at api.slack.com/apps. |
events | Object | No | A map of event keys to action bindings that handle the events. Define a key for each event that your Slack app subscribes to at api.slack.com/apps. |
Action Binding
An action binding is an object that represents a command, global shortcut, message shortcut, or event.
1/apex-create-record:
2 action:
3 definition: apex__action__CreateRecordCommandDispatcher
4 title: Create Record Command
5 description: Create a record using a slack command.The action binding is specified by the following keys.
Keys
| Key | Type | Required | Description |
|---|---|---|---|
action | String | Yes | The address to an Apex class in the format apex__action__ClassName or apex__action__Namespace.ClassName bound to the command, shortcut, or event. |
title | String | No | Reserved for future use. |
description | String | No | A description of the action binding. Not used in code. |
Configure the App Connection
Configure your Apex SDK for Slack app to communicate with the Slack app. In the slackapps folder, create a file called <appname>.slackapp-meta.xml, where <appname> matches the <appname>.slackapp file.
For field information, see SlackApp metadata type.
Beta Feature