DEV Community

Cover image for Automate JIRA Ticket Updates with Slack Reactions
Abhishek Vaidya
Abhishek Vaidya

Posted on • Edited on

Automate JIRA Ticket Updates with Slack Reactions

Tired of Manually Updating JIRA Tickets? Let Slack Reactions Do It for You! 🚀

On-call engineers already have enough on their plate—manually updating JIRA ticket statuses shouldn’t be one of them. It’s a tedious, time-consuming task that’s easy to forget, leading to delays and miscommunication.

But what if a simple Slack reaction could handle it for you? In this post, we’ll build an automation that updates JIRA ticket statuses instantly based on Slack emoji reactions—saving time and making life easier!

Fun Fact: Even AI can't generate this solution. Yet! 😎

Architecture

Image description

The workflow begins when an end-user creates a JIRA ticket in Slack using the /jira create command or directly from the console. Automation is triggered based on the emoji reaction to the Slack message, which seamlessly updates the JIRA ticket status.

Prerequisites:

  1. Need a paid Slack subscription.
  2. An AWS User/Role with the below permissions:
    • AWSLambda_FullAccess
    • IAMFullAccess
  3. Jira Cloud integration with Slack

GitHub

You can find the resources in abhivaidya07/slack-reaction-bot

Steps:

Create a Slack Application

  1. On the Your Apps page, select Create New App.
  2. Select From scratch.
  3. Enter your App Name.
  4. Select the Workspace where you'll be developing your app. You'll be able to distribute your app to other workspaces later if you choose. Image description
  5. Click Create App.

Adding Permissions to Slack application

  1. Go to the Slack application created in the above steps.
  2. From the left navigation panel, select OAuth & Permissions, scroll down to Scopes.
  3. Under Bot Token Scopes, select Add an OAuth Scope.
  4. To allow your app to react based on slack reactions, add below scopes:
    • channels:history
    • reactions:read
    • users:read
    • users:read.email Image description
  5. Scroll up to OAuth Tokens and click on Install to Workspace button. Image description
  6. You'll now be sent through the Slack OAuth flow. Select Allow on the following screen.
  7. Copy and Save the Bot User OAuth Token (starting with xoxb), we will need it in the next steps !!

Enable Workflow steps

  1. From the left navigation panel, select Org Level Apps.
  2. Click Enable Org-Readiness and enable it. Image description
  3. Go to Workflow steps in left navigation panel.
  4. Click on Update settings Image description
  5. We'll enable Event Subscriptions in further steps.

Create Lambda Function (Using AWS Console)

  1. Open the Functions page of the Lambda console.
  2. Choose Create function.
  3. Select Author from scratch.
  4. In the Basic information panel, enter the Function name.
  5. For Runtime, choose Python 3.9.
  6. Leave architecture set to x86_64.
  7. Expand Additional Configurations and then select Enable function URL.
  8. For Auth type, choose NONE. Image description
  9. Choose Create function.

Create/Attach Lambda Layers

  1. Install python version 3.9
  2. Run the below command to install jira package on the local filesystem.

    pip3 install jira -t jira/python
    
  3. Repeat the same command to install requests package on the local filesystem.

    pip3 install requests -t requests/python
    
  4. Create .zip files for both the install packages

    cd jira && zip -r ../jira_layer.zip python
    cd ..
    cd requests && zip -r ../requests_layer.zip python
    cd ..
    
  5. Create AWS lambda layers using the below commands:

    aws lambda publish-layer-version --layer-name jira-layer --zip-file fileb://jira_layer.zip --compatible-runtimes python3.9 --query 'LayerVersionArn' --output text
    aws lambda publish-layer-version --layer-name requests-layer --zip-file fileb://requests_layer.zip --compatible-runtimes python3.9 --query 'LayerVersionArn' --output text
    
  6. Copy LayerVersionArn from the above commands

  7. Run the below command to attach layers to the lambda function.

    aws lambda update-function-configuration \
    --function-name <FUNCTION_NAME> \
    --layers <JIRA_LAYER_VERSION_ARN> <REQUEST_LAYER_VERSION_ARN>
    


    Replace the following:

    • FUNCTION_NAME: Name of the lambda function created in above steps.
    • JIRA_LAYER_VERSION_ARN: ARN of the JIRA layer.
    • REQUEST_LAYER_VERSION_ARN: ARN of the request layer.

Upload Code to Lambda Function (Using AWS Console)

  1. Clone this GitHub repository.
  2. Zip the repository content using the below commands.

    cd slack-reaction-bot
    zip -r slack_reaction_function.zip . -x ".git/*"
    
  3. Open the Functions page of the Lambda console.

  4. Choose the function created above and choose the Code tab.

  5. Under Code source, choose Upload from.

  6. Choose .zip file, and then choose Upload.

  7. Select the zip file we created in earlier steps.

  8. Uploaded code structure should look like this:
    Image description

  9. Click Deploy.

Set Environment Variables for Lambda Function (Using AWS Console)

  1. Open the Functions page of the Lambda console.
  2. Choose the function created above and choose the Configuration tab.
  3. Select Environment variables, choose Edit.
  4. Click Add environment variable and add below variables:
    • Key: JIRA_SERVER, Value: Your JIRA server URL for eg. https://org-name.atlassian.net
    • Key: JIRA_USERNAME, Value: Your JIRA username.
    • Key: JIRA_API_TOKEN, Value: API Token for above user. Refer to this link for token creation.
    • Key: SLACK_APP_TOKEN, Value: Slack token created in Adding Permissions to Slack application step
    • Key: DONE_TRANSITION_ID, Value: Transition ID of done status. for example: 41
    • Key: IN_PROGRESS_TRANSITION_ID, Value: Transition ID of in-progress status. for example: 31
      • Steps to get transition ID:
        • Go to JIRA board > Project settings > Workflows > Edit workflow
  5. Click Save.

Enable Event Subscriptions

  1. On the Your Apps page, select application created in above steps.
  2. From the left navigation panel, select Event Subscriptions and toggle Enable Events to ON.
  3. Paste the Function URL of our lambda function into Request URL
  4. Request URL should be Verified. Image description
  5. (Temporary) Within Subscribe to bot events, select Add Bot User Event, then search for reaction_added.
  6. Click Save Changes.

Note: We will remove the reaction_added event to ensure we do not receive two events when a slack reaction is added.

Create Workflow Steps

  1. From the left navigation panel, select Workflow Steps.
  2. Click Update settings from the highlighted text. Image description
  3. Go to Event Subscriptions, remove the reaction_added event added in the earlier step and click Save Changes.
  4. Go back to Workflow Steps and click Add Step.
  5. Provide the Basic Information as shown in the below image: Image description
  6. Click Input Parameters and fill in the details as follows:
    • Input 1:
      • Input type: String
      • Make required: Enabled
      • Parameter ID: message_ts
      • Title: Message Timestamp
    • Input 2:
      • Input type: Channel
      • Make required: Enabled
      • Parameter ID: channel_id
      • Title: Message Channel ID
    • Input 3:
      • Input type: User
      • Make required: Enabled
      • Parameter ID: user_id
      • Title: Message User ID
  7. Click Create.
  8. Add one more step, while providing Basic Information as shown in the below image: Image description
  9. Click Input Parameters and fill in the details as follows:
    • Input 1:
      • Input type: String
      • Make Required: Enabled
      • Parameter ID: message_ts
      • Title: Message Timestamp
    • Input 2:
      • Input type: Channel
      • Make Required: Enabled
      • Parameter ID: channel_id
      • Title: Message Channel ID
    • Input 3:
      • Input type: User
      • Make Required: Enabled
      • Parameter ID: user_id
      • Title: Message User ID
  10. Click Create.
  11. Go to Install App from the left navigation bar and then click Reinstall

Now we are ready to create automation based on Slack reactions !!

Add Automation on Slack Channel

  1. Open the slack channel on which you want to add automation.
  2. Click on the name of the channel and go to the Integration tab. Image description
  3. Under Apps, click Add apps and select the slack application created in earlier steps.
  4. Go back to the Integration tab, then click on Add Automation.
  5. Now click on + New Workflow and select Build Workflow.
  6. For event choose When an emoji reaction is used.
  7. Choose an emoji of your choice and channel on which you want automation to work. for eg. I'm using emoji as ✅ and channel as #devops Image description
  8. Click Continue.
  9. For Steps, scroll down to the last and select Custom.
  10. Select the Slack application, which we created in earlier steps.
  11. Select Update Status Done, as this automation is to update the JIRA ticket status as done.
  12. Provide inputs for Message Timestamp, Channel ID, and User ID as specified in the image below: Image description
  13. Click Save, then click on Finish Up
  14. Provide Name and Description to the automation.
  15. (Optional) You can also specify who can manage, copy, or find this workflow by clicking on Show more permissions.
  16. Click Publish.
  17. Repeat the same steps to create automation for updating the JIRA ticket status as In Progress. Image description

Is it working?

  1. Create a JIRA ticket on Slack using /jira create command. Image description
  2. Add a 👀 reaction to the ticket.
  3. This will trigger our In-Progress automation and perform the following steps:
    • Update the ticket status to In Progress.
    • Update the Assignee to the user who reacted. Image description
    • If the ticket status is already In Progress, then the Lambda function specifies it in CloudWatch logs.
  4. Now add a ✅ reaction to the ticket.
  5. This will trigger our Done automation and perform the following steps:
    • Update the ticket status to Done.
    • Add a comment on the ticket. Image description
    • If the ticket status is already Done, then the Lambda function specifies it in CloudWatch logs.

Conclusion

To sum it up, we’ve created a seamless automation that updates JIRA ticket statuses directly through Slack reactions. With the power of a Slack app, AWS Lambda, and Slack workflow steps, this solution not only saves time but also ensures smoother workflows. Plus, it’s highly customizable—you can extend it to handle more reactions, add comments to JIRA tickets based on Slack threads, and much more. The possibilities are endless for optimizing your team's productivity!

Alternatively, you can explore JIRA Service Management, which costs approximately $140 for 4 agents (on-call engineers). However, with this solution, you only pay for the AWS Lambda executions, making it a more cost-effective approach. 🚀

Questions?

If you have any questions, I’ll be happy to read them in the comments.
You can connect with me on LinkedIn.

Thank you for reading :)

Top comments (0)