Tip #1: Making your Slack messages interactive using buttons:

StdLib LunchBot that asks what would you like for lunch today

At StdLib we overcame our lunch indecision (or lunch paralysis) through our LunchBot. With a simple command our LunchBot lists a few restaurants and asks everyone to vote using buttons.

Array of actions our StdLib LunchBot sends

In Slack, message buttons are are a type of action that you pass into the action array in your attachment.

Our bot attaches the buttons in array of actions . Here you can see how our lunch bot created two different actions for two different lunch choices. You can also check it out in the message builder. In a subsequent tutorial, we’ll have more detail on how you can implement handlers for those actions.

Check out Slack’s guide to attaching interactive message buttons for more information on buttons.

Here we’ll show you can build and deploy this really quickly. (This assumes you’ve gone through our tutorial on how to get a Slack Bot up and running with StdLib in 9 minutes)

In your service look for the file functions/commands/hello.js and modify the callback function to include the text and attachment. The results of the callback get passed directly into chat.postMessage .

For example:

After you modify the file run lib up dev then you can test it by running /hello command in Slack.

LunchBot in action

Tip #2: Making your Slack messages interactive using images:

StdLib LunchBot that gently encourages you to make a decision

Sometimes you want to add an image to your message to create a more dramatic effect.

In our Lunch Bot if nobody makes a decision or you choose not to decide we f̶o̶r̶c̶e encourage people to pick by t̵h̵r̵e̵a̵t̵e̵n̵i̵n̵g suggesting Keith’s (CEO and founder of StdLib) favorite restaurant as a place to eat.

Below you can see the JSON that we pass into the message to send an image and format it as an attachment.

List of parameters our bot sends to customize the attachment