In case you haven’t noticed, we are on the verge of a new era - the bot era!!
[Dramatic music in the background]
So what is a bot? If you’ve ever said
Hey Cortona, or
Alexa, then you have interacted with a bot. That bot received an input, returned an output - it woke you up, reminded you of something, sent an email, or ordered a new book from Amazon - and you if you’re lucky, a drone delivered it!
Now that we understand what a bot is, let’s start to see how we can write one. Any chat platform provide bots, and there are two ways for them to communicate:
Slack, Facebook Messenger, Skype, and Telegram all provide integrations with bots in one way or another, but in this post we will focus on Slack.
First, create a bot in your team. You can do it under
http://yourteam.slack.com/apps and create a custom bot integration.
Next you’ll need to start with a library. There’s something like a quadrillion libraries - PHP, NodeJS, Python, and couple in Go lang. For our purposes, we need an easy setup, listening to events and acting, understanding from the text what kind of task the user requires, and even more (cron tasks for reminders, incoming web hooks, DB layer, etc.). Sounds a bit daunting, no? You’re right!
When I started to write the first task, I saw that analyzing the text is more than just matching a function to the text. When there are a lot of tasks, the code will get long and messy. And that’s why I created Nuntius: a PHP framework based on Symfony components that helped me organize the code.
No and no. To make things easy, Nuntius does not use hooks or events dispatching to integrate with custom code. Instead, all of the integrations defined in a YML file.
hooks.local.yml we will add a custom task:
Our task will be located at
After implementing the task, we can start to code. So, what should this task do? Get a keyword, look for an image which relates to that keyword, and send it as an attachment to the message. When you are feeling down you could ask for a picture of a cute kitten to take away your sorrow.
We will need to search for pictures via a REST request. I found a nice service for that: pixabay. You’ll need to register and get an API key.
After acquiring the access token, we need to store it somewhere. The best place would be in the
credentials.local.yml which located under the
Let’s have a look at the code to get the picture:
What we need to do is to return the image URL, and that’s it! This the full code:
And this is the result:
Slack was kind and embedded the picture for us, but it’s not the best practice. Using attachments makes the message much more readable and gives us this:
The code is a bit more complex than the simple URL we returned:
Your mind was blown, I know. But what’s next? If you thought that this branch of development is left without any SAAS solution, you are wrong. Bots need to interact with people and require deep learning and natural language analysis. There are two famous players in the market (for now) - api.ai and wit.ai.
In a nutshell, they will give you informative object to interact with and train with deep learning.
No. Skynet is not around the corner, and HAL 9000 isn’t going to be in NASA’s new spaceships. This is just the beginning. Unless you are a big company like Apple, Google, or Facebook you probably won’t provide a solution like Siri and other bots.
Bots, as I can see it, will be another interaction with the product and can provide a simple way to get information like:
Don’t forget that QA was once done pretty much manually. Now, QA is automated but still need to be written and maintained. We might be killing one field but creating a new field.