Automate As Much As You Can

Don’t waste your time doing the same thing over and over again!

Fahri Shihab
4 min readJan 29, 2020

Today, we live in a world where technology has helped us in so many ways. Voice call over the internet, connect to your car audio systems via bluetooth, even book a ride to your destination via your mobile phone. Those three examples are complex technologies that require more than 1 person to build.

Let’s scale down a little bit. Try to think of yourself at this moment, how can technology help you right now? Some of you who are reading this are on a short break from doing a repetitive stuff. Well if its repetitive, why not automate it?

Gojek Group CTO, Ajey Gore, once told us

If you had to do the same thing twice, the third time must be automated!

This sentence really got stuck in my head and has helped me enhanced my automation and scripting skills. So I decided to dedicate this post about automating some repetitive task that I encounter at work.

At Gojek, we set up slack alerts for our custom policies at our cloud infrastructure. If the alert is categorised as a potential incident, we would forward it to the respective team for a justification and a fix.

Sample Alert

The bolded sentence is one of my repetitive tasks and is what I aim to automate.

To report this to the respective teams, we have a centralized ticketing system powered by freshservice which APIs I will be leveraging for this.

Getting Started

To get started with this, we need to build a slackbot. This page explains in such great detail and will help you set it up. I personally like his template and refer to it for my next projects.

I don’t want to go into much technical details on this post, but I will share with you the major change to make this functionality to work.

The app

Basically that is what this automation looks like. Once an alert comes, you can reply on the thread mentioning the bot with the command :

@k.k create ticket [entity] -m [Additional Message" -u [UrgencyLevel]

Milestones

Retrieve parent message from the same thread

The goal of this is when we type the bot command, it will be in a thread and for the bot to pickup the actual message, we need to use Slack’s API to retrieve that.

For this case, we will be using conversations.replies API. Here is the full function I wrote

ticket_ts = the timestamp of the message
ticket_ch = the channel of the message
history_token = bot token used to run this API

Create Ticket to Freshservice

Once we have the content for our soon-to-be created ticket, we can go ahead and hit the Create Ticket API for Freshservice. You can choose between an API key, or basic username and password authentication. I chose API key in this scenario.

Now, we should pay attention to the fields from the Freshservice UI. When generating the ticket dictionary in python, we have to make sure that the required fields are present.

Here is a snippet of my create_ticket function

domain = your freshservice domain (ex: domain.freshservice.com)
bot_message = the additional bot message (the -m argument when calling the bot)
urgency_message = ticket urgency

Hopefully by now, you also have a fully functioning Freshservice create ticket automation! What I want to emphasize here is that technological innovation does not have to be as big as creating a bluetooth connected car audio system, giant social media company, or the internet, but it has to serve the purpose of helping humanity improve and be more efficient in their work.

Automating freshservice ticket creation may be a little bit of time consuming and some people would rather create the ticket manually. But if you break down the time and the amount of tickets need to be created per day, automating it is still worth it!

References

--

--