Setup a simple Telegram chatbot with RedBot

This is a quick tutorial to setup a very simple chatbot with Telegram and RedBot.

First of all install Node-RED

sudo npm install -g node-red

Then open the user data directory $HOME/.node-red and install the package

cd $HOME/.node-red
npm install node-red-contrib-chatbot

Then run


The next step is to create a chat bot, I reccomend to use Telegram since the setup it’s easier ( Telegram allows polling to receive messages, Facebook requires a https callback and a valid https certificate).
Telegram is really coherent and you have to use a chat bot to create a chatbot. Connect to @BotFather and type /newbot, then in the next two steps give the bot a name and username (this will be the real unique address of your chatbot), you’ll get something like this for @my_new_chat_bot


Copy and paste the access token. For more information read here.

Then open your Node-RED and add a Telegram Receiver, in the configuration panel, add a new bot and paste the token


Now add a Message node and connect to the Telegram Receiver


Finally add a Telegram Sender node, don’t forget to select in the configuration panel the same bot of the Telegram Receiver, this should be the final layout


Now you have a useful bot that answers “Hi there!” to any received message.

Receving the same answers is not very useful, we can introduce Command node: it will pass through the output only if the input message is “hi”:


In this way it’s possible to trigger different actions with different commands, read more about Telegram commands here.

August 25th, 2016|2 Comments

RedBot, a chatbot framework for Node-RED


RedBot is a Node-RED framework to create chatbots for Telegram, Facebook and Slack. Almost no coding skills required.


Node-RED is a tool for wiring together hardware devices, APIs and online services in new and interesting ways.


With RedBot it’s possible to easily create chatbots just wiring together basic blocks like message, audio, location, etc. and interact with the Node-RED ecosystem. If you have particular need, you can do it by yourself in NodeJS, it’s all open source!

RedBot is able to understand user’s input using a simple token-based detector or more advanced language interaction like RiveScript.

RedBot node palette


The GitHub repository, a quick tuorial to setup a Telegram chat bot and some blog posts about chatbots.

August 23rd, 2016|0 Comments

Inizialization of Backbone models and variables passed as reference

There are some apparently strange behaviours when working with Backbone models and properties.
Try this

var MyClass = Backbone.Model.extend({
  counter: {
    value: 1
  getCounter: function() {
    return this.counter.value;
  incCounter: function() {
    return this.counter.value += 1;

var myClass1 = new MyClass();
var myClass2 =  new MyClass();

myClass1.getCounter(); // = 1
myClass1.incCounter(); // = 2
myClass1.getCounter(); // = 2, everything is fine so far
myClass2.getCounter(); // = 2 WTF!

Javascript is a dynamic language, the class above is extended at runtime from the Backbone model class, in particular the property counter is set to an hash with just the key “value”. The point is that hashes (like arrays) are passed by reference, so MyClass in the first line is extended with a reference to that hash and the method incCounter() basically increments every time the same hash even in different instances of the class.

This can easily be solved with a proper initialization method

var MyClass = Backbone.Model.extend({
  initialize: function() {
    this.counter = {
      value: 1
  getCounter: function() {
    return this.counter.value;
  incCounter: function() {
    return this.counter.value += 1;
July 4th, 2014|3 Comments