/ RedBot
RedBot 0.19.4

Some recent changes in Slack API remove the bot scope from RTM API. That basically means the for all new applications it's not possible to use the RTM API and the old ones will stop working at the end of 2020.

The 0.19.4 will use the Event API which has the drawback of being not compatible with the Express stack of Node-RED, for this reason the web hook server is running in a separate Express app on a different port (that can be configured in the connection panel).

Follow the updated instruction here to upgrade to the new connection params.

/ RedBot
Twilio connector for RedBot

Create an account on Twilio (you'll need to verify a mobile number to proceed)

In order to create a SMS service you have to buy a Twilio phone number (any country is fine).

Twilio sends notification of incoming messages with a callback, use ngrok to expose your development instance of Node-RED to a public address, open a Terminal window and

ngrok http localhost:1880

You should get something like this

`

The address https://*.nkrok.io is the public URL that points back to your development machine.

First go to the Messaging services section and create a new service and pick up "Chatbot/Interactive 2-way" from the drop down menu.

Associate the Twilio number to this new service

Then check the

/ RedBot
Setting up a dev chatbot for Facebok and RedBot

This is a quick tutorial to setup a very simple chatbot with Facebook Messenger 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 node-red.

Setting up a Facebook Messenger is quite tricky since Facebook API talks to Red-Node via a https callback (a self signed certificate is not enough). It also requires a verify token that makes the whole process non linear and confusing.

We'll use ngrok to create a https tunnel for our local Node-RED instance. Install it, then open a shell window and run

ngrok http 127.0.0.1:1088

Grab the https address

/ RedBot
Store user response in RedBot

Working with chatbots it's sometimes useful to parse and store the user response somewhere.

In RedBot there's the chat context, it's a volatile memory space where it's possible to store variables related to the current chat user, for example consider this flow in which we ask the user to type in his email.

parse-email

The first Message node just sends out the question to the user "What is your email?" (always use a conversational tone with a chatbot and not cold robotic sentences like "Type your email").

Note that the Telegram Sender node has the track option enabled, that means that the chat flows will re-start from here: any answer from the chat user will be redirected to the output pin

/ RedBot
Logging conversations with RedBot

Running a chat bot requires some caring, in particular you're never done training it.

A good habit is to inspect the chat bot log searching for user sentences that were not recognized by the bot and then update the parsers Listen node, RiveScript node, etc) in order to support it.

Log filename

In RedBot every platform receiver can log the conversation to a file, it looks like

196520947 [Guido Bellomo] > Wed Oct 05 2016 12:08:45 GMT+0000 - /start
196520947 [Guido Bellomo] < Wed Oct 05 2016 12:08:45 GMT+0000 - Hi, this is GuidoneBot, here's what I can do for you:/help - you're already seeing this/where - tells where's Guido's house/cv
/ NodeRED
NetAtmo dashboard for Node-RED

There are few Node-RED nodes for the NetAtmo weather station, most of them return data of the sensors as time series.

I needed something simpler for my chatbot, a way to get fetch all current values from all sensors, something like this

{
  "temperature": 27.5,
  "co2": 246,
  "humidity": 60,
  "noise": 38,
  "pressure": 1009.5,
  "pressureTrend": "stable",
  "externalTemperature": 30,
  "externalHumidity": 51,
  "externalTemperatureTrend": "stable"
}

So I created this node-red-contrib-netatmo-dashboard.

To install

cd $HOME/.node-red
npm install node-red-contrib-netatmo-dashboard

See Netatmo Connect to get an API key.

/ RedBot
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

node-red

The next step is to create a chat bot, I recommend 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

/ RedBot
RedBot, a chatbot framework for Node-RED
RedBot_logo

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 tutorial to setup a Telegram chat bot and some blog posts about chatbots.

/ JavaScript
Middleware in NodeJS

Talking with a collegue of mine I came up with this solution about organizing the code in NodeJS+Express using middlewares.
Consider this example in which we have a simple page that performs two queries and shows the result in a template.
Since everything is asynchronous, we chain in two queries in this way

app.get('/mypage', function(req,res,next) { 
  sequelize.search(query1)
    .on('success', function(res_query1) { 
      sequelize.search(query2)
        .on('success', function(res_query2) { 
          res.render('my_template', {
            query1: res_query1, query2: res_query2
           });
        });
    });   
});

There's nothing wrong with this, the only problem is that as long as the page gets new functionalities, you keep nesting queries and asyncronous callback.
The resulting code could become unreadable after

/ JavaScript
Tiny little JavaScript polling object

Few days I came across this situation where I had to check, at predefined interval, against a remote server for some conditions. So just for not having the setTimeout and setInterval ids hanging around my code, I wrapped everything in a small JavaScript object Poller.

It's pretty simple: just configure any number of intervals, a callback in case of success, a callback in case of failure, and the function that checks the server

var poller = new Poller();
poller.intervals([1000,5000,10000])
  .checkback(function(callback) {
    // could be anything asynchronous
    $.getJSON('/is/server/ready', function(response) {
      if (response.ready) {
        callback(true);
      } else { 
        callback(false);
      }
    })
    .callback(function() {
      // checkback succeded and the end of one interval
      // stops the poller and callback
      console.