How to set a Slack status from other apps

How the Zapier team uses custom status in Slack

One of the most important parts of a developer’s work is communication about the work. That’s why we review pull requests, talk through architecture, and follow processes. At Zapier, since we’re an entirely remote company, most of those discussions start in Slack. For the last couple months, we’ve been setting status messages to help our teammates worldwide know how to best work with us.

Set a custom status to let your team know what you’re up to

Slack’s custom status does some things automatically, like set itself to “on a call” when someone hops on a video chat. We quickly realized there were many other situations where we could intelligently make automatic status updates and improve work with our teammates. Since Zapier helps anyone bring automation to the apps they use every day, it was natural that our team and customers would find ways to do that with Slack statuses. Now I’d like to help you do the same in your own code.

The status endpoint

You can use Slack’s APIs to set your status outside of the user interface. Sending your Slack status via API is the first step toward automating your status based on activity in other apps.

There no separate status endpoint. Instead, you set a custom status by sending data to the user profile endpoint:

https://slack.com/api/users.profile.set

You’ll need three more things to send your status to Slack:

1. The status data
2. An access token with appropriate scopes to edit the user’s profile (eg: users.profile:write)
3. Some way to make an API request

The first is the easiest, because you likely already know how you want to set your status. You’ll need to convert that to JSON format, like this:

{
“status_text”: “Reading about automated status”,
“status_emoji”: “:slack:”
}

You’ll need the text of your message and your emoji of choice. This data can be changed later, so don’t worry if you haven’t figured out your perfect status yet.

Since this is a proof of concept, you can create a test token, or check out Slack’s more recent route to building an app for just your team, internal integrations.

Armed with your status JSON and access token, we can now make the API request. There are many online tools you can use to send API requests, such as Hurl.it or the tester tab in Slack’s own documentation. Here, we’ll use cURL, the popular command-line utility that may already be installed on your machine.

From a terminal prompt, paste this command:

curl -X POST https://slack.com/api/users.profile.set\?profile\=%7B%0D%0A%20%20%20%20%22status_text%22%3A%20%22Reading%20about%20automated%20status%22%2C%0D%0A%20%20%20%20%22status_emoji%22%3A%20%22%3Aslack%3A%22%0D%0A%7D\&token\=YOUR_TOKEN

Replace `YOUR_TOKEN` with your actual token and hit enter. Now check your Slack status, which should match your update!

Note that the profile field has URL-encoded JSON, including the `status_text` and `status_emoji` values described earlier.

The next step is to take this example API call and include it within your own Slack applications. For example, at Zapier we built an app to interact with the Slack API via our developer platform. When the status feature was added to Slack, we were able to quickly incorporate it as an action within our app.

Ways to intelligently communicate status

Like many teams, we were excited to update our statuses in Slack. A Zapier engineer quickly incorporated it into our Slack automation app.

Want a behind-the-scenes peek at Zapier’s Slack automations? Here are some handy use cases we’ve found for setting a custom status.

Calendar events

If you live your life by a calendar, let your coworkers know when meetings are taking your attention. Sure, your co-workers could check your calendar, or you could remember to update your status manually, but those both require space in your mind that could better spent on that call or project.

Most calendar events have a start time and an end time. Either, or both, of these times are good ways to hook into your Slack status.

You can set your status at the beginning of a calendar event, or even a few minutes before. Choose a status based on the title, description, or attendees. For example, if the calendar event is “Coffee with Matt,” you could automatically pull out coffee as a keyword and set the status “Having coffee” with the `:coffee:` emoji.

There is a lot of context that you can pull from calendar events, so get creative! The harder part may be pulling data from your calendar in the first place. Many cloud calendar services, such as Google and Office 365, have APIs. Another programmable option is Cronofy, a sort of abstraction service across multiple types of calendars. Zapier also supports a handful of calendar apps.

Location

Your physical whereabouts is useful to communicate in your Slack status. At Zapier, our entire team is remote, so it’s common to work from cafes and coffee shops. It may be more difficult to hop on a video call, for example, when in public. So, it’s helpful to know when my co-workers are away from their home offices.

If you use Swarm, Facebook, or another app to “check in” when you’re out and about, you can help Slack tap into that location awareness. For example, Swarm has categories for every place, so you could use them to automatically craft your status text and even choose an emoji. When I check in at the gym, my app could set my Slack status as “Working out” and pair that with an impressive “:weight_lifter:” icon.

Your calendar (see the previous section) is another place where you can find location context. Every calendar event has a location field. While this isn’t really communicating where you are, it does get across where you should be.

Other methods of determining your location could include apps on your phone, which pull your GPS data in real-time. Either use APIs provided by those apps, or write your own app that sets Slack status from your whereabouts.

Work activity

The apps you use or websites you visit say a lot about what’s taking your attention in the moment. Pay attention to the signals in your activity, and your Slack status may write itself!

Let’s say you use a time tracking app in work with clients. When you start the clock, why not also let your co-workers know?

These services typically connect time tracking to a particular project. Heck, you could even make a custom emoji for every client and use that in your status.

If detailed time tracking is too granular for you, how about connecting your task or project app to your status? Let’s say you use the popular project management tool, Trello. Whenever you drag a card into the “Working” list on your Trello board, you could update your Slack status. Create your status based on the card labels, open checklist items, or any of the other data on each card.

Other project management apps may have similar features. One we like is RescueTime, software you install on your machine that reports on what websites and applications you use most. RescueTime also has the concept of FocusTime, a session designed to remove distractions so you can work. These sessions would be great time to set your Slack status accordingly so others know not to expect a response right away.

RescueTime and Trello both have APIs, and are available through Zapier. Look at the documentation for your project management tool to see how you might communicate your work activity with automated and intelligent status messages.

Time of day

Routines are powerful forces in our work lives, and they can provide a foundation for your custom status in Slack. While similar to calendar events, setting your status by the time of day is less specific. With teammates in different timezones all around the world, this way of setting status has been extremely useful at Zapier.

Choose a time of day when you’re typically “off the clock” (or should be) and automatically set your status to let your co-workers it’s the end of your day. Pair that with :city_sunset: or :zzz: emoji and you’re ready for your evening.

Of course, nobody wants to still appear sleeping in the middle of their day. Automatically clear your status or choose a breakfast emoji to start your next day. You can do something similar with the beginning and end of your typical weekend. Expand this to other times that are part of your routine, and you’ll have the outline of status that follows your usual week.

To do it, anything that can load a URL at a specific time will suffice. You can simply set a cron job on your machine or a server you can access, and have it call the cURL command we set up earlier in this post. Zapier has a similar concept in our Schedule app, and there are some online cron services that may work, too.

Better communication means better work

Now you can write a little code and intelligently update your own custom status in Slack.

In the process you’re helping your co-workers work better with you, and giving yourself more time to focus your efforts. That’s code worth writing!


By Adam DuVander