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:
Here's before and after examples of the rule in action. (Previously it was just showing {{issue.assignee.displayName}}.)
I 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. :-}
Darryl Lee
Sr. Systems Engineer
Roku, Inc.
San Jose, CA
185 accepted answers
1 comment