Stories

The Story of Alan: Resurrection of a Slack Bot

Kenan Kokic
Editor
Posted
Sep 18th 2019

Bots. They are the stuff that our nightmares of dystopian post-apocalyptic futures are made of. In games, they are what certain skill trees specialize in, but also who we like to imagine living and working in our computers to shift bits and store bytes. More realistically, however, bots are mostly useful helpers that can automate menial tasks and optimize everyday routines. One such bot by the name of Alan was recently revived to help us do just that.

Sometimes, certain internal projects have to take a backseat because people find it hard to invest the time to really make them valuable. This was the case for our old Slack bot, who hitherto had been lurking in the shadows, eagerly awaiting the day a developer would take the time to polish it and bring it back to life. Thus, a team of three of our developers, Bernat, Lovre and Marc, was assigned the task of rebuilding the bot from scratch with an updated technology stack:

  • MongoDB
  • NodeJS
  • TypeScript
  • Kubernetes
  • Rancher

“We had a bot some time ago, but it didn’t get a lot of attention because it was missing key features.”

Marc Slavec
— iOS Developer

The new functions needed for the bot were determined by an annual internal survey called ‘pulse check’ where people can give feedback on their general well-being and also report on any processes they think need improvement (or automatization). Having worked out the requirements for the bot from this feedback, the development began without further delay. Bernat provided some insights into the development process:

“Many people were not even aware of the existence of the old bot given that it primarily used to manage deployments. In order for Alan to become useful for the majority of people, common use cases needed to be implemented first, such as validating Mite entries and sending reminders for specific events. One of the challenges we faced was that almost every new functionality required access to a new API and the data it provides. However, we were able to reuse structures and code that had already been in place for many of those. Similarly, we wanted to take advantage of the huge amount of existing information in our Confluence system, which is why we decided to enhance Alan so it could answer freely phrased questions.

async function sendMessages(usersOnDuty: TSlackUser[]): Promise<void> {
 const botText = new BotTextLoader(‘sendKitchenDutyReminder’, defaultStrings);
 await botText.ready();
 usersOnDuty.forEach(user => {
   botApi.sendPrivateRichMessage(
     {
       text: botText.line(‘youAreOnDuty’, {
         peopleAlsoInDuty: `<@${usersOnDuty
           .filter(u => u.id !== user.id)
           .map(u => u.id)
           .join(‘>, <@’)}>`,
       }),
     },
     user.id
   );
 });
}

Whenever a user directly talks to it, the sentence is compared with some predefined patterns (using the very cool compromise library for JS). If the sentence matches a known pattern, Alan will answer accordingly or otherwise search confluence using the keywords of the sentence and provide links to those results. Of course, this is far from perfect, but often it works surprisingly well!”

One such instance of it working surprisingly well is when you can no longer contain your indignation at something:

Chat interaction with Alan

“Alan also has some functionality dedicated to its future improvement. Statistics for every command are internally tracked (to know which are being used the most) and users can propose new features and give feedback directly via Alan.
They are also occasionally reminded of things Alan can help with, specifically the functions they haven’t yet used. Also, it will remind everyone about upcoming holidays, suggest small exercises to prevent fatigue at work and even give a heads-up when some faulty Mite entries have been ignored for some time.”

In conclusion, Alan can take care of a lot of things now. And if it can already provide you with fundamental teachings of the holy scriptures, who’s to say where the limits are?

Chat interaction with Alan
You may also like
Stories
Angular Boot Camp
Stories
Internships 2019: A Summer at Parkside
Stories
Developing for accessibility