blog.pleb.in

Life of Apps

Showing posts with label chatbot. Show all posts
Showing posts with label chatbot. Show all posts

First Look at Google's API.AI

API.AI is a chatbot development platform bought by Google last September. This is one of the prominent chatbot development platforms along with Facebook's Wit.ai and Microsoft's BotFramework. What I found unique about API.AI is that you can build a basic bot without writing any code. All the development happens within the browser and you can test it there.

So, what does it take to build a bot in API.AI?

Here are the key concepts that you need to build a bot in API.AI.

Intents: Intents are actions that perform a task and are defining them is usually the first step to build a bot. If I were to build a bot that gives me recommendations on tourist attractions. I would define intents such as recommendations for beaches, hill stations etc. So, a typical conversation could be:

User: show me some beaches in India
Bot: Here are some nice beaches - (may show pictures)

Entities: From the user's sentence above, beach would be identified as an entity. Hill station could be another. These would then be abstracted as an entity type called tourist attraction. This makes the conversation extensible as more entities and corresponding intents can be added. When the user requests a recommendation on beaches, the bot understands beach as a type of tourist attraction entity and invokes the beach recommendation intent. Again, no code is required to do this, just point and click to link the two.

Training: Once the intents and entities are defined, the bot is to be trained. This can be done through the test console within the browser's "console", which is the DEV environment. Each conversation is logged, it can be reviewed and the erroneous responses corrected. Sometimes, the bots can behave pretty poorly. For instance,

User: show me hills in India (instead of hill stations)
Bot: I am sorry I did not understand that

To make the bot respond, hills need to be included in the synonym for the hill stations entity. All such synonyms need to be entered to ensure that the bot responds correctly. Once added, repeat the training and correct the errors till there are none.

Integration: Once the bot is ready, it can be integrated with Facebook Messenger, Skype, Twitter, Slack, Google Assistant and many other platforms. Before making the bot public, the integrations make it easy to test the bot on the go through a mobile device.

Prebuilt Agents: API.AI provides prebuilt agents that range from engaging in small talk to helping book restaurants, flights and control home appliances. These agents come with prebuilt intents and entities that you can use to start from instead of building from scratch.

Fulfillment: In order to extend the functionality of bots such as invoking external APIs to check weather, make hotel bookings etc., API.ai provides integration capabilities through web hooks. Web hooks can point to external endpoints such as third party APIs or your own API hosted elsewhere.

The bot can be hosted on API.AI itself or any other platform with support for node.js. The interaction with the bot could be using HTTP RESTful calls or through one of the many languages that are supported through the SDKs.

Overall, I am impressed with the ease of use of the API.AI platform and will continue spending time with it in building a bot that can keep me amused :) 

Building Bots with Bottr

It has been a while since I posted to this blog. What have I been up to? I have been looking at some chatbot frameworks, Bottr being one of them. Bottr is a simple JavaScript framework that allows you to quickly build a chatbot. It runs on node.js and can be tested on your local desktop.

Bottr is available as a npm module. After installing the module, you can use it like so

var Bottr = require('bottr');
var BottrApp = require('bottr-app');
var bot = new Bottr.Bot();
//BottrApp for local server
bot.use(new BottrApp());

It has functions to listen to messages received and do some processing. The function below will fire on each message and when done with processing, will invoke the next function using the next() function.

bot.on('message_received', function(message, session, next) {
  //function code here
  //invoke other handlers to process the message
  next();
}

It also has functions that can listen to specific message types/patterns and respond. The function below listens to all messages and echoes them back using the send function. The listen function at the end starts the bot to listen.

bot.hears([/.+/], function(message, session) {
      // Echo the user's message 
      session.send(message.text)
});
bot.listen();

The framework's documentation provides clear instructions on deploying the code in Heroku and integrating with Facebook Messenger. Within a matter of minutes, I was available to deploy the code and use it in Facebook Messenger. However, as the framework is relatively new, the documentation is not exhaustive. This makes it a bit tough to use the framework for building complex bots. As the framework gains popularity and more people start using it, hopefully the documentation will also mature. And we can see more bots built using Bottr.