You are here

JIRA Notifications via Slack

Background 

Atlassian’s JIRA Agile is a big part of how we build software here at Opsview. We often have multiple projects running at the same time, which means there is a lot of back-and-forth communication to keep track of. One of the biggest elements of communication that our teams often miss is the assigning of stories, defects and tasks. JIRA attempts to fix this with their standard communication method (email) which works for some, but not many of us here. Email can be too invasive, with JIRA alerts feeling like the 'wrong' sort of info to be in our mailboxes. It is also becoming an outdated method of receiving notifications. 

Attempting to correct the cons of email is where Slack comes in. It has taken our office by storm and for good reason; its slick design and plethora of integrations makes everything so much more efficient. It also gave us the idea to use it to notify one another of when we assign tasks to each other. Slack felt like a natural fit for casual notifications since we already receive so many from different colleagues and channels.

Jira Slackbot Screenshot

How We Implemented the Jira Slackbot

With Slack being as popular as it is, there are SDKs for almost any language. I’m a big Node.js fan, so we decided to go with that. The bot needed to do a few things and these became the requirements for the project:

  • Must alert users when they are assigned a task
  • The notification must tell them what they have been assigned and by whom
  • Must support future actions that we want notifications for
  • Must be able to work without each user telling the bot what their Slack username is

With the requirements set, I got to work. The first element was building a server to receive incoming web hooks from JIRA and to run the OAuth2 side of the app to get a token to talk to Slack with. I went with the industry standard Express.js and set up two routes to listen to: a POST request to `/jira-webhook` and a GET to `/redirect`. The POST request is listening out for messages from JIRA. JIRA sends a massive JSON payload with each web hook with volumes of data about the change. From that, I could pull out all the info needed.  

Beforehand, it was also necessary to work out what type of notification this is. By using a simple switch case to check the contents of `issue_event_type_name` and run the notification code when it is `'issue_assigned’`, it allowed me to easily add support for other events in the future.

Once I knew something had been assigned, I could deconstruct the JSON payload to work out what it is and who to notify. I first used ES6’s fantastic templating syntax to build a string to send to the recipient:

`${response.user.displayName} has just assigned ${response.issue.key} to you (${changelog.toString}) - https://opsview.atlassian.net/browse/${response.issue.key}`. 

Including the URL helps people save time fiddling around trying to find it in their queue or on the project board. 

The next step was to check if there were any comments in the last 15 minutes on the task, and if there were, tag them on to the message. This helps add context to why the task is being issued to them and gets rid of the need to ask the assigner about why they’ve been assigned the task. 

Next, a quick check is important to make sure that you don’t get a notification when assigning something to yourself - some wanted to get notifications in this case, but we decided it could be confusing to new users. The last thing to do was look up the user in the Slack directory based on their JIRA email address. I listed the users in the directory and compared the email address we have against each one until a match was found, using the corresponding user ID to contact them in Slack. That’s it. Ping. The recipient gets a message in their `Slackbot` chat from our bot letting them know what’s up.

This was a small, but fun and rewarding project as it gave us a chance to improve productivity as a direct result of gripes that we had about the way we communicate changes in JIRA. We’re hoping to add more support for other events in the future and we’ve tried to build the bot in a way that anyone can use it! 

A single platform for your monitoring notifications