Package a Slack App

You can package a Slack app using first-generation managed packages (1GP) or second-generation packages (2GP). With 2GP, your version control system is the source of truth for the metadata in your package. Contrastingly for 1GP, the packaging org is the source of truth for the metadata in your package. See Comparison of First- and Second-Generation Managed Packages.

We recommend using 2GP to package and distribute Slack apps. The rest of the article discusses how you can use 2GP, which uses a scratch org during the package generation process. Enable Dev Hub in your org so you can create and manage scratch orgs and 2GPs.

Packaging and distribution of Slack Apps is available only after the beta phase is complete. Users operating under the beta agreement can't package and distribute Slack apps using the Apex SDK.

Users can package in beta after the Slack and Slack Apex Terms of Service are accepted.

To generate a package, use these orgs.

  • A Dev Hub org with the Slack Packaging org permission enabled
  • A scratch org (associated with your Dev Hub org), which you use to create the actual package
  • A Developer Edition org with a namespace, which you link to the Dev Hub org

The rest of this article discusses the steps in detail.

The steps discussed in this article assume that you have set up your development environment.

Creating a Developer Editiong org enables you to reserve a namespace.

  1. To set up your second-generation packaging, create a Developer Edition org and a namespace. If you don't already have a Developer Edition org, sign up for a new org. This org is separate from your Dev Hub org.

  2. Using the Developer Edition org, create your namespace. We recommend that you use a single namespace for your 2GP packages.

You can't change a namespace or reuse it after you register it. If you're registering a namespace for testing purposes, choose a disposable namespace. Don't choose one that you want to use in the future for a real use case.

  1. Before you can package a Slack app, you must create a dev hub org and enable the user permissions.

Contact Salesforce to enable the Slack Packaging org perm in your Dev Hub org. Users operating under the pilot agreement can't currently package a Slack app.

  1. In Setup, ensure that Dev Hub and Second-Generation packages are enabled in your org.
  2. Enable Slack for Salesforce by accepting the Beta Terms of Service.
  3. Link the namespace that you created in your Developer Edition org in the previous step to your Dev Hub.

If you see an invalid client ID error when logging in to the Developer Edition org, wait 15–20 minutes for the new namespace to propagate.

  1. To create an SFDX project, run this command.

  2. In a terminal, navigate into the project directory.

  3. Open the project in VS Code with code ..

  4. Update sfdx-project.json.

  5. Add files to project for packaging.

Add Apex classes, view definitions, and a Slack app to your force-app folder in your project. See the project structure. Or copy the files from one of these resources. We recommend that you start from a few basic files and then add more after the package is successfully created.

First, run sf org list to find the Dev Hub alias you've already authorized SFDX to. You need the alias for this step. Note that the Dev Hub alias is different from your scratch org alias. Using a scratch org alias to create a package returns an error. In this case, the alias to note is devhub.

To create the package, run this command.

You can’t change the package namespace or package type after you create the package.

  • package create creates a package. See Help for package create.
  • --name sets a name for your package. It must be unique within your namespace.
  • --path refers to the path to the directory that contains the contents of the package.
  • --package-type is the package type for the package. We use Managed to enable the package to be distributed on AppExchange. Alternatively, an Unlocked package is suitable for internal business apps.
  • --target-dev-hub sets a username or alias for the target Dev Hub org. It overrides the default Dev Hub org.

This step generates a package version, which is a fixed snapshot of the package contents and related metadata. The package version enables you to track your changes each time you release or deploy.

To create the package version, run this command.

  • package version create creates the package version based on the scratch definition file config/project-scratch-def.json
  • --installation-key-bypass bypasses the installation key requirement, enabling anyone to install your package. To enforce the installation key requirement, replace --installation-key-bypass. with --installation-key yourkeyhere. See installation key usage at Help for package version create.
  • --target-dev-hub sets a username or alias for the target Dev Hub org. It overrides the default Dev Hub org.
  • --wait sets a wait time in minutes to run the command in non-asynchronous mode. If the package version is created within the time, the sfdx-project.json file is automatically updated with the package version information. If not, you must manually edit the project file. See Generate a Package Version.
  • --codecoverage promotes a package version to released. The package must meet the code coverage requirements.

After the package is successfully created, you receive an install URL for the new package.

Creating a package version can be a long-running process, depending on the package size and other variables. View the status and monitor progress using this command: sf package version create report --package-create-request-id 08cxx00000000YDAAY. The package create request ID starts with 08c.

Log in to the org where you want to install the package. You can install it in one of these orgs.

  • Your Dev Hub org
  • A new org
  • A scratch org (with a different SFDX project)

To modify your package with new or updated files, create a package version. After making the changes you need in your project, rerun the step in Create the Package Version.