# Define an App

Define your app using the [SlackApp metadata type](/docs/platform/salesforce-slack-sdk/guide/meta_slackapp.md). In your SFDX project, create the app definition in the `slackapps` folder.

```txt
|_ slackapps/
    |_ MySlackApp.slackapp
    |_ MySlackApp.slackapp-meta.xml
```

An 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.

```yaml
description: Example Apex SDK for Slack App
commands:
  /apex-create-record:
    action:
      definition: apex__action__CreateRecordCommandDispatcher
    title: Create Record Command
    description: Create a record using a slack command.
  /apex-view-record:
    action:
      definition: apex__action__ViewRecordCommandDispatcher
    title: View Record Command
    description: View record details by objectApiName and recordId.
globalShortcuts:
  apex-create-record-global:
    action:
      definition: apex__action__CreateRecordShortcutDispatcher
    title: Create Record Global Shortcut
    description: Create a record using a slack global shortcut.
messageShortcuts:
  apex-create-record-message:
    action:
      definition: apex__action__CreateRecordShortcutDispatcher
    title: Create Record Message Shortcut
    description: Create a record using a slack message shortcut.
events:
  app_home_opened:
    action:
      definition: apex__action__AppHomeOpened
    title: Example event handler for app_home_opened
    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](#action-binding) that handle the slash commands. Define a key for each slash command that you defined in your Slack app at [api.slack.com/apps](http://api.slack.com/apps). A slash command must start with `/`. |
| `globalShortcuts`  | Object | No       | A map of global shortcut callback ID keys to [action bindings](#action-binding) that handle the global shortcuts. Define a key for each global shortcut that you defined in your Slack app at [api.slack.com/apps](http://api.slack.com/apps).                    |
| `messageShortcuts` | Object | No       | A map of message shortcut callback ID keys to [action bindings](#action-binding) that handle the message shortcuts. Define a key for every message shortcut that you defined in your Slack app at [api.slack.com/apps](http://api.slack.com/apps).                |
| `events`           | Object | No       | A map of event keys to [action bindings](#action-binding) that handle the events. Define a key for each [event](https://api.slack.com/events) that your Slack app subscribes to at [api.slack.com/apps](http://api.slack.com/apps).                               |

### Action Binding

An action binding is an object that represents a command, global shortcut, message shortcut, or event.

```yaml
/apex-create-record:
  action:
    definition: apex__action__CreateRecordCommandDispatcher
  title: Create Record Command
  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](/docs/platform/salesforce-slack-sdk/guide/meta_slackapp.md).
