Life of Apps

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. 

Danesh

Visit Pleb.in for apps developed by Danesh

No comments :

Post a Comment

Leave a Comment...