How can I map Jira users to my Slack users when sending notifications with Automation for Jira?

andreas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 5, 2019

In the past it was possible to @mention users in Slack simply by adding this type of smart-value to your Automatin for Jira rules (see https://docs.automationforjira.com/getting-started/actions.html#send-slack-message):

Hi @{{assignee.name}}

This would at runtime be replaced with the Assignee's Jira username, and Slack would mention this user.  

Now that Jira Cloud will remove usernames & user keys due to GDPR, how can we still mention Slack users directly with Automation for Jira?

 

5 answers

1 accepted

0 votes
Answer accepted
andreas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 5, 2019

I'm glad you asked ;).  So this has become a little more complicated.  

First of all: The above was never 100%  correct, and would have only worked, if your Jira usernames, mentioned your Slack usernames exactly.  If they didn't always match, then this wouldn't have worked at all.

Going forward we do want to add a better Slack integration in future that will allow mapping Slack users to their corresponding Jira users, however in lie of that, there's another solution using user properties.

 

For each user you'll have to set their slack handle as a user property in Jira.  This is now necessary, since usernames will no longer be available in Jira cloud.

To set the slack handles as properties you'll have to make some REST calls to your Jira instance:

  1. First you need to get an API token for this: https://confluence.atlassian.com/cloud/api-tokens-938839638.html
  2. Next for all of your users, you'll have to set their slack handle using this CURL command:
    curl --request PUT \
    --url 'https://YOUR_CLOUD_URL/rest/api/2/user/properties/slack?username=USERNAME' \
    -u YOUR_USERNAME:API_TOKEN \
    --header 'Content-Type: application/json' \
    --data '"SLACK_HANDLE"'

For example here's a request to set my Slack handle against our instance:

curl --request PUT \
--url 'https://codebarrel.atlassian.net/rest/api/2/user/properties/slack?username=admin' \
-u andreas@codebarrel.io:abc123def456 \
--header 'Content-Type: application/json' \
--data '"andreas"'

So this will set the 'slack' user property for the 'admin' user to 'andreas' on our 'codebarrel.atlassian.net' instance

 

Next in your Automation rules, you can use this smart-value to now mention users:

Hi @{{assignee.properties.slack|assignee.displayName}}

This will try to lookup the slack mention from user properties, and fall back to the full name, if no slack property can be found.

slack-mentions.png

Martin Bossev July 31, 2020

This workaround still works but the query is a bit different and accountId needs to be used now as it looks like username is deprecated:

 

curl --request PUT \
--url 'https://YOUR_CLOUD_URL/rest/api/2/user/properties/slack?accountId=USERNAME' \
-u YOUR_USERNAME:API_TOKEN \
--header 'Content-Type: application/json' \
--data '"SLACK_HANDLE"'

 

Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 9, 2020

In a recent ShipIt, we wrote a python script that handles (no pun intended) the Jira user properties for you when you feed it your Jira API and Slack API tokens. Check it out in this article or view the script directly here.

Like Jonas likes this
1 vote
JOY April 3, 2023

Hello,

Is there any update on this request so a non-tech admin like me can setup it?

I don't know where to run these scripts.

0 votes
ekaterina.zadorozhnaia May 17, 2022

Hello to everyone who has encountered this problem and is looking for a solution.

I hope my short summary will help to save a few hours of ones work ;)

 

First of all, thank you very @andreas without your tips and script I wouldn't be able to do it🙏!

 

With new GDPR requirements initial scrip needs to be adjusted in the following way:

curl --request PUT \

--url 'https://YOUR_CLOUD_URL/rest/api/2/user/properties/slack?accountId=abc123abc' \

-u YOUR_USERNAME:API_TOKEN \

--header 'Content-Type: application/json' \

--data '"SLACK_Member_ID"'

To find accountID run the following API call:

https://YOUR_CLOUD_URL/rest/api/3/user/search?query="YOUR_USERNAME"

To find SLACK_Member_ID follow these steps:

- Click on a user name within Slack.

- Click on "View profile" in the menu that appears.

- Click the more icon "...".

- Click on "Copy Member ID".

 

Last step

In your automation to trigger the mentioning function use "<>" along with a smart-value 

e.g.

Hi <@{{assignee.properties.slack|assignee.displayName}}>
0 votes
Ricardo Gomes April 30, 2020

Hi @andreas ,

Which Slack property is the correct one to use for the mention to work?

Is it the "real_name" or display_name" one?

Thanks!

Martin Bossev July 31, 2020

I had to use the slack Username for the mention to work

0 votes
Haris Vugdalic March 14, 2019

Oh boy, this is rough workaround with large sets of users. How much of a priority is it for you guys to improve the integration to support mentions better? Do you happen to have a timeline? I'd imagine this is quite a popular use case for JIRA automation.

John McKiernan
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
March 26, 2019

Hey Haris,

Sorry about the slow response on this one. We can't give an exact timeline on it unfortunately as we have a lot of high priorities in our backlog right now. 

Once we do ship the improvement though, we will leave a note here so you know. 

Cheers,

John 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events