Start tracking your progress
Trailhead Home
Trailhead Home

Customize Slack Messages

Learning Objectives

At the end of this unit, you will be able to:

  • Explain the basics of Slack Message formatting.
  • List best practices in creating Slack Messages.
  • Add interactivity to your messages.

Mightier Slack Messages

The pen is mightier than the sword, and the Slack Message is mightier than the pen. Well, maybe that’s not quite how the idiom goes, but it’s close enough—the Slack Message is mighty in the realm of productivity!

In this unit, you’re going to learn how to get the most out of them with your Slack App.

The Basics of Message Formatting

At face value, messages are easy to construct. A message is a simple JSON object containing your message text and related attachments.

The JSON object "text": “This is a line of text. \nAnd this is another one.”

Your App posts in Slack, “This is a line of text.” On the next line, “And this is another one.”

Formatting your message is done with some simple cues in the text of your message.

  • Use double stars for bold text, **[bold text]**.
  • Use underscores to indicate italicized text, _[italic text]_.
  • Use \n for a line break or new line.
  • Use a single backtick ` for a line of code.
  • Use a triple backtick ``` for a larger block of code.

You can do more with your text than simple bolds and italics.

  • Link to users and channels with the following construction <@0000XXXXX>.
  • Hyperlink to a web page using a | after the the URL, like <http://www.example.com|hello>. This example displays as hello, but links to http://www.example.com.
  • You can also display and format dates from Unix timestamps. <!date^1392734382^Posted {date_num} {time_secs}|fallback text goes here> displays as Posted 2014-02-18 6:39:42 AM.

Sometimes on older Slack clients, the automated date conversion from timestamp doesn’t work. Fallback text, shown above, lets you post the date/time in string. 

  • You can show an emoji by typing a colon. :smile: will display as smiling face with open mouth.
  • And you can use special commands with an exclamation mark. For instance, <!channel> links to #channel.

You can test all of this out in Slack’s message builder, located on the Slack API website.

The message builder on the Slack API site lets you input a message in JSON and preview it in the Slack UI below the input field.

Note

Note

There’s a lot more to be said about formatting text in your messages. Bookmark the developer documentation so you can always refer to the docs as you build your Slack App. If you install the Slack Developer Tools app, you can also copy the JSON from apps with message design you like.

Text is only the start of your quest—Slack gives you other tools you can use to forge amazing messages.

Attachments

Any user can format their messages in the ways we’ve highlighted above. Slack Apps have a special power to add more context and interactivity to their messages, through attachments.

Attachments make your messages richer with context. 

The attachment message with input fields for title and various text.

Let’s break this down.

  • On top of the attachment box, you can include an author (linkable), a title (also linkable), some pretext, and some optional text.
  • At the bottom of the attachment, you can include an icon, some footer text, and a timestamp.
  • In the middle, you can include any fields you want, either short or long.

And all of this is as simple as writing it in the JSON. 

An attachment written in JSON, with fallback, color, text fields, and image URLs.

Use attachments to bring richer information into your messages, as well as to organize that information.

Get Interactive

It’s time to take your messages to another level completely by making them interactive.

Buttons

Buttons are exactly what they sound like—little buttons, letting users select between values.

Your App posts in Slack, “Would you like to play a game?” with options for Chess and Go.

Setting up buttons is as simple as attaching a JSON object to a field in an attachment.

JSON for “actions” indicating a button for Chess.

When a button is clicked, an event fires through the Slack Events API to let you know so you can take the next step in the app.

Menus

Menus at their core are dropdowns that let users select between a set of options. 

Slackbot reminding the user to “drink water” with options to mark as complete, delete, or snooze with a dropdown option for 20 minutes, 1 hour, 3 hours, tomorrow, or next week.

With buttons and menus, you can give your users a means to respond to your app through choices whether it’s to mark a task to send an email as complete, snooze a reminder to drink water, and so on.

Best Practices

Messages and Formatting—check!

Attachments—check!

Buttons, Menus, Interactivity—check! 

In this unit, you’ve learned the basics of customizing Slack Messages. But there is an art to using these tools to craft powerful messages with meaning. Ultimately, it can be broken down into two strategies: Be concise and be clear.

Be Concise

In general, strive to make your messages as concise and as uncluttered as possible. This can take form in a lot of ways.

  • Consider using a single text message before using Attachments.
  • Use one Attachment to convey your message when possible.
  • Keep lists small.
  • Use the least amount of formatting needed.

Be Clear

The goal of your message is to enable your users to get from point A to point B in their work. Make this process as simple, quick, and productive as possible for them.

  • Focus on tasks that make sense to complete inside Slack conversations, rather than trying to offer too many options.
  • Use color to resonate with your users.
  • Know your button types—primary, default, and danger. If there is a primary action you wish to highlight above all other actions, use the primary button. If an action is destructive (think delete), use the danger button and offer a clear confirmation step before carrying out the action.
  • Use those primary and danger buttons sparingly!
  • If there’s a destructive step, offer a direct confirmation step to ensure your user wishes to take it.
  • After a user does something—clicks a button, takes any sort of step—be sure to give them a confirmation message or visual to ensure they know they completed the action.

Additional Strategies for Successful Messages

  • Send a regular message to the whole channel if it’s useful for everyone to see an action that has been taken.
  • If you want something visible only to a certain user, then send them a Direct Message.
  • If something requires a lot of steps, send ephemeral messages to the user taking those steps to avoid cluttering the channel. Ephemeral messages are a special kind of message on Slack visible only to a specific user based on the context.

Messages contain a wide variety of formatting tools to deliver more organized content, as well as loads of interactive features to give your people what they need to conquer in the name of productive work.

In the next unit, you learn about the the things that connect the world of Slack to the rest of your business universe: the Slack APIs.

Resources

retargeting