The age of bots and backend as a service
Or, How I coded a knowledge sharing bot in 5 hours flat
Our team has a very high appetite for knowledge — each of us consumes a wide range of articles and videos. The more we read, the more we like to share it with others on the team. And since slack is the de-facto tool for office communication, we share everything on slack, in various channels.
This is awesome for sharing, but terrible for going back and finding something. Or for keeping track of who is sharing what.
Enter Regina — the slackbot that listens to all conversations, and captures anything that’s a web Url. This Url is then saved in a database and exposed as an API for search.
Building the bot
I used this excellent tutorial on scotch.io to get started on my bot. I code-named it regina and extended it with a few small features — crack star wars jokes, listen to any Urls being shared, etc. Regina would listen to everything on all channels, and the moment someone shared a link, get activated.
Time spect: 1.5 hours
Look Ma, no backend
But what happens when Regina detects a link? We needed a way to store it, along with who shared it, in what channel and preferably also detect what kind of article it is.
This was supposed to a quick hack and an internal tool at best. I didn’t want to get into this business of writing a backend which would connect to a db and save the links. However, I wanted it to be a production quality hack, just in case we extended it in future.
I created an app in Stamplay. Then I created a model called knowledge-object. Each knowledge-object had title, content, url,thumbnail, tags, channel, sender. I like to view all my data in this manner, as it give me flexibility to add various parameters and also the certainity of what those parameters would be.
Modelling the information around us as knowledge objects has proven to be a very extensible and reliable thing for me. But that is a matter of a separate post, some time soon.
Now Regina had an awesome REST based api, where she could send links, each time they were posted on slack.
Time spent: 15 minutes
Tagging at the speed of thought
I mentioned tagging, remember. How do you auto-tag articles shared on slack, without any human involvement. You use Alchemy API. Alchemy is an awesome API for quick AI analysis on your content, and finding out subject, author, tags, etc. It has a nifty nodejs code sample that you can rapidly repurpose into an API.
I created an API endpoint that received URLs and retuned a JSON structure with tags and other metadata.
Time spent: 2 hours
Stamplay is awesome because it allows you to wire a complex application simply by wiring individual pieces together and setting tasks based on triggers.
In any normal development environment, this would take hours of code-test-build-code cycles. Here, I simply did the following -
- I wrote a small codeblock, that would receive an id and url, hit the Alchemy API above, and once it got the response, would send a post update to the database with the tags and other metadata.
- I set up a task where each time a knowledge-object was created, the codeblock would get activated with the id of that object and the url.
- Once Alchemy did its job, my knowledge-object would get updated.
This allowed me to keep everything de-coupled and independent of each other. If my alchemy API went down for some reason, it still meant that my bot could keep saving the links into the Stamplay backend.
Time spent: 1 hour
The age of smart bots
To make my bot look smart, I did one final piece of hack on Stamplay. I set up a reverse trigger that would post back the tags from alchemy into the slack channel. This was interesting as it stumped people, when they heard the bot chime back at them about what that link was talking about.
Time spent: 15 minutes
Finally, what good is all this data if it isn’t exposed in a nice UI on the front-end. People should be able to search based on sender, tags, channels or see a timeline of what was posted when.
Stamplay exposes all objects in a very nice REST based API that can be queried by parameters. It has inbuilt pagination, and the structure is JSON.
This makes writing a simple front-end in Angular or any other technology a piece of cake. All one needs to do is consume this API on the frontend and render it as html.
Thus, you can have a fairly complex, end to end solution by wiring existing technologies and a service like stamplay at the backend. It allows you to get from idea to MVP in over a few hours (literally) with very little investment in code.
You can run this in production environment, observe user behaviour, fine tune your product, raise money, literally anything you want.
The age of bots and backend as a service has truly arrived.