Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Send a Slack message with an @mention using Web Request

My colleague asked me about this article:

Wherein @Daniel Eads provides a Python script to connect to the Slack API and for every user in the Slack workspace, obtain their User ID and then write a Jira User Property for each user with that ID.

Which... is cool. But sounds like a lot of work. And you have to regularly schedule it to run, or trigger it when there's a new user added to... Slack? Ugh. I ain't got time for that. :-}

Why not use the Slack API to look up just the User ID you need?

So I also created a Slack App bot (not user) token with users:read.email scope and then used it in a Web Request to call the Slack API users.lookupByEmail method.

My colleague was sending a Slack notification to let Assignees know when a ticket has breached SLA, so here's the Web Request URL, and so he needed their Slack User ID for the @mention.

https://slack.com/api/users.lookupByEmail?email={{issue.assignee.emailAddress}}

It's a GET, and you should check the Delay checkbox that pauses your automation until it gets a response back.

Note that your Slack token needs to be in an Authorization header as shown, and the Value should be: Bearer YOURTOKEN. Once you've confirmed it works, it's good practice to Hide it, as other admins (including Project admins) would otherwise be able to see it. 

Finally, to format the @mention properly for Slack you'll use this

<@{{webResponse.body.user.id}}>

Here's a screenshot:

Screenshot 2024-07-12 at 1.04.36 AM.png

Here's before and after examples of the rule in action. (Previously it was just showing {{issue.assignee.displayName}}.)

image (27).png

guess if you're trying to minimize Web Requests calls (oh no, are they going to start charging us for them?), then syncing all the IDs to User Properties is a fine approach. It certainly is faster.

But that's a lot of infrastructure you have to maintain. I thought moving to the Cloud was supposed to free us up from that. :-}

1 comment

Travis Hill
Contributor
July 31, 2024

This is awesome! I want to attempt to use this as I am running into issues with Python on the other solution as well.

I had one quick question on: Value should be: Bearer YOURTOKEN

How do you go about getting your token information? Ive been trying to find some resources without much luck. (maybe I have to be an admin?)

Thanks in advance!

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events