Working with Message Attachments in Slack

Using Message Attachments in Slack Triggers

Due to popular demand, message attachment data is now available for most triggers. If the message is proceeded by an indent, then it's a message attachment:

Slack Message Attachment Example

Note: We are currently only able to trigger on non-ephemeral attachments, which appear to all users in a #channel or IM (rather than being visible to only you).

A lot of messages with these attachments come from bots, so in order to see and trigger on those, make sure you select "yes" on the "Trigger on Bot Messages?" field. If your bot doesn't post any text with the attachment, the first attachment's text will become that message's text. We'll include attachment details in the response as well.

Note: This feature is only available for trigger steps, not actions. If you'd like to send in a feature request for this to be added - contact us and let us know!

How do I filter message attachments?

Since message attachments aren't always going to be there, you'll probably want to limit your trigger to fire on certain user/bot names or channels. If you want to limit your trigger to a certain channel, use the "New Message in Channel" trigger and select your desired channel.

If you want your Zap to only trigger on certain user/bot names, you can add a Filter and look for the username field like so:

Example Zap

Sometimes message attachments can return a lot of data, and dealing with these responses can be a little daunting. So let's use a message from my Playlist Bot as an example. It posts a GIF of an artist and an associated playlist from Spotify, which are two separate attachments in Slack. Here's the message it posts to my channel:

To trigger off this, I set up my Trigger with "New Message Posted to Channel" and select your desired channel. Before you pull in samples, make sure the kind of post you're looking to trigger on is the most recent in the channel, otherwise you won't be able to grab that data.

Because not all messages will have this data, it's a good idea to set up a Filter to make sure we're only watching for posts from this particular bot. Let's add a Filter step to our Zap and set it to check our bot's username like above:

Great! Now we can take our desired action. In this case, it's posting this playlist and the associated GIF as a Photo Post to Tumblr:

And voila! Our GIF and the link to the playlist it made it to our Tumblr page:

Was this article helpful?
0 out of 0 found this helpful