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?
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:
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.
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"'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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}}>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I had to use the slack Username for the mention to work
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.