Walk-through: Check for New Slack Channels
It can be hard to keep up with all of the changes in your Slack workspace! This tutorial will walk you through how to build a simple tool in Darklang that posts all new, public Slack channels created in your Slack workspace in the past 24 hours.
A full sample canvas for this tutorial is available here.
Slack Configuration
- Create a new app in Slack.
- Navigate to Features -> OAuth& Permissions, scroll down to scopes and add
the following bot token scopes:
channels:manage,channels:read,chat:write, andchat:write.public. This will allow our app to interact with our the channels (also known as conversations) and post messages about them.

- Install your app to the workspace (either via Settings -> Basic Information or Settings -> Install App). Since this app is being built for your workspace specifically, we will not need to set up full OAuth, like we would if we wanted to distribute this more publicly.
- Copy your bot user access token, which will now be available under Settings
-> Install app and save it as a function in your Darklang canvas. Use this
function wherever you see
tokenin the code examples. - If no new channels have been created in your Slack recently, create a new public channel so we have some data to work with.
- You will need to choose a Slack channel to post your messages to. You can
find your Slack channel's id by navigating to the channel and looking for the
11 character string that begins with a capital C - it will look something
like
C1234567891. Add that to its own Darklang function as well, and use it wherever you seechannelin the code examples.
Building in Darklang
- Create a new daily Cron named
checkForNewChannelsby clicking the + in the sidebar next to Cron, and call thegetNewConversationsSlack function (it's a little confusing, but channels are referred to as conversations in the Slack API). ThegetNewConversationsfunction is built into Darklang's package manager, and it takes your token as well as an amount of time to check in Epoch seconds. Here, we're asking it to check in the past 24 hours, which is equivalent to 86400 seconds.

- Click the play button on the
getNewConversationsfunction and then place your carat innewChannels. You will see a list of information about any new channels that have been created.

- Create a function called
formatChannelListwith achannelListparameter. This is where we're going to build the format of the messages Slack will print about your new channels, but for now, just returnchannelList. You'll notice that an error is shown - this is becausechannelListhas not yet been set.

- Return to your
checkForNewChannelsCron, and add a line to format thenewChannelslist you previously generated. Press the play button.

- Return to your
formatChannelListfunction and place your carat over the top dot (trace) on the left. You will see yourchannelListtrace - now you can work with that data in order to format your list.

- For our purposes, we're going to do a very simple amount of formatting -
we're going to add the markdown Slack needs to make channel names links, and
add information about the channel's purpose. However, lots of information
about Slack channels is available. Type
val.and scroll through the autocomplete to see all of your options.

-
In your
checkForNewChannelsCron, rerunformatChannelListto update the value offormattedList. -
Add a check for the length of the list - we're going to print out something different if there have been no new channels.

- The full code is going to look like this - if there are entries in the list,
we'll post an announcement message and then the list of new channels. You'll
notice that we also use the
postMarkDownMessageSlack function to simplify the posting of the message.

- To make our code a little bit cleaner, we've pulled the logic of posting the list of new channels out into a function. This function iterates through the list it is given and posts a markdown message to Slack for each entry.

- Once you've completed all of your code, run the Cron again. A message will appear in the channel you selected.

Congratulations - you now have a Slack app that will post every 24 hours with any new channels created since it last posted.