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

117 lines (112 loc) 4.86 kB
<script type="text/javascript"> $.RedBot.registerType('chatbot-context', { category: $.RedBot.config.name, color: '#FFCC66', defaults: { command: { value: 'intent' }, fieldValue: { value: '' }, fieldType: { value: 'str' }, fieldName: { value: '', validate: function(value) { if (this.command !== 'intent' && $.RedBot.validate.isEmpty(value)) { return false; } return true; } } }, inputs: 1, outputs: 1, paletteLabel: 'Context', icon: 'chatbot-context.png', label: function() { return 'Context' + (this.command != null ? ' (' + this.command + ')' : ''); }, oneditprepare: function() { $('#node-input-fieldValue').typedInput({ 'default': 'str', types: ['str','num','bool', 'json'], typeField: $('#node-input-fieldType') }); $('#node-input-command').change(function() { var command = $(this).val(); $('.only-for').hide(); $('.only-for-' + command).show(); }); $('.only-for').hide(); $('.only-for-' + this.command).show(); }, oneditsave: function() { $("#node-input-template").val(this.editor.getValue()); delete this.editor; } }); </script> <script type="text/x-red" data-template-name="chatbot-context"> <div class="form-row"> <label for="node-input-command">Command</label> <select id="node-input-command" placeholder="Language to match" style="width: 250px;"> <option value="get">Get</option> <option value="set">Set</option> <option value="delete">Delete</option> <option value="intent">Store values from intent</option> </select> </div> <div class="form-row only-for only-for-set only-for-get only-for-delete"> <label for="node-input-fieldName">Variable</label> <input type="text" id="node-input-fieldName" placeholder="Variable" style="width:250px;"> </div> <div class="form-row only-for only-for-set"> <label for="node-input-fieldValue"><i class="icon-pencil"></i> Value</label> <input type="text" id="node-input-fieldValue" placeholder="" style="width:250px;"> <input type="hidden" id="node-input-fieldType"> </div> <div class="form-row only-for only-for-intent"> Store variables extracted from a NPL service (like <b>Alexa</b>, <b>Dialogflow.com</b>, <b>Recast.ai</b>) from an <i>intent</i> message type or from a <i>response</i> message type (a <b>Slack</b> response to a Block or Dialog) </div> </script> <script type="text/x-red" data-help-name="chatbot-context"><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=20230218T124909Z&X-Amz-Expires=3600&X-Amz-Signature=1479f5fe3acc186f3cb336ec77867de3228a17a11a6ab979e5bcc7ea73aa6956&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>