UNPKG

node-red-contrib-chatbot

Version:

REDBot a Chat bot for a full featured chat bot for Telegram, Facebook Messenger and Slack. Almost no coding skills required

112 lines (108 loc) 4.91 kB
<script type="text/javascript"> $.RedBot.registerType('chatbot-context-store', { category: 'config', color: '#FFCC66', defaults: { name: { value: '' }, contextStorage: { value: '' }, contextParams: { value: '' } }, paletteLabel: 'Context', label: function() { return this.name || "Context Store"; }, oneditsave: function() { this.contextParams = $('#node-config-input-contextParams').typedInput('value'); }, oneditprepare: function() { var node = this; var widget = $('#node-config-input-contextParams'); widget.typedInput({ 'default': 'json', types: ['json'] }); widget.typedInput('value', this.contextParams); var nodeRedUrl = $.RedBot.getNodeRedUrl(); // fetch available context providers $.get(nodeRedUrl + 'redbot/context-providers') .done(function(response) { var select = $('#node-config-input-contextStorage') .append('<option value="">Select context provider</option>'); var idx; var providers = {}; for(idx = 0; idx < response.length; idx++) { select.append('<option value="' + response[idx].type + '">' + response[idx].name + '</option>'); providers[response[idx].type] = response[idx]; } select.val(node.contextStorage); $('#provider-documentation') .html(providers[node.contextStorage] != null ? providers[node.contextStorage].description : ''); // on change select.change(function() { var providerName = select.val(); $('#provider-documentation').html(providers[providerName] != null ? providers[providerName].description : ''); }); }); } }); </script> <script type="text/x-red" data-template-name="chatbot-context-store"> <div class="form-row"> <label for="node-config-input-name"><i class="icon-tag"></i> Name</label> <input type="text" id="node-config-input-name" placeholder="Name" style="width:250px;"> </div> <div class="form-row"> <label for="node-config-input-contextStorage">Type</label> <select id="node-config-input-contextStorage"> </select> </div> <div class="form-row"> <label for="node-config-input-params">Params</label> <input type="text" id="node-config-input-contextParams" placeholder="Params"> </div> <div id="provider-documentation" style="max-width: 460px;font-size: 12px;color: #999999;line-height: 14px;clear:both;margin-top:5px;margin-bottom:10px;"> </div> </script> <script type="text/x-red" data-help-name="chatbot-context-store"><p>Get, set or delete an element in the chat context.</p> <p>The chat context is a volatile namespace for variables related to the current chat user, some variables are predefined (like <em>firstName</em>, <em>lastName</em>, <em>topic</em>, <em>chatId</em>, etc).</p> <p>Typically this node is used to manually set the <em>topic</em> of the user before or after entering a <a href="https://www.notion.so/db8481a702b6491093f7ea53d765129e">Rivescript node</a> or to store the extracted variables of an <a href="https://www.notion.so/b4bd4f8db5d243d487430d073c35992b">Intent payload</a> .</p> <p>For example, nodes like <a href="https://www.notion.so/84b9ea66d20743fd9cf45d3de5f17693">Dialogflow node</a> can extract the <em>intent</em> from a sentences along with some variables (numbers, dates, etc). Chaining a <a href="https://www.notion.so/24a646bff58b4edfb249f1d27384230f">Context node</a> stores these vars in the chat context</p> <p><img src="https://s3.us-west-2.amazonaws.com/secure.notion-static.com/d13e4586-3e43-4549-aad8-d7139cab26dc/context-example-1.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20230218%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20230218T124936Z&X-Amz-Expires=3600&X-Amz-Signature=3ae8387482c6879b353c42ed0557e30f7f55563d188cdc3911b79dc244c792c7&X-Amz-SignedHeaders=host&x-id=GetObject" alt="Store Intent vars"></p> <p>Available parameters for the <code>msg.payload</code></p> <table> <thead> <tr> <th>Name</th> <th>Type</th> <th>Description</th> </tr> </thead> <tbody><tr> <td>command</td> <td>string</td> <td>Operation to do on the context: <em>get</em>, <em>set</em>, <em>delete</em>, <em>intent</em></td> </tr> <tr> <td>fieldType</td> <td>string</td> <td>Type of field to set. Required for command: <em>set</em>. Can be: <em>str</em>, <em>num</em>, <em>bol</em>, <em>json</em>.</td> </tr> <tr> <td>fieldValue</td> <td>string</td> <td>The value to be set. Required for command: <em>set</em></td> </tr> <tr> <td>fieldName</td> <td>string</td> <td>The name of the chat context variable. Required for command: <em>set</em>, <em>get</em>, <em>delete</em></td> </tr> </tbody></table> <p>This node is available for all platforms.</p> </script>