Hackathon#4 - @Edgar on steroids

Published on

Nov 17, 2016


For the fourth edition of our KNP Hackathon, Emma, Flo, Sylvain and Yann wanted to resurrect our Edgar bot on Slack. For the outsiders, we used for a long time Hipchat as our major communication interface and several KNPeers, mostly Flo, gave a lot of love to a bot named after our mascot Edgar. He had a lot of nice features and the search functionality for gifs was amazingly appropriate. After a common vote, we moved to Slack, and some of us were very disappointed with the Slackbots, too anonymous and Giphy sucks most of the time. IMG_0229 IMG_0233

So Sylvain had the really nice idea to boost Edgar on Slack.

For four days they worked on a new Edgar bot. As our goal was to go out of our comfort zone  during the Hackathon (using new technologies or languages), they chose to use Elixir/Erlang with the Hedwig Bot framework, Elastic Search & Ruby on Rails and voilà!

Here are some killer features they developed :

  • Bookmark feature, automatically indexing the content of any pasted URL in elasticsearch, and retrieving it back given some keywords
  • Today I learned : tweet about something you’ve learned on the KnpLabs account
  • Search for gif on giphy
  • Happy-Amandine-feature (propose themes for the KNPQuiz)
  • Bullshit responder : Give rational answers to touchy questions
  • Table flip : Edgar will flip a table out of rage … and will put it back after 10 sec.
  • Pug bomb (also for Amandine)
  • What’s the weather like in a specific city ?

Teamwork :

They divided the work in two teams : Flo and Sylvain worked on making Edgar work again with the latest Hedwig version and bringing back our beloved Edgar on Slack. As soon as the already existing features were back, they worked on the improvements :

  • Flo used Elastic Search to save the bookmarks, so that with some keywords we could ask Edgar to remember the associated bookmarks (which contain the keywords). They also used some native Erlang to make Edgar realize the table flip.
  • Emma and Yann made a Ruby client to search in Stack Overflow’s API. It brings the most accurate links based on the keywords you want to quiz about. It also look on RationalWiki and Skeptics Stack Exchange to look for rational answers to delicate questions, usually answered with woo woo. They used Ruby on Rails - and Emma likes Ruby :D

IMG_0239 Fancy technical details :

  • For the bot they used Hedwig library, written in Elixir. Some basic Erlang (for its concurrency model via messaging).
  • API (bullshit and quizzme) written with Ruby on Rails
  • Docker. Dockerize everything.

The erlang VM has the advantage to bring a very robust framework to build highly available applications. Its (unique?) process model makes it friendly to handle failures. The whole paradigm can be resumed in one sentence: “let it crash!”.

Compared to other usual languages, each process is isolated and has its own garbage collector: there is no such thing as “global, shared mutable state”, and “block-everything-garbage-collector-pass”.

Process communication is built-in the language and native helpers are provided to programmatically manipulate them: that’s what we used for example to implement the table flip.

Some process is sent a message after a decided time. When the process unstacks its mailbox, it decides what to do with the message. This asynchronous, non-blocking messaging mechanism is the reason why erlang is so unique, robust and able to answer the C10K problem!

Using processes to model a bot is ideal: you can take advantage of erlang supervisors to ensure a process is always alive (or recreated if killed). That makes the edgar bot almost invincible!

It was also really interesting to discover Ruby with a simple syntax which is pleasant to write and nice to understand. We can see this line “return unless text”, it’s prettier than a “if (that) { return that }” in php! Ruby is just quick to learn and easy to use.

Features : edgar_1 edgar_6 edgar_5 edgar_4 edgar_3 edgar_2A big KUDO to the team, we are all happy to welcome Edgar on Slack :D IMG_0294-ANIMATION

Written by

Eve Vinclair-Berkemeier
Eve Vinclair-Berkemeier

People Manager @ KNPLabs

Scrum Mistress - AFOL at home and at work :D Helping hand for client projects and internal organization of our teams at KNP.