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 2GP and 1GP 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 will be available only after the pilot phase completes. Users operating under the pilot agreement can't currently package and distribute Slack apps using the Apex SDK.
To generate a package, you 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 Edtion 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.
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.
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 once 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.
- Before you can package a Slack app, make sure you have created a dev hub org and enabled 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.
- In Setup, ensure that Dev Hub and Second-Generation packages are enabled in your org.
- Enable Slack for Salesforce by accepting the Beta Terms of Service.
- 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.
To create an SFDX project, run this command.
In a terminal, navigate into the project directory.
Open the project in VS Code with
config/project-scratch-def.json. Add the
SLACKPACKAGINGfeatures. The features are case-sensitive.
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. Alternatively, copy the files from one of these resources. We recommend starting from a few basic files and adding more files after the package is successfully created later.
sfdx force:auth: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
To create the package, run this command.
You can’t change the package namespace or package type after you create the package.
force:package:createcreates a package. See Help for force:package
-nsets a name for your package. It must be unique within your namespace.
-rrefers to the path to the directory that contains the contents of the package.
-tis the package type for the package. We use
Managedto enable the package to be distributed on AppExchange. Alternatively, an
Unlockedpackage is suitable for internal business apps.
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.
force:package:version:createcreates the package version based on the scratch definition file
-xbypasses the installation key requirement, enabling anyone to install your package. To enforce the installation key requirement, replace
--installationkey yourkeyhere. See installation key usage at Help for force:package:version
-vsets a username or alias for the target Dev Hub org. It overrides the default Dev Hub org.
-wsets 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.jsonfile is automatically updated with the package version information. If not, you must manually edit the project file. See Generate a Package Version
--codecoveragepromotes a package version to released. The package must meet the code coverage requirements.
You must specify a scratch org definition when creating a package as described using the
-f flag. Your scratch org definition contains the
SLACKPACKAGING permissions. If you don't provide a scratch org definition, SFDX creates a basic one that doesn't include the Slack permissions. Alternatively, include the
definitionfile property in
sfdx-project.json to reference your scratch org definition.
When the package is successfully created, you should 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:
sfdx force:package:version:create:report --packagecreaterequestid 08cxx00000000YDAAY. The package create request ID starts with
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 new package version. After making the changes you need in your project, re-run the step in Create the Package Version.
- Package and Distribute Your Apps
- First-Generation Managed Packages
- Second-Generation Managed Packages