How to Build a Slack App to Keep a Slack Channel Topic Locked with Airtable and Standard Library
Tags: slack, node, productivity, javascript
Published: 2019-09-25 23:22:15

---
title: How to Build a Slack App to Keep a Slack Channel Topic Locked with Airtable and Standard Library
published: True
description: Today we are going to see how you can retake control of your Slack channel topics by deploying a Slack bot on Standard Library that uses Airtable to lock a channel’s topic to a stored value. So let’s dive in!
tags: Slack, Nodejs, Productivity, Javascript 
canonical_url: https://medium.com/@brimm_reaper/how-to-build-a-slack-app-to-keep-a-slack-channel-topic-locked-with-airtable-and-standard-library-dddea4b9ca03
cover_image: ![](https://miro.medium.com/max/1080/1*KTtFl5yH6qck5o63Y-Qg2Q.gif)
---

[Have you ever wanted to lock your Slack channel topics?] (https://medium.com/@brimm_reaper/how-to-build-a-slack-app-to-keep-a-slack-channel-topic-locked-with-airtable-and-standard-library-dddea4b9ca03) A friend of ours, Ben Tossell, recently posed this question on Twitter: 

{% twitter 1174220505395732481 %}

A fine question, indeed.

If you’re reading this, then odds are that you use [Slack] (https://slack.com/) for internal communication when at work. It is likely that you also know that Slack Channel topics can set the tone for how users interact with one another in a given channel. They are a constant reminder that a channel is meant for serious business, reserved for horseplay, or falls somewhere in between. And while they are undeniably important, they are also extremely fragile, subjected to the will of the masses who make up the channel. At any moment your topic can be replaced, willy-nilly, by any member of the channel, and you are powerless to prevent it. That is, until now.

![](https://miro.medium.com/max/1080/1*KTtFl5yH6qck5o63Y-Qg2Q.gif)There is always one.


Today we are going to see how you can retake control of your Slack channel topics by deploying a Slack bot on [Standard Library](https://stdlib.com/) that uses [Airtable](https://www.airtable.com/) to lock a channel’s topic to a stored value. So let’s dive in!

*For those who just want to deploy a finished project, navigate to this [Github repo](https://github.com/stdlib-examples/project-slack-topic-bot). You will still need to set up Airtable and have a Standard Library account, but no other setup will be required on your part.*

##What You’ll Need Beforehand

1x Airtable Account — https://www.airtable.com
1x Slack Account — https://www.slack.com
1x Standard Library Account — https://www.stdlib.com

##Step 1: Setting Up Airtable

First thing’s first. We want to set up some way to persist our desired channel topics. Airtable, while it looks like a spreadsheet, works a lot like a database, and is simple to use and easy to set up. Get a free account by [clicking here](https://www.airtable.com/), and then click [here to add our template](https://airtable.com/addBaseFromShare/shruHRGfYKFcyU4U4) to your workspace. You should end up with something like this, except yours will only have 1 row:

![](https://miro.medium.com/max/3251/1*_liYZJ_xpbYUm-ohdqrncg.png) Highlighted: Table Name


Feel free to add as many channels as you would like here! For this tutorial, I would recommend adding the #random channel and a topic of your choosing to the Base (this will be used in our test event later on). Just note that you *must* include the *#* before all channel names in the first columns, and that **topics are limited to 250 characters.** You are now ready to move on to setting up your workflow.

#Step 2: Set up Your Workflow & Link Airtable

Head over to [Build on Standard Library](https://build.stdlib.com/) and begin setting up your project. Choose the following options for your project:

**Event:**

Slack → messages.channels

**Actions:**

Airtable → Select Rows by querying a Base

Slack → Set a Channel’s Topic

It should look like this:

![](https://miro.medium.com/max/5778/1*IWtIqBII1pQKA5WbeUfTPg.png)You are ready to **Create Workflow!**

The next screen that you see will ask you to link your Airtable and Slack resources. We already set up an Airtable account in the previous step, so let’s start there. Click on the blue **Link Resource** button next to Airtable. On the following dialog page, click **Link New Resource** to select your new table. If you have used Airtable with Standard Library before, click **Finish** to link your previous account. If you are new to Airtable, you will see a different dialog box asking you to **Enter a Name for Your Account** (I recommend your account email) and to **Retrieve the API Key from Your Account Page** (found here). The screen should look like this:

![](https://miro.medium.com/max/2174/1*m6SIpjaX1pi54nU50pqpvQ.png)Click on Finish to proceed!

Click on **Finish**, and on the next screen find and select the Base that we created earlier, **Channel Topics**, and click **Finish** here as well. That’s it for Airtable. Let’s move on to Slack!

#Step 3: Set up Your Slack Bot

To begin, click on the **Link Resource** button next to Slack. If you already have a bot set up in your desired workspace, find it and select it on this first dialog screen. That’s it! You’re ready to move on to the next step. If you do not have a bot currently set up in the desired workspace, then continue along in this section.
Once you click **Link New Resource,** you will arrive at our new Slack workspace linking process. Your screen should look like this:

![](https://miro.medium.com/max/2428/1*WMo3iDT4DWwR5ZgMTGaQLw.png)Choose Install Standard Library App to proceed.

Select the Standard Library Bot option and a pop-up will ask you to install Standard Library into your Slack workspace.

![](https://miro.medium.com/max/1668/1*G2MsLOg6pGKLi-poJUjd7w.png)Slack workspace OAuth page.

On the following page, you will have the option to customize your bot. Feel free to be as creative as you would like here, but keep in mind that if you choose to add additional functionality to your bot down the road, other users in your channel may be exposed to the name of your bot and the thumbnail image.

![](https://miro.medium.com/max/2444/1*pZFZsX67LCqX0MKn1WS0Ow.png)Our Topic Bot.

Click on **Finish** and you should now see a green circle with a message **Identity Generated** underneath your two resources. If you do, click on the blue **Next** at the bottom of the dialog box and move on to Step 4.

#Step 4: Set up Your Workflow

For this step, we will be using Build on Standard Library’s intuitive interface to generate Node.js code that will drive the functionality of our bot. The first order of business is setting up our Airtable query. Fill in the following details:

Table → Topics

Where → Channel → is equal to → #${result.step1.channel.name}

We can now give this a test run. Click the **pause** button next to the **Set a Channel’s Topic** row in our workflow, as pictured below, and click on the green **Run with Test Event** button:

![](https://miro.medium.com/max/3236/1*omGFzqraLeB8RRqopccyEQ.png)Finding our channel in Airtable.

Scroll down to the very bottom of the test result and find the portion that includes **“step3”.** It should look something like this:

![](https://miro.medium.com/max/1536/1*DCM0NvrPKv3-bkqjlooG9A.png) Your topic may vary.

If you see this, then we are ready to move on to the next step! Unpause the row that we paused earlier, and click on the six dots next to the Set a **Channel’s Topic** step in the workflow. Fill in the two fields as follows:

channel → ${result.step3.selectQueryResult.rows[0].fields.Channel}

topic → ${result.step3.selectQueryResult.rows[0].fields.Topic}

It should look something like this:

![](https://miro.medium.com/max/3100/1*T-ZaH60V0k1f4Vj4tKK2gg.png)We are ready to change some topics!

Click on the **Run with Test Event** button and watch your bot go! Check your Slack workspace’s #random channel and you should see a message informing you that the channel’s topic has been changed to the value you input in Airtable. Pretty neat!

#Step 5: The Finishing Touch

As it currently stands, our bot will attempt to change the topic in any channel that it receives any message in. But we really only want to perform this action when a user changes the channel topic in a channel that we are monitoring, not whenever Janice in accounting asks everyone to submit their expense reports. To do this, click on the **Developer Mode** button under your workflow to get a behind the scenes look at the code that we have been generating.
![](https://miro.medium.com/max/3272/1*WCBWY1eShJXgoJKS2TGd7Q.png)Developer Mode: ON.

Here you will want to replace all of the code with the following snippet to make sure that things are running smoothly.

This looks like a lot, so let’s take a closer look at what it is that we are doing.

-We are setting up some conditional logic to tell our project that if the message that is received is not an alert that the channel topic has been changed, then return a message to our logs (‘Status unchanged.’)

-If the message is an alert that the status has been changed, then we preform our query as written and perform one more conditional check before updating the channel topic

-Our conditional check looks to see if the channel is part of our Airtable Base, and then validates the topic length. If the channel is being monitored and the topic is valid, then we perform the set topic action using the value stored in Airtable for the respective channel

If you **Run with Test Event** now, the project should simply return a message informing you that the status was unchanged.

![](https://miro.medium.com/max/3056/1*AUgGNz3YOenr_u7RPN-iyA.png)You should see a “Status unchanged” message.

You will also notice that you received no message in your #random Slack channel regarding a topic change. This means that our checks are working as intended. Click on the blue **Next** button, give your app a name, and click **Alright, Ship it!** That’s all you have to do! Feel free to test it out. Happy patrolling, Topic Bot!

**Kevin Brimmerman is a Software Engineer at Standard Library. Outside of work he is an avid runner and a die-hard Chicago sports fan. Go Cubs! **