Step 2: Create a Free Standard Library Account

Head over to https://code.stdlib.com/ and create a free account.

On the bottom left corner click (sign in). If you have a Standard Library account click Already Registered and sign in using your Standard Library credentials. A module will pop up prompting you to claim a namespace (this is your username). Input your e-mail and choose a password.

After you create your account, a different module will appear listing the subscription plans. A free account is all you need to get started. Once you click Subscribe + Earn Credits you should see a confirmation message pop up. Click Continue to return to the landing page.

Step 3: Select the @janethl/atlassianappsmetrics Sourcecode

I have published my Slack app’s code on the Standard Library so that it’s available for anyone to easily copy and modify.

Click API from Sourcecode You’re going to fork my code and create your own, personal API that will power your Slack app!

Find & select @janethl/ atlassianappsmetrics.

Make sure to enter a unique name for your API and hit Okay (or press enter).

Once you hit enter, you’ll see a API project scaffold on the left sidebar (a folder tree view) that has been automatically generated.

A Brief Explanation of the Sourcecode:

The sourcecode for Slack Apps contains four directories (folders). For this tutorial, we will only work within the functions directory which comes equipped with actions/commands/ events/__main__.js.

When you deploy your API, Standard Library will automatically generate https endpoints for each function. The resulting URLs allow Slack users to configure webhooks that listen and respond to Slack’s actions, slash commands, and events.

All five functions are set up with a __main__.js file (or the function’s main endpoint). These __main__.js endpoints dispatch the appropriate function when they receive a message from Slack. For a more in depth explanation of how functions work head on over to our docs page.

commands: We’ll only need the command directory for this tutorial. You should use the commands directory as the endpoint for all Slack slash commands. To create any additional commands, all you have to do is add another .js file under /functions/commands/ as name.js where name matches the name of your Slack slash command.

Step 4: Add Your Standard Library and Slack App Credentials

We are almost there! It’s time to open your env.json (environment variables). We’ll be making modifications to the "dev" environment variables — make sure you’re modifying the right set! Note that "dev” values are for your development environment and "release" values should only be populated when you’re ready to release your app. “local” variables can be left blank when deploying from Code on Standard Library — they should be filled when testing an API from your local CLI.

Place your cursor in between the quotation marks (see screen) and either right-click and select Insert Library Token… or use the shortcut ⌘ + K.

Select your library token

Select Library Token to fill in "dev" and environments.

Now go back to the Basic Information page of your Slack App and scroll down to App Credentials:

Copy your Client ID, Client Secret, and Verification Token. Paste them into their respective fields in “dev” section of the env.json file.

Add the name you gave your Slack app in env.json.

Fill in “SLACK_REDIRECT” with https://<username>.api.stdlib.com/<apiname>@dev/auth/ — the https URL with your username and your API name.

Set your Slack app’s capabilities and permissions with the following scopes:

“SLACK_OAUTH_SCOPE”: bot,commands,chat:write:bot,chat:write:user,files:write:user,channels:history

Make sure to save the changes with ‘⌘ + s’ (or hit Save in the bottom right).

On the sidebar navigate through functions/commands to open the atlassianmetrics.js file and deploy the function by clicking “Run.”

*It’s normal to see the “Invalid app name” error message when you deploy your API because the endpoint is intended to be called via Slack slash command.

Step 5: Create a New Slash Command

Next, we need to create our /atlassianmetrics Slack command. Find and Click Slash Commands on the sidebar menu.

After clicking Create New Command, you’ll be asked to enter some command details, for this example use:

Command: /atlassianmetrics

RequestURL:

https://<username>.api.stdlib.com/<apiname>@dev/commands/:bg

Fill in with your username and apiname.

Short Description: fetches latest metrics

Usage Hint: [app_name]

Hit “Save” once complete

Step 6: Enable OAuth & Permissions

Return to your Slack App, we’ll need to enable OAuth. on the sidebar menu, click OAuth & Permissions. Once there, you’ll want to enter in a Redirect URL as follows: https://<username>.api.stdlib.com/ <apiname>@dev/auth/

where <username> is your Standard Library username and <apiname> is the name you gave your deployed Standard Library API.

click “Add” and “Save URLS.”

Step 7: Add a Bot to Your Slack App

Return to your Slack App page, and click Bot Users on the left sidebar. Click Add Bot User. Keep the default settings.

The final step is to authorize the app. In your browser, type: https://<username>.api.stdlib.com/<app_name>@dev/

Click Add to Slack

Click the Add to Slack button. You will be taken to another authorization screen.

Click Authorize. You should see a success message!

Step 8: Test Your Application Metric Tracker

Test your app with /atlassianmetrics questions

You’re all done. Try it out! Your Slack App is now available for use in the Slack workspace you authorized it for. Your Slack app should respond to a /atlassianmetrics questions as I show in the screenshot above.

Step 9: Return and Add Your Applications Unique Identifiers

Return to your API on Code on Standard Library and on the sidebar navigate through functions/commands to open the atlassianmetrics.js . The code inside your file should look like this:

I published the Sourcecode with a sample APP_DETAILS including addonKey, imageUrl, and appLink for Questions for Confluence application currently sold on the Atlassian Marketplace. This function was triggered when you typed /atlassianmetrics question inside your Slack message field.

When you are ready fill in the APP_DETAILS with your own applications’ information. Change the default name APP2 to a short name description of your app. Add your unique addonKey , provide an imageUrl to display an image of your application, and if you’d like add an appLink to redirect to your app’s website from Slack. Make sure you save the changes by selecting the orange “Save” button at the bottom right corner and re-deploy your API by clicking the “Run” button again.

Below is a screenshot of the Slack app API I created for Midori. I configured the API so that one Slack slash command could return the metrics of four different apps.

You can add as many app addonKeys as you would like to your Standard Library API.

That is it & Thank You!

I hope you found this tutorial helpful. I would love for you to comment here, e-mail me at Janeth [at] stdlib [dot] com, or follow Standard Library on Twitter, @StdLibHQ . Let me know if you have an additional functionality request for your Slack app — I’d love to help!