<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[JavascriptJedi]]></title><description><![CDATA[JavascriptJedi]]></description><link>https://www.javascript-jedi.com/</link><image><url>https://www.javascript-jedi.com/favicon.png</url><title>JavascriptJedi</title><link>https://www.javascript-jedi.com/</link></image><generator>Ghost 4.47</generator><lastBuildDate>Tue, 19 Jul 2022 07:26:21 GMT</lastBuildDate><atom:link href="https://www.javascript-jedi.com/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[RedBot 1.0]]></title><description><![CDATA[New release for RedBot: Mission Control, a persistance layer and pluggable control panel]]></description><link>https://www.javascript-jedi.com/redbot-1-0/</link><guid isPermaLink="false">62d54bb0e444030001ecdaf6</guid><category><![CDATA[RedBot]]></category><dc:creator><![CDATA[Guidone]]></dc:creator><pubDate>Mon, 18 Jul 2022 15:26:30 GMT</pubDate><content:encoded><![CDATA[<p>A new version of <strong>RedBot</strong> was released today, the biggest change is <strong>Mission Control</strong>: a persistance layer and pluggable control panel for <strong>RedBot&apos;s </strong>bots. </p><p>Key features:</p><ul><li>Storage for inbound and outbound messages (<em>SQLite</em>)</li><li>Chatbot user management and persisted chat context (<em>SQLite</em>)</li><li>Admins management with multiple roles</li><li>Basic <em>Content Management System</em> with custom fields</li><li>Chatbot simulator</li><li><em>GraphQL</em> endpoint to access <em>SQLite</em> database</li><li>New <em>Node-RED</em> nodes (<em>MC GraphQL</em>, <em>MC Simulator</em>, etc)</li><li>Plugins repository for additional features</li><li>Pluggable and open architecture</li><li><em>Docker</em> image</li></ul><div class="kg-card kg-callout-card kg-callout-card-green"><div class="kg-callout-emoji">&#x2757;</div><div class="kg-callout-text"><strong>Mission Control</strong> is not enabled by default to ensure maximum retro-compatibility. Run <em>Node-RED</em> with the env variable REDBOT_ENABLE_MISSION_CONTROL (i.e. <code>REDBOT_ENABLE_MISSION_CONTROL=true node-red -u /my-node-red-project</code>)</div></div><h2 id="user-management">User Management</h2><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://www.javascript-jedi.com/content/images/2022/07/user.gif" class="kg-image" alt loading="lazy" width="1200" height="694"><figcaption>Users management</figcaption></figure><p>When enabled, the bot is persisting bot&apos;s user information (fist name, last name, language, chat context, etc) that can be inferred or extracted from the chat platforms. All users can be searched, modified or deleted from <strong>Mission Control </strong>(i.e. change user&apos;s detail or inspecting the current chat context).</p><p>Each new user receives a unique <code>userId</code> which can be used to identify the user within the chatbot indipendently from the chat platform (i.e. the same user can access the bot with multiple platforms, there&apos;s a 1-to-many relation between <em>userId </em>and <em>chatId</em>).</p><p>A custom JSON <code>payload</code> field can be used to store anything related to a user, it can be modified from <strong>Mission Control</strong> or - programmatically - using the <code>MC GraphQL node</code> in <em>Node-RED</em>.</p><h2 id="messages-storage">Messages Storage</h2><p>Messages are automatically stored in <em>SQLite</em>, it&apos;s now possible to inspect messages filtering for <em>chatId</em>, <em>platform</em>, <em>userId</em> or <em>chatId</em>.</p><h2 id="admins">Admins</h2><p>Access can be granted to an unlimited number of admins with fine grain permissions.</p><p>Every feature has it own set of permissions that can be added individually to each admin. <br>The <strong>Mission Control</strong>&apos;s panel can handle multiple chatbots, admins can be assigned to all or specific chatbots.</p><h2 id="chatbot-simulator">Chatbot Simulator</h2><p>It&apos;s now possible to simulate the bot with the chatbot simulator inside <strong>Mission Control</strong>, it&apos;s even possible to impersonate an existing user to investigate on production problems.</p><p>Implementing the simulator is easy, just drop the <code>MC Simulator nodes</code> in the flow like normal senders and receivers.</p><h2 id="graphql-support">GraphQL support</h2><p><em>SQLite</em> database can be accessed with <strong>GraphQL</strong>: chabots can read/write data using <code>MC GraphQL node</code>, admins can read/write data using <strong>Mission Control</strong>&apos;s panel, third party systems can read/write data using the <code>/graphql</code> endpoint (with a security token).</p><p>These are the available entities<br><br><strong>users</strong> chatbot&apos;s user<br><strong>messages</strong> the inbound and outbound messages<br><strong>content</strong> the post-like contents<br><strong>records</strong> user-related entities (i.e. orders, invoices, etc)</p><h2 id="content-management-system">Content Management System </h2><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://www.javascript-jedi.com/content/images/2022/07/content.gif" class="kg-image" alt loading="lazy" width="1200" height="773"><figcaption>Content Management System</figcaption></figure><p>It&apos;s a simple post-like content management system with some basic fields (i.e. <em>title</em>, <em>body</em>, <em>category</em>, <em>language</em>, etc) plus</p><p><strong>slug</strong> it&apos;s an arbitrary id to identify a content. For example it&apos;s possible to fetch the content with <code>MC Content node</code> using the slug instead of the numeric id or it&apos;s possible to use it to identify the same content in different languages (multi-language support)<br><strong>custom fields</strong> a list of structured and typed fields for a content (string, number, etc)<br><strong>payload</strong> a custom JSON field that can contain anything<br><strong>namespace</strong> contents are grouped by namespace, the default one is <code>content</code>, but it&apos;s possible to develop plugins using different namespaces and reusing the same UI, the <em>Mission Control</em>&apos;s CMS can be used to store anything</p><h2 id="new-node-red-nodes">New Node-RED nodes</h2><p>A bunch of new nodes are available to use the power of <strong>Mission Control</strong>:</p><p><strong>MC Content </strong>to easily fetch content from <em>Mission Control</em>&apos;s CMS using the slug or the id<br><strong>MC GraphQL</strong> to explore and persist data on <em>SQLite</em> using simple <em>GraphQL</em> queries<br><strong>MC Simulator sender / receiver</strong> add these nodes to simple add support for the simulator in <em>Mission Control</em><br><strong>MC User Payload</strong> to store and persist any kind of json payload into the user&apos;s space in <em>SQLite</em></p><h2 id="plugins">Plugins</h2><p>This is actually the most important feature. <strong>Mission Control</strong> has an open architecture and it&apos;s pluggable: every feature is a plugin, new and optional features can just be plugged into the control panel.</p><p>Some simple plugins are already available in the <em>Plugins Store</em> like <strong>Send Direct Message</strong>, <strong>Commands</strong>, <strong>Knowledge Base</strong>, <strong>Authorization</strong> and more to come in the future.</p><p>Since <strong>RedBot</strong> is open source, everyone can develop custom plugins using <em>React</em> and <em>RSuite</em> (docs for this is still not available).</p><h2 id="docker-image">Docker image</h2><p>There&apos;s an <a href="https://hub.docker.com/repository/docker/guidone/redbot">official Docker image for RedBot</a>, just run it to quickly test <strong>RedBot</strong> in a local environment or to easily deploy in production.</p><p>Just run (<strong>Mission Control</strong> is not enabled by default)</p><pre><code class="language-bash"> docker run -d -p 1880:1880 \
   -e REDBOT_ENABLE_MISSION_CONTROL=true \
   guidone/redbot</code></pre>]]></content:encoded></item><item><title><![CDATA[Authenticating Node-RED web sockets]]></title><description><![CDATA[Using Node-RED web sockets in a secured server]]></description><link>https://www.javascript-jedi.com/authenticating-node-red-web-sockets/</link><guid isPermaLink="false">6262d01c1b67610001ed09c6</guid><category><![CDATA[Node-RED]]></category><dc:creator><![CDATA[Guidone]]></dc:creator><pubDate>Fri, 22 Apr 2022 16:15:10 GMT</pubDate><content:encoded><![CDATA[<p>While developing extension nodes for Node-RED is sometimes useful to re-use the built-in Web Sockets channel (<em>/comms</em>) to provide two ways communication between the extension and Node-RED.</p><p>Everything works fine until the moment we put everything in production and we secure the Node-RED server, <strong>the web socket connection remains pending</strong>. That&apos;s because the <em>Web Socket</em> connection is initiated through the <em>http://</em> protocol (which requires authentication) and then upgraded to <em>ws://</em>. </p><p>I&apos;ve found the solution after digging a little in the Node-RED code (since the lack of documentation on this topic)</p><!--kg-card-begin: markdown--><pre><code class="language-javascript">import Sockette from &apos;sockette&apos;;
const ws = new Sockette(
  &apos;http://localhost:1880/comms&apos;, // the Node-RED server  
  {
    // ...
    onopen: () =&gt; {
      const raw = localStorage.getItem(&apos;auth-tokens&apos;);
      let json;
      try {
        json = JSON.parse(raw)
      } catch(e) {
        // do nothing
      }
      if (json != null &amp;&amp; !_.isEmpty(json.access_token)) {
        ws.send(`{&quot;auth&quot;:&quot;${json.access_token}&quot;}`);
      }
    }
  }
);
</code></pre>
<!--kg-card-end: markdown--><p>Basically the trick is to <strong>use the same Node-RED authentication token to authenticate the web socket connection</strong>.</p>]]></content:encoded></item><item><title><![CDATA[RedBot 0.19.4]]></title><description><![CDATA[<p>Some recent changes in <em>Slack API</em> remove the <code>bot</code> scope from <em>RTM API</em>. That basically means the for all new applications it&apos;s not possible to use the <em>RTM API</em> and the old ones will stop working at the end of 2020.</p><p>The <em>0.19.4</em> will use the</p>]]></description><link>https://www.javascript-jedi.com/redbot-0-19-4/</link><guid isPermaLink="false">5f0db01a1a680f0b8c2f07ba</guid><category><![CDATA[RedBot]]></category><dc:creator><![CDATA[Guidone]]></dc:creator><pubDate>Tue, 14 Jul 2020 13:18:28 GMT</pubDate><content:encoded><![CDATA[<p>Some recent changes in <em>Slack API</em> remove the <code>bot</code> scope from <em>RTM API</em>. That basically means the for all new applications it&apos;s not possible to use the <em>RTM API</em> and the old ones will stop working at the end of 2020.</p><p>The <em>0.19.4</em> will use the <em>Event API</em> which has the drawback of being not compatible with the <em>Express</em> stack of <strong>Node-RED</strong>, for this reason the web hook server is running in a separate <em>Express</em> app on a different port (that can be configured in the connection panel).</p><p>Follow the updated instruction <a href="https://github.com/guidone/node-red-contrib-chatbot/wiki/Slack-Receiver-node">here</a> to upgrade to the new connection params.</p>]]></content:encoded></item><item><title><![CDATA[Twilio connector for RedBot]]></title><description><![CDATA[How to setup a simple SMS responder with RedBot and Twilio]]></description><link>https://www.javascript-jedi.com/twilio-connector-for-redbot/</link><guid isPermaLink="false">5b92968ac2870138fe08009e</guid><category><![CDATA[RedBot]]></category><dc:creator><![CDATA[Guidone]]></dc:creator><pubDate>Mon, 10 Sep 2018 17:44:00 GMT</pubDate><content:encoded><![CDATA[<p>Create an <a href="https://www.twilio.com/try-twilio">account on Twilio</a> (you&apos;ll need to verify a mobile number to proceed)</p><p>In order to create a SMS service you have to buy a <strong>Twilio</strong> phone number (any country is fine).</p><p><strong>Twilio</strong> sends notification of incoming messages with a callback, use <a href="https://ngrok.com/">ngrok</a> to expose your development instance of <strong>Node-RED</strong> to a public address, open a <strong>Terminal</strong> window and</p><pre><code>ngrok http localhost:1880</code></pre><p>You should get something like this</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://www.javascript-jedi.com/content/images/2018/09/fb-tutorial-2-1-2.png" class="kg-image" alt loading="lazy"><figcaption>`</figcaption></figure><p>The address <em>https://*.nkrok.io</em> is the public URL that points back to your development machine.</p><p>First go to the <a href="https://www.twilio.com/console/sms/services">Messaging services</a> section and create a new service and pick up <em>&quot;Chatbot/Interactive 2-way&quot;</em> from the drop down menu.</p><p>Associate the <strong>Twilio</strong> number to this new service</p><figure class="kg-card kg-image-card"><img src="https://www.javascript-jedi.com/content/images/2018/09/Screen-Shot-on-2018-09-07-at-19_44_36.png" class="kg-image" alt loading="lazy"></figure><p>Then check the <em>&quot;Process inbound message&quot;</em> and fill it using the <strong>ngrok</strong> address from the <strong>Terminal</strong> window, it should be something like</p><pre><code>https://&lt;my-ngrok-address&gt;.ngrok.io/redbot/twilio</code></pre><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://www.javascript-jedi.com/content/images/2018/09/Screen-Shot-on-2018-09-07-at-19_46_56.png" class="kg-image" alt loading="lazy"><figcaption>Set the callback for inbound messages</figcaption></figure><p>Now switch to <strong>RedBot</strong> and create a connection for the <code>Twilio Sender node</code>: the <strong>Accound SID </strong>and <strong>Auth Token</strong> will be requested, you&apos;ll find both in the <strong>Twilio</strong>&apos;s <em>Dashboard</em></p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://www.javascript-jedi.com/content/images/2018/09/Screen-Shot-on-2018-09-07-at-19_54_41.png" class="kg-image" alt loading="lazy"><figcaption>Twilio&apos;s Dashboard</figcaption></figure><p>Also don&apos;t forget to fill the <strong>Sender Name</strong> (the <strong>Twilio</strong> number you bought in the first step).</p><p>To verify that everything is working fine, try a simple flow to send out an SMS</p><figure class="kg-card kg-image-card"><img src="https://www.javascript-jedi.com/content/images/2018/09/Screen-Shot-on-2018-09-07-at-19_59_50.png" class="kg-image" alt loading="lazy"></figure><p>In the <a href="https://github.com/guidone/node-red-contrib-chatbot/wiki/Conversation-node">Conversation node</a> set the <strong>chatId</strong> with the recipient&apos;s phone number (complete with the international prefix). Be sure that the international prefix of recipient phone number is included in the <a href="https://www.twilio.com/console/sms/settings/geo-permissions">Geographic Permissions</a>.</p>]]></content:encoded></item><item><title><![CDATA[Setting up a dev chatbot for Facebok and RedBot]]></title><description><![CDATA[This is a quick tutorial to setup a very simple chatbot with Facebook Messenger and RedBot]]></description><link>https://www.javascript-jedi.com/setup-a-development-chatbot-for-facebok-and-redbot/</link><guid isPermaLink="false">5b8bb7c8c2870138fe080069</guid><category><![CDATA[RedBot]]></category><dc:creator><![CDATA[Guidone]]></dc:creator><pubDate>Fri, 31 Aug 2018 11:50:16 GMT</pubDate><media:content url="https://www.javascript-jedi.com/content/images/2018/09/fb-tutorial-2-1-1.png" medium="image"/><content:encoded><![CDATA[<img src="https://www.javascript-jedi.com/content/images/2018/09/fb-tutorial-2-1-1.png" alt="Setting up a dev chatbot for Facebok and RedBot"><p>This is a quick tutorial to setup a very simple chatbot with <strong>Facebook Messenger</strong> and <a href="https://github.com/guidone/node-red-contrib-chatbot">RedBot</a>.</p><p>First of all install <a href="http://nodered.org/docs/getting-started/installation">Node-RED</a></p><pre><code>sudo npm install -g node-red</code></pre><p>Then open the user data directory <em>$HOME/.node-red</em> and install the package</p><pre><code>cd $HOME/.node-red npm install node-red-contrib-chatbot</code></pre><p>Then run <code>node-red</code>.</p><p>Setting up a <strong>Facebook Messenger</strong> is quite tricky since <strong>Facebook API</strong> talks to <strong>Red-Node</strong> 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.</p><p>We&apos;ll use <strong>ngrok</strong> to create a https tunnel for our local Node-RED instance. <a href="https://ngrok.com/download">Install it</a>, then open a shell window and run</p><pre><code>ngrok http 127.0.0.1:1088</code></pre><p>Grab the https address you get, something like <strong><a href="https://123123.ngrok.io">https://123123.ngrok.io</a></strong>, this is the base url of the Facebook callback</p><figure class="kg-card kg-image-card"><img src="https://www.javascript-jedi.com/content/images/2018/09/fb-tutorial-2-1.png" class="kg-image" alt="Setting up a dev chatbot for Facebok and RedBot" loading="lazy"></figure><p>The callback is</p><p>http://<strong>youraddress.ngrok.io</strong>/redbot/facebook</p><p>Replace the hostname in bold with what you got above.<br><a href="https://developers.facebook.com/">Start here</a> to create a new Facebook app</p><figure class="kg-card kg-image-card"><img src="https://www.javascript-jedi.com/content/images/2018/09/fb-tutorial-1-1.png" class="kg-image" alt="Setting up a dev chatbot for Facebok and RedBot" loading="lazy"></figure><p>Then click on <em>&quot;get started with Messenger&quot;</em>. Your Facebook app must be connected to a <strong>Facebook page</strong>, select one from the drop down menu (or create one if you don&apos;t have any) and confirm, that will create a new <strong>access token</strong></p><figure class="kg-card kg-image-card"><img src="https://www.javascript-jedi.com/content/images/2018/09/fb-tutorial-3.png" class="kg-image" alt="Setting up a dev chatbot for Facebok and RedBot" loading="lazy"></figure><p>Copy this value as well as the <strong>app secret</strong> that you find in the <em>&quot;dashboard&quot;</em> section. Don&apos;t close this page yet and open <strong>Node-Red</strong>.</p><p>Add a new <code>Facebook Receiver</code> node, then open the configuration of the node and fill up form with the <strong>access token</strong> and <strong>app secret</strong> you got before, then give a name to this configuration for your convenience and specify the <strong>verify token</strong>: this is an arbitrary string, you can put here whatever you like, just remember it you&apos;ll need in the next step.</p><figure class="kg-card kg-image-card"><img src="https://www.javascript-jedi.com/content/images/2018/09/fb-tutorial-5.png" class="kg-image" alt="Setting up a dev chatbot for Facebok and RedBot" loading="lazy"></figure><p>Save your node and switch back to the <strong>Facebook App</strong> configuration page, click on <em>&quot;Setup webhooks&quot;</em></p><figure class="kg-card kg-image-card"><img src="https://www.javascript-jedi.com/content/images/2018/09/fb-tutorial-4.png" class="kg-image" alt="Setting up a dev chatbot for Facebok and RedBot" loading="lazy"></figure><p>Copy the callback url you got before and the arbitrary verify token you put in <strong>Node-RED</strong>, don&apos;t forget to check <em>&quot;messages&quot; </em>(otherwise your chatbot will never be notified of incoming messages).</p><p>Click on <em>&quot;Verify and Save&quot;</em>, if you don&apos;t get any error means Facebook is able to contact your <strong>Node-RED</strong> instance and everything is ok.<br>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.<br>To exclude the second option and be sure that your <strong>Node-RED</strong> instance works correctly, grab your <strong>ngrok</strong> url and open this address</p><p><code>http://youraddress.ngrok.io/redbot/facebook/_status</code></p><p>If you get an <em>&quot;ok&quot;</em> then <strong>Node-RED</strong> is up and running.</p><p>The most is done, let&apos;s test if it works: connect a <strong>RedBot</strong> <code>Debug node</code> &#xA0;to the <code>Facebook Receiver node</code>, then open the Facebook page selected with the drop down (when the access token was generated), click on the <em>&quot;Message&quot;</em> button and type anything.</p><p>Something should be visible in the console. From now on everything is similar to what explained in the <a href="http://javascript-jedi.com/simple-telegram-chatbot-with-redbot/">Telegram chat bot tutorial</a> (most of the nodes in <strong>RedBot</strong> can be used for all platforms <strong>Telegram</strong>, <strong>Facebook</strong>, <strong>Slack</strong> so there&apos;s no need to create platform specific flows).</p><p>Happy chatboting!</p>]]></content:encoded></item><item><title><![CDATA[Store user response in RedBot]]></title><description><![CDATA[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.]]></description><link>https://www.javascript-jedi.com/store-user-response-redbot/</link><guid isPermaLink="false">5b8bb7c8c2870138fe080068</guid><category><![CDATA[RedBot]]></category><dc:creator><![CDATA[Guidone]]></dc:creator><pubDate>Thu, 30 Aug 2018 14:09:35 GMT</pubDate><content:encoded><![CDATA[<p>Working with chatbots it&apos;s sometimes useful to parse and store the user response somewhere.</p><p>In <a href="https://github.com/guidone/node-red-contrib-chatbot">RedBot</a> there&apos;s the <em>chat context</em>, it&apos;s a volatile memory space where it&apos;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.</p><figure class="kg-card kg-image-card"><img src="https://www.javascript-jedi.com/content/images/2018/09/parse-email-1.png" class="kg-image" alt="parse-email" loading="lazy"></figure><p>The first <code>Message node</code> just sends out the question to the user <em>&quot;What is your email?&quot;</em> (always use a conversational tone with a chatbot and not cold robotic sentences like <em>&quot;Type your email&quot;</em>).</p><p>Note that the <code>Telegram Sender node</code> has the <strong>track</strong> 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.</p><p>The <code>Parse node</code> analyze the incoming message and cab be configure to search for a pattern, it could be email, image, location, etc.<br>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.</p><p>If the user&apos;s input doesn&apos;t match a valid email, a warning message is sent to the user and the flow restart from the node asking for the email.</p><p>If a valid email is found, it&apos;s stored in the chat context (the name of the variable can be configured in the <code>Parse node</code> panel) and it&apos;s available in the rest of the flow.</p><p>For example we can use it in the final <code>Message node</code> with a handlebars-like syntax with the text: <em>&quot;Thanks, from now on I&apos;ll use {{myemail}} as your email&quot;</em>.</p><p>Or we can use it in a <code>Function node</code>:</p><!--kg-card-begin: markdown--><pre><code class="language-javascript">// get the chat context
var chat = msg.chat();
// email payload
msg.to = chat.get(&apos;email&apos;);
</code></pre>
<!--kg-card-end: markdown--><p>To setup a <strong>Telegram</strong> bot, follow the <a href="http://javascript-jedi.com/simple-telegram-chatbot-with-redbot/">tutorial</a>.</p>]]></content:encoded></item><item><title><![CDATA[Logging conversations with RedBot]]></title><description><![CDATA[Running a chat bot requires some caring, in particular you're never done training it.]]></description><link>https://www.javascript-jedi.com/logging-conversations-with-redbot/</link><guid isPermaLink="false">5b8bb7c8c2870138fe080067</guid><category><![CDATA[RedBot]]></category><dc:creator><![CDATA[Guidone]]></dc:creator><pubDate>Thu, 30 Aug 2018 14:01:14 GMT</pubDate><content:encoded><![CDATA[<p>Running a chat bot requires some caring, in particular you&apos;re never done training it.</p><p>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 <code>Listen node</code>, <code>RiveScript node</code>, etc) in order to support it.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://www.javascript-jedi.com/content/images/2018/09/chat-log.png" class="kg-image" alt loading="lazy" title="Log file field"><figcaption>Log filename</figcaption></figure><p>In <a href="https://github.com/guidone/node-red-contrib-chatbot">RedBot</a> every platform receiver can log the conversation to a file, it looks like</p><pre><code>196520947 [Guido Bellomo] &gt; Wed Oct 05 2016 12:08:45 GMT+0000 - /start
196520947 [Guido Bellomo] &lt; Wed Oct 05 2016 12:08:45 GMT+0000 - Hi, this is GuidoneBot, here&apos;s what I can do for you:/help - you&apos;re already seeing this/where - tells where&apos;s Guido&apos;s house/cv - to get an updated CV (via email)/cam - pry into Guido&apos;s living room/message - send a high priority message to Guido/home - check if Guido is at home
196520947 [Guido Bellomo] &gt; Wed Oct 05 2016 12:11:23 GMT+0000 - Come ti chiami?
196520947 [Guido Bellomo] &gt; Wed Oct 05 2016 12:11:23 GMT+0000 - Sorry, I&apos;m can only speak English</code></pre><p>The first string is the <em>chatId</em> followed by the name (if available). Then the symbol <code>&gt;</code> means it&apos;s an inbound message (from user to the chatbot).</p><p>There is also the <code>Log node</code> that produces a log string for every message that can be manipulated inside <strong>Node-RED</strong> (in case for example the log string should be sent to an external service).</p>]]></content:encoded></item><item><title><![CDATA[NetAtmo dashboard for Node-RED]]></title><description><![CDATA[<p>There are few <a href="http://nodered.org/">Node-RED</a> nodes for the <a href="https://www.netatmo.com/">NetAtmo</a> weather station, most of them return data of the sensors as time series.</p><p>I needed something simpler for my <a href="https://telegram.me/guidone_bot">chatbot</a>, a way to get fetch all current values from all sensors, something like this</p><!--kg-card-begin: markdown--><pre><code class="language-javascript">{
  &quot;temperature&quot;: 27.5,
  &quot;co2&quot;</code></pre>]]></description><link>https://www.javascript-jedi.com/netatmo-dashboard-for-node-red/</link><guid isPermaLink="false">5b8bcb89c2870138fe08007e</guid><category><![CDATA[Node-RED]]></category><dc:creator><![CDATA[Guidone]]></dc:creator><pubDate>Mon, 29 Aug 2016 11:37:00 GMT</pubDate><content:encoded><![CDATA[<p>There are few <a href="http://nodered.org/">Node-RED</a> nodes for the <a href="https://www.netatmo.com/">NetAtmo</a> weather station, most of them return data of the sensors as time series.</p><p>I needed something simpler for my <a href="https://telegram.me/guidone_bot">chatbot</a>, a way to get fetch all current values from all sensors, something like this</p><!--kg-card-begin: markdown--><pre><code class="language-javascript">{
  &quot;temperature&quot;: 27.5,
  &quot;co2&quot;: 246,
  &quot;humidity&quot;: 60,
  &quot;noise&quot;: 38,
  &quot;pressure&quot;: 1009.5,
  &quot;pressureTrend&quot;: &quot;stable&quot;,
  &quot;externalTemperature&quot;: 30,
  &quot;externalHumidity&quot;: 51,
  &quot;externalTemperatureTrend&quot;: &quot;stable&quot;
}
</code></pre>
<!--kg-card-end: markdown--><p>So I created this <a href="http://node-red-contrib-netatmo-dashboard">node-red-contrib-netatmo-dashboard</a>.</p><p>To install</p><pre><code>cd $HOME/.node-red
npm install node-red-contrib-netatmo-dashboard</code></pre><p>See <a href="https://dev.netatmo.com/">Netatmo Connect</a> to get an API key.</p>]]></content:encoded></item><item><title><![CDATA[Setup a simple Telegram chatbot with RedBot]]></title><description><![CDATA[This is a quick tutorial to setup a very simple chatbot with Telegram and RedBot.]]></description><link>https://www.javascript-jedi.com/setup-a-simple-telegram-chatbot-with-redbot/</link><guid isPermaLink="false">5b8bcca5c2870138fe080082</guid><category><![CDATA[RedBot]]></category><dc:creator><![CDATA[Guidone]]></dc:creator><pubDate>Thu, 25 Aug 2016 11:42:00 GMT</pubDate><content:encoded><![CDATA[<p>This is a quick tutorial to setup a very simple chatbot with <strong>Telegram</strong> and <a href="https://github.com/guidone/node-red-contrib-chatbot">RedBot</a>.</p><p>First of all install <a href="http://nodered.org/docs/getting-started/installation">Node-RED</a></p><pre><code>sudo npm install -g node-red</code></pre><p>Then open the user data directory <code>$HOME/.node-red</code> and install the package</p><pre><code>cd $HOME/.node-red npm install node-red-contrib-chatbot</code></pre><p>Then run</p><pre><code>node-red</code></pre><p>The next step is to create a chat bot, I recommend to use <strong>Telegram</strong> since the setup it&apos;s easier ( <strong>Telegram</strong> allows polling to receive messages, <strong>Facebook</strong> requires a https callback and a valid https certificate).<br><strong>Telegram</strong> is really coherent and you have to use a chat bot to create a chatbot. Connect to <strong>@BotFather</strong> and type <code>/newbot</code>, then in the next two steps give the bot a name and username (this will be the real unique address of your chatbot), you&apos;ll get something like this for <strong>@my_new_chat_bot</strong></p><figure class="kg-card kg-image-card"><img src="https://www.javascript-jedi.com/content/images/2018/09/telegram-token.png" class="kg-image" alt="telegram-token" loading="lazy"></figure><p>Copy and paste the access <strong>token</strong>. For more information <a href="https://core.telegram.org/bots#botfather">read here</a>.</p><p>Then open your <strong>Node-RED</strong> and add a Telegram Receiver, in the configuration panel, add a new bot and paste the <strong>token</strong></p><figure class="kg-card kg-image-card"><img src="https://www.javascript-jedi.com/content/images/2018/09/example-telegram-receiver.png" class="kg-image" alt="example-telegram-receiver.png" loading="lazy"></figure><p>Now add a <code>Message node</code> and connect to the <code>Telegram Receiver node</code></p><figure class="kg-card kg-image-card"><img src="https://www.javascript-jedi.com/content/images/2018/09/example-simple-message.png" class="kg-image" alt="example-simple-message.png" loading="lazy"></figure><p>Finally add a <code>Telegram Sender node</code>, don&apos;t forget to select in the configuration panel the same bot of the <code>Telegram Receiver node</code>, this should be the final layout</p><figure class="kg-card kg-image-card"><img src="https://www.javascript-jedi.com/content/images/2018/09/example-simple.png" class="kg-image" alt="example-simple.png" loading="lazy"></figure><p>Now you have a useful bot that answers <strong>&quot;Hi there!&quot;</strong> to any received message.</p><p>Receving the same answers is not very useful, we can introduce <code>Command node</code>: it will pass through the output only if the input message is <em>&quot;hi&quot;</em>:</p><figure class="kg-card kg-image-card"><img src="https://www.javascript-jedi.com/content/images/2018/09/telegram-command.png" class="kg-image" alt="telegram-command" loading="lazy"></figure><p>In this way it&apos;s possible to trigger different actions with different commands, read more about <strong>Telegram</strong> commands <a href="https://core.telegram.org/bots#commands">here</a>.</p>]]></content:encoded></item><item><title><![CDATA[RedBot, a chatbot framework for Node-RED]]></title><description><![CDATA[<figure class="kg-card kg-image-card"><img src="https://www.javascript-jedi.com/content/images/2018/09/RedBot_logo.png" class="kg-image" alt="RedBot_logo" loading="lazy"></figure><h3 id="redbot-is-a-node-red-framework-to-create-chatbots-for-telegram-facebook-and-slack-almost-no-coding-skills-required-">RedBot is a Node-RED framework to create chatbots for Telegram, Facebook and Slack. Almost no coding skills required.</h3><blockquote>Node-RED is a tool for wiring together hardware devices, APIs and online services in new and interesting ways.</blockquote><p>With <strong>RedBot</strong> it&apos;s possible to easily create chatbots just wiring together basic</p>]]></description><link>https://www.javascript-jedi.com/node-red-redbot-chatbot-framework/</link><guid isPermaLink="false">5b8c2929c2870138fe08008a</guid><category><![CDATA[RedBot]]></category><dc:creator><![CDATA[Guidone]]></dc:creator><pubDate>Sat, 23 Jul 2016 18:17:00 GMT</pubDate><content:encoded><![CDATA[<figure class="kg-card kg-image-card"><img src="https://www.javascript-jedi.com/content/images/2018/09/RedBot_logo.png" class="kg-image" alt="RedBot_logo" loading="lazy"></figure><h3 id="redbot-is-a-node-red-framework-to-create-chatbots-for-telegram-facebook-and-slack-almost-no-coding-skills-required-">RedBot is a Node-RED framework to create chatbots for Telegram, Facebook and Slack. Almost no coding skills required.</h3><blockquote>Node-RED is a tool for wiring together hardware devices, APIs and online services in new and interesting ways.</blockquote><p>With <strong>RedBot</strong> it&apos;s possible to easily create chatbots just wiring together basic blocks like <em>message</em>, <em>audio</em>, <em>location</em>, etc. and interact with the Node-RED <a href="http://flows.nodered.org/">ecosystem</a>. If you have particular need, you can do it by yourself in NodeJS, it&apos;s all open source!</p><p><strong>RedBot</strong> is able to understand user&apos;s input using a simple token-based detector or more advanced language interaction like <a href="https://www.rivescript.com/">RiveScript</a>.</p><figure class="kg-card kg-image-card"><img src="https://www.javascript-jedi.com/content/images/2018/09/red-bot-screenshot.png" class="kg-image" alt="RedBot node palette" loading="lazy"></figure><p>The <a href="https://github.com/guidone/node-red-contrib-chatbot">GitHub repository</a>, a <a href="https://github.com/guidone/node-red-contrib-chatbot#getting-started">quick tutorial to setup a Telegram chat bot</a> and some <a href="http://javascript-jedi.com/category/chatbot/">blog posts about chatbots</a>.</p>]]></content:encoded></item><item><title><![CDATA[Middleware in NodeJS]]></title><description><![CDATA[<p>Talking with a collegue of mine I came up with this solution about organizing the code in <strong>NodeJS+Express</strong> using middlewares.<br>Consider this example in which we have a simple page that performs two queries and shows the result in a template.<br>Since everything is asynchronous, we chain in two</p>]]></description><link>https://www.javascript-jedi.com/middleware-in-nodejs/</link><guid isPermaLink="false">5b8c2d83c2870138fe080091</guid><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Guidone]]></dc:creator><pubDate>Fri, 02 Mar 2012 19:35:00 GMT</pubDate><content:encoded><![CDATA[<p>Talking with a collegue of mine I came up with this solution about organizing the code in <strong>NodeJS+Express</strong> using middlewares.<br>Consider this example in which we have a simple page that performs two queries and shows the result in a template.<br>Since everything is asynchronous, we chain in two queries in this way</p><!--kg-card-begin: markdown--><pre><code class="language-javascript">app.get(&apos;/mypage&apos;, function(req,res,next) { 
  sequelize.search(query1)
    .on(&apos;success&apos;, function(res_query1) { 
      sequelize.search(query2)
        .on(&apos;success&apos;, function(res_query2) { 
          res.render(&apos;my_template&apos;, {
            query1: res_query1, query2: res_query2
           });
        });
    });   
});
</code></pre>
<!--kg-card-end: markdown--><p>There&apos;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.<br>The resulting code could become unreadable after few cycle of releases.</p><p>The <em>app.get()</em> accepts any combination of middlewares and arrays of middlewares, each one carrying the same instance of req object (that means we can use it to store temporary result...).<br>So we could split everything in middlewares using the rule of thumb that only the last middleware is allowed to speak with the rest of the world</p><!--kg-card-begin: markdown--><pre><code class="language-javascript">app.get(&apos;/mypage&apos;, 
  function(req, res, next) { 
    sequelize.search(query1)
      .on(&apos;success&apos;, function(res_query1) {
        req.query1 = res_query1;
        return next();
      });
  },
  function(req,res,next) {
    sequelize.search(query2)
      .on(&apos;success&apos;, function(res_query2) { 
        req.query2 = res_query2;
        return next();
      });
  },
  function(req, res, next) { 
    res.render(&apos;my_template&apos;, {
      query1: req.query1,
      query2: req.query2
    });
  }
);
</code></pre>
<!--kg-card-end: markdown--><p>Basically every middleware performs a single step in our asynchronous operations, saving the result in the <em>req</em> object (used like a stack for temporary result) and, finally, calling return <em>next()</em>: don&apos;t forget this, it passes the control to the next middleware (otherwise the browser call will hang up until time out).</p><p>So far it&apos;s just a way of writing the same thing in a different manner. But suppose that, at some point, you want to be able to update the first query via AJAX without reloading the whole page.<br>We don&apos;t want for replicate piece of codes, so we just assign the first two middlewares to variables (for example mw_1 and mw_2) and detach the part of the template that renders query1 into a sub-template (called within <em>my_template</em>).<br>After this code reorganization, it&apos;s super easy</p><!--kg-card-begin: markdown--><pre><code class="language-javascript">app.get(&apos;/mypage/ajax&apos;, mw_1, function(req, res, next) {
  res.render(&apos;my_subtemplate&apos;, { query1: req.query1 });
});
</code></pre>
<!--kg-card-end: markdown--><p>The front-end code (not relevant for this example) just have to put the resulting piece of HTML in the right place.<br>We added functionality without duplicating functionality and without messing up the organization of the code.<br>Welcome middlewares!</p>]]></content:encoded></item><item><title><![CDATA[Tiny little JavaScript polling object]]></title><description><![CDATA[<p>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 <strong>setTimeout</strong> and <strong>setInterval</strong> ids hanging around my code, I wrapped everything in a small JavaScript object <strong>Poller</strong>.</p><p>It&apos;s pretty simple:</p>]]></description><link>https://www.javascript-jedi.com/tiny-little-javascript-polling-object/</link><guid isPermaLink="false">5b8c2a72c2870138fe08008d</guid><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Guidone]]></dc:creator><pubDate>Thu, 01 Dec 2011 19:22:00 GMT</pubDate><content:encoded><![CDATA[<p>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 <strong>setTimeout</strong> and <strong>setInterval</strong> ids hanging around my code, I wrapped everything in a small JavaScript object <strong>Poller</strong>.</p><p>It&apos;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</p><!--kg-card-begin: markdown--><pre><code class="language-javascript">var poller = new Poller();
poller.intervals([1000,5000,10000])
  .checkback(function(callback) {
    // could be anything asynchronous
    $.getJSON(&apos;/is/server/ready&apos;, 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.log(&apos;Ok&apos;)
    })
    .failback(function() {
      // after the third attempt, exits calling the failback
      console.log(&apos;Failed&apos;);
    })
    .start(); // start the process
</code></pre>
<!--kg-card-end: markdown--><p>Each <em>callback()</em>, <em>failback()</em>, <em>checkback()</em> run in the <strong>Poller</strong> context, means that this operator points to the <strong>Poller</strong> instance.<br>A bunch of additional methods are available like: <em>start()</em>, <em>stop()</em>, <em>restart()</em>, <em>next()</em>.</p><p><strong>To do:</strong> implement <em>Deferred</em> pattern for the method that checks the server</p><p><strong>Update</strong>: Update with a <a href="http://github.com/guidone/Poller">GitHub</a> repository and support for deferred/promise.</p>]]></content:encoded></item></channel></rss>