I've been playing a lot with bots lately, and recently had a great opportunity to help others play, too.
It was part of the Future.Today conference in New York City last month. Futurist and organizer Amy Webb planned deep discussions about artificial intelligence and human-machine interactions on the main stage. In a side room, she wanted to give the audience tactile bot experiences — and asked me to help. Could I create a "Build-A-Bot" workshop?
The idea was to get conference-goers building chatbots over lunch -- making them easily, without code, and in a way people could "take" their bots home to work on further.
We ended up making nearly 100.
My initial vision was ...
- Have each person build an "Ask Me Anything" bot about themselves or something they knew really well, such as a favorite movie or book.
- Make it super-easy to build and grow the bot's "corpus," or body of knowledge.
- Make each bot shareable so others can use it.
After some tinkering and investigation, here's how it came together:
The Bot Engine
I quickly settled on Botkit for the chatbot brain — the part that listens for questions and responds with answers. Botkit is open-source code with super clear documentation and the ability to work with Slack, Facebook and other chat platforms.
I spun up a virtual server on Amazon's Web Services platform and installed Botkit there. This would be my bot server.
The Chat Room
The bot and the people needed a place to chat together. I considered using Facebook Messenger, but it turns out that bots you make there can't be used by anyone else until Facebook reviews and approves each one. No thanks.
Instead, I switched to the "programmable chat" service from Twilio.
Using tutorials and example code from both Twilio and Botkit, I got a chat server working on a second Amazon Web Service computer.
I made the bot a permanent resident of any room, or channel, created on the chat server.
The knowledge for each person's bot, I thought, could live in a Google spreadsheet with a "question" column and an "answer" column. I set one up and used the still-awesome Tabletop.js to pull the spreadsheet data into Botkit.
I then programmed Botkit so that any time someone posted a message into a chat room, the bot spun through the "question" column looking for a match. Say a person's question to my bot was "What's John's favorite color?" In the question column of the spreadsheet I had "favorite color" — which is a match. The bot then replied with the text in the adjacent answer column: "It's purple!"
Handling Many Botmakers
We expected dozens of people would be making individual bots. I needed a way for each person's bot to respond with the right corpus (and therefore the right answers).
In the end, I decided that each person would give their bot a short name — like "johnbot." That name would actually become the name of a chat room, or "channel" in Twilio parlance
I then created a MongoDB database and stored for each bot the bot name, the corresponding chat channel's Twillio ID, the Google spreadsheet key for the bot's corpus and contents of that corpus read from that spreadsheet.
So when someone posts a message in a chat channel, the bot server detects the channel ID, checks the database for the corresponding corpus, pulls in the corpus data, scans the corpus questions and responds appropriately — all in an instant.
Finally, I put the bot name into a web address people could bookmark or share. Visiting that URL automatically puts the user into the proper chat channel.
One hiccup was that Twilio requires any bots to use HTTPS — secure communications you may know by your browser's little green lock. So my bot server had to use HTTPS, which meant setting up certificates and a bunch of server wizardry I've never built before.
Fortunately, the good people at LetsEncrypt are working to make it easy and free to make a secure website. My web server is using Nodejs and Express, so I used the Nodejs library letsencrypt-express, which made the whole process painless.
You can give my bot a try. Here are some others:
I also wired the bot server to Wit.ai to demonstrate some pretty cool ways bots can use artificial intelligence to recognize the type of question being asked, the intent of the person asking it and even some of the details from each question. (You can see this in action if you go to my bot and ask "What's the day after tomorrow?")
Botkit makes it incredibly straightforward to link up Wit.ai and several other machine-learning services.
All in all, the system worked perfectly for eight one-hour workshops over two days.
First I'm hoping to move the bot system and the chat system onto Amazon's Lambda service. That means that instead of running (and paying for) two servers waiting 24/7 for someone to ask a question in a chat room, the Lambda system will run only for the few moments it takes to field a question and respond — making the system essentially free(!)
I also want to play with Wit.ai more and make my bots smarter at handling questions — moving beyond simple pattern matching and into true computer smarts
Making the whole system more immune to human error will be important, too. Currently, a misplaced bracket in a corpus will confuse the bot
And I plan to clean up my code so I can open-source it for others to use. I whipped this whole system together in just a few weeks, and if you were to see my repo now, that'd be pretty obvious. :-)
Photo: Future Today Summit