Use 'Send Slack message' action in Automation to send a Slack direct message from Jira Service Management Cloud
Platform Notice: Cloud Only - This article only applies to Atlassian apps on the cloud platform.
Summary
The ‘Send direct message on Slack’ action is available in the automation rule in the service project. However, you can also send a direct message using the 'Send Slack message' action.
Solution
We are setting up an automation rule that sends a Slack direct message to the reporter when a comment is made on a work item.
Trigger an automation rule when a comment is made on a work item
Retrieve the email address of the work item's reporter and use the Slack API to obtain the Slack user ID associated with that email address.
Use the obtained Slack user ID to send a direct message to the target user via a Slack bot.
Preparation:
Setting up the Slack App:
Creating a Slack App: To use the Slack API, you need to create a Slack App and configure the appropriate permissions (scopes).
From Your Apps in the Slack API, create a new app.
Once the app is created, set the necessary scopes in the "OAuth & Permissions" section. You need "users:read" and "users:read.email" scopes.
Obtaining the OAuth Token: After setting the scopes, click the [Install App to <your Slack workspace name>] button to install the app into your workspace. This will issue an OAuth access token, which will be used later when performing the "Send Web Request" action in automation.
Obtaining the Slack Webhook URL:
Creating an Incoming Webhook: From the Incoming Webhooks setting in Slack, specify a desired destination channel for posts. (Initially, you can use the default #general channel. The configuration to send DMs to each user will be done later.)
Copy the generated Incoming Webhook URL. Later, we will paste this URL into the [Webhook URL] field of the "Send Slack Message" action in automation.
Reference: Use Slack with Automation.
Detailed Setup Instructions:
(Optional) Add the action "Log action."
In the Log message, include the following smart value (this is to retrieve the reporter's email address):
retrieve the reporter's email address
Reporter's email address: {{issue.reporter.emailAddress}}Add the action "Send web request" and set each field as follows:
[Web Request URL]:
Web Request URL
https://slack.com/api/users.lookupByEmail?email={{issue.reporter.emailAddress}}[HTTP method]: GET
[Web request body]: Empty
[Delay execution of subsequent rule actions until we've received a response for this web request]: Checked
[Headers (optional)]
Key:
AuthorizationValue:
Bearer <OAuth access token obtained from the Preparation>
In the Log message, include the following smart value (this is to retrieve the reporter user's Slack ID):
Slack ID
Slack ID: {{webResponse.body.user.id}}
Add the action "Send Slack message" and set each field as follows:
[Webhook URL]: Enter the Incoming Webhook URL obtained during the Preparation.
[Message]: Here, we mention the reporter in a direct message and include a link to the work item as well as an added comment. (You can customize this as you wish.)
Slack message body
<@{{webResponse.body.user.id}}> - Ticket: <{{issue.url}}|{{issue.summary}}> - Comment: {{issue.comment.last.body}}[Send message as Automation user]: Checked
[Channel or user]:
@{{webResponse.body.user.id}}
After setting these up, the automation rule should look like the following:


Was this helpful?