Article

How to Build a Slack App with Dark

Dark is a new language for writing deployless backends. It’s also the editor and infrastructure. That means you can only write Dark in your browser, but you never need to set up a server. You don’t even deploy to a server, the code is live as you write it, with changes hidden behind feature flags to prevent breaking your apps.

Dark is a holistic programming language, editor, and infrastructure. By putting the three together we prevent developers from needing to think about infrastructure and deployment, and give them the ability to work with real data and traces.

— Engineering Team at Dark

At the time of writing, it’s still in private beta, but you can request an invite.

Want to gain access faster? Mention my name: Curtis Blackwell, Senior Application Developer at Highland.

I also want to point out that the people creating Dark seem awesome. Their values align well with Highland’s, and I personally admire their active approach to inclusivity—I would love to see more tech companies put people first.

Anyway, the app I’ll show you how to build is similar to IRC’s /me command. Yes, Slack already has a /me command, but all it does is regurgitate what you type in italics as though you said it yourself.

 /></p><p><img src=

apps page in your Slack workspace and click Create New App.

 /></p><p>Name and choose the workspace for your new app, then click <strong>Slash Commands</strong> then <strong>Create New Command</strong>.</p><p><img src=

Here’s Dark’s guide. I recommend you read it, but I’ll include everything you need to know to get through this tutorial.

First, a trace is basically a log of an event. As far as I’ve seen in Dark, it’s specifically a log of a request or function call. Without a trace, the Dark IDE won’t allow you to write code that attempts to access non-existent values, e.g. request.headers is inaccessible until you actually send a request. (Dark plans to change this, according to their guide.) When you have a trace available, a small dot will appear to the left of the handler, sort of like a tab/window in a more traditional IDE. As you create more traces, you gain the ability to select a specific one to work with. Simply click the dot representing the desired trace.

 /></p><p>In this image, the pink arrow points to the currently-hovered trace (its data appears to the left), the blue arrow points to other available traces, and the green arrow points to the currently selected trace (its data appears in tooltips and suggestions as you type).</p><ol start=
  • Writing an OAuth endpoint in Dark
  • Before we can write our OAuth endpoint, we’ll need to create a datastore to persist authorized Slack teams’ IDs and their OAuth access tokens, allowing members of the Slack workspace to use your app.

     /></p><ol><li>Add a datastore by clicking the plus sign next to <strong>Datastores</strong></li><li>Name the datastore <code>Tokens</code>, and</li><li>Add <code>String</code> fields for <code>team_id</code> and <code>access_token</code></li></ol><p>Next, we need to send a request to the endpoint before writing it. In the Slack app settings, under Settings, click on Manage Distribution. Copy the Sharable URL, and visit it in your browser.</p><p><img src=

    typical authorization code grant flow, so I won’t delve into what’s going on here.

    After defining response, click the play button to have Dark execute the code. You must do this before defining workspace so Dark allows you to access the values in response.

     /></p><p>If you receive an error indicating that the code has expired, just revisit the Sharable URL and click Allow again. Make sure you select the newest trace by clicking the highest white do to the left of the endpoint.</p><p>After defining <code>workspace</code>, click the play button next to it so Dark persists the OAuth token.</p><ol start=
  • Writing the slash command’s endpoint
  • Finally, we get to the most exciting part: writing a slash command! We already created the command in the Slack app settings earlier; now we just need to send a request to Dark so that we have a trace to work with.

     /></p><p>Just enter <code>/act whatever text you want</code> in Slack. Don’t worry when you get the error message; we expect that until we actually write the code to handle the request Slack sends to Dark.</p><p>Go back to your 404s in your Dark canvas and create a new endpoint from the new <code>/act</code> 404.</p><p>For now, let’s keep it simple and just throw italicized text back at Slack. After we have that working, we can add the more complex feature of displaying the user’s name. In the new <code>/act</code> endpoint, add the following code:</p><p>This code simply sends a POST request back to Slack using the URL Slack provided in the request, <code>request.body.response_url</code>. Then we pass the text we want to send (italicizing text is as simple as wrapping the text in underscores, just like when typing messages in Slack) along with the type of response. Without specifying the latter, the message would be visible only to the user who used the slash command. For more info, see <a href=

    Slack’s API docs.

    Once you have this done, click the play button in the Dark endpoint to have it respond to Slack again. This time, you should see your text displayed. Huzzah!

     /></p><ol start=
  • Grabbing the user’s profile
  • Now for some more fun, we’ll use Slack’s API to grab the user’s name for some proper narration. Let’s update our /act endpoint in Dark to look like this:

    First, to query the Slack API, we have to snag our access token from the Tokens datastore using the team_id from the request. Then we can pass the token and user_id (also from the request) to Slack’s API and pull the display name out of that.

    For more info, see the docs on the API endpoint.

    😅 Phew

    We now have a working Slack app to narrate our every move 👀! For some finishing touches, you can head over to the Slack app settings’ Basic Information page and fill out the Display Information card.

    Slack’s Display Information form showing the values I used to get my desired style.

    Download “The Essential Guide to Launching a Digital Product for Experts & Expert Firms”

    Let's Talk
    Tell us about the opportunity you're pursuing, and we'll follow up in one business day. If you prefer, you can email ask@highlandsolutions.com.