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

The first string is the chatId followed by the name (if available). Then the symbol > means it’s an inbound message (from user to the chat bot).

There is also the Log node that produces a log string for every message that can be manipulated inside Node-RED (in case for example the log string should be sent to an external service).

October 5th, 2016|0 Comments

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


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 following the rest of the flow.

The Parse node analyze the incoming message and cab be configure to search for a pattern, it could be email, image, location, etc.
In that case it searches for a valid email: if the content of the incoming messages matches the pattern, the value is stored in the chat context and the output is redirected to the first output, otherwise the second output.

If the user’s input doesn’t match a valid email, a warning message is sent to the user and the flow restart from the node asking for the email.

If a valid email is found, it’s stored in the chat context (the name of the variable can be configured in the Parse node panel) and it’s available in the rest of the flow.

For example we can use it in the final Message node with a handlebars-like syntax with the text: “Thanks, from now on I’ll use {{myemail}} as your email”.

Or we can use it in a Function node:

To setup a Telegram bot, follow the tutorial.


September 16th, 2016|0 Comments

Setup a development 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


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

Grab the https address you get, something like https://123123.ngrok.io, this is the base url of the Facebook callback (update: now the Facebook web hook is mounted on the same address/port of Node-Red),


The callback is


Replace the hostname in bold with what you got above.
Start here
create a new Facebook app


Then click on “get started with Messenger”. Your Facebook app must be connected to a Facebook page, select one from the drop down menu (or create one if you don’t have any) and confirm, that will create a new access token


Copy this value as well as the app secret that you find in the “dashboard” section. Don’t close this page yet and open Node-Red.

Add a new Facebook Receiver node, then open the configuration of the node and fill up form with the access token and app secret you got before, then give a name to this configuration for your convenience and specify the verify token: this is an arbitrary string, you can put here whatever you like, just remember it you’ll need in the next step.


Save your node and switch back to the Facebook App configuration page, click on “Setup webhooks”


Copy the callback url you got before and the arbitrary verify token you put in Node-RED, don’t forget to check “messages”.

Click on “Verify and Save”, if you don’t get any error means Facebook is able to contact your Node-RED instance and everything is ok.
If you get an error means that you have used wrong parameters (access token, app secret, etc) or, for some reason, Facebook APIs cannot reach the your callback url.
To exclude the second option and be sure that your Node-RED instance works correctly, grab your ngrok url and open this address


If you get an “ok” then Node-RED is up and running.

The most is done, let’s test if it works: connect a RedBot Debug node  to the Facebook Receiver node, then open the Facebook page selected with the drop down (when the access token was generated), click on the “Message” button and type anything.

Something should be visible in the console. From now on everything is similar to what explained in the Telegram chat bot tutorial (most of the nodes in RedBot can be used for all platforms Telegram, Facebook, Slack so there’s no need to create platform specific flows).

Happy chatboting!



September 1st, 2016|5 Comments