UNPKG

node-red-contrib-tekosbot

Version:

Tekos bot based on matrix

225 lines (211 loc) 10.8 kB
<script type="text/javascript"> RED.nodes.registerType('tekos-chatbase-config',{ category: 'config', defaults: { name: { value: undefined }, version: { value: undefined } }, credentials: { token: { type: "text" } }, label: function() { return this.name || "Chatbase config"; } }); </script> <script type="text/x-red" data-template-name="tekos-chatbase-config"> <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" style="width:70%;"> </div> <div class="form-row"> <label for="node-config-input-token"><i class="fa fa-lock"></i> Token</label> <input type="text" id="node-config-input-token" placeholder="" style="width:70%;"> </div> <div class="form-row"> <label for="node-config-input-version"><i class="fa fa-id-card"></i> Version</label> <input type="text" id="node-config-input-version" placeholder="0.0.1" style="width:70%;"> </div> </script> <script type="text/x-red" data-help-name="tekos-chatbase-config"> <p>Configuration for chatbase logging.</p> <h3>References</h3> <ul> <li><a href="https://chatbase.com/documentation/generic">Chatbase</a> - generic events</a></li> <li><a href="https://chatbase.com/documentation/events">Chatbase</a> - custom events</a></li> <li><a href="https://github.com/NGRP/node-red-contrib-viseo/">VISEO BotMaker</a> - the nodes github repository</li> </ul> </script> <!-- ************************************************************************************************************************* --> <script type="text/javascript"> RED.nodes.registerType('tekos-chatbase',{ category: 'Analytics', color: '#3FADB5', defaults: { name: { value: undefined }, config: { value: undefined, type: 'tekos-chatbase-config'}, user: { value: undefined }, platform: { value: undefined }, platformType: { value: 'str' }, chatbaseType: { value: undefined }, chatbaseIntent: { value: undefined, validate: RED.validators.typedInput("chatbaseIntentType") }, chatbaseIntentType: { value: 'str' }, chatbaseSender: { value: 'user' }, properties: { value: [{ n: "", v:"", vt:"str"}] }, message: { value: undefined, validate: RED.validators.typedInput("messageType") }, messageType: { value: 'msg' }, notHandled: { value: false } }, inputs: 1, outputs: 1, icon: "chart.svg", align: "right", paletteLabel: 'Chatbase', label: function() { return this.name || "Chatbase"; }, oneditprepare: function() { $('#node-input-chatbaseType, #node-input-chatbaseSender, #node-input-notHandled').change(function() { if($("#node-input-chatbaseType").val() === 'generic') { if($('#node-input-chatbaseSender').val() === 'user' && $('#node-input-notHandled:checked').length === 0){ $('#chatbaseIntent-row').show() } else { $('#chatbaseIntent-row').hide() } if($('#node-input-chatbaseSender').val() === 'agent') { $('#notHandled-row').hide() } else { $('#notHandled-row').show() } } else { $('#chatbaseIntent-row').show() } }); $("#node-input-properties-container").css('min-height','200px').editableList({ addItem: function ( row, index, data ) { var property = data.p, name = '', value = '', valueType = 'str'; if(property) { if(property.hasOwnProperty('n')) { name = property.n; } if(property.hasOwnProperty('v')) { value = property.v; } if(property.hasOwnProperty('vt')) { valueType = property.vt; } } $('<span>Name</span>').appendTo(row) var nameField = $('<input/>', { class:"node-input-property-name", type:"text",style:"margin-left: 5px;width:calc(50% - 50px);margin-right:15px", value: name}).appendTo(row); $('<span>Value</span>').appendTo(row) var typeField = $('<input/>', { type: "hidden", value: valueType, id: 'propertyType-'+index }).appendTo(row) var valueField = $('<input/>', { class:"node-input-property-value", type:"text", style:"width:calc(50% - 50px)", value: value }).appendTo(row).typedInput({default: valueType || 'str' ,types:['str', 'num', 'bool', 'msg'], typeField: $('#propertyType-'+index) }); }, removable: true }); $('#node-input-platform').typedInput({default: "str", typeField: $("#node-input-platformType"), types: ['msg', 'str']}); $('#node-input-user').typedInput({default: "msg", types: ['msg']}).val(this.user || 'user'); $('#node-input-chatbaseIntent').typedInput({default: 'str', typeField: $("#node-input-chatbaseIntentType"), types: ['msg', 'str']}); $('#node-input-message').typedInput({default: 'msg', typeField: $("#node-input-messageType"), types: ['msg', 'str']}); $('#node-input-chatbaseType').change(function() { $('.section').hide() $('.section.chatbase-'+$(this).val()).show() }); $('#node-input-chatbaseType').val(this.chatbaseType || 'generic'); for (var i = 0; i < this.properties.length; i++) { var property = this.properties[i]; $("#node-input-properties-container").editableList('addItem', {p: property, i: i} ); } }, oneditsave: function() { var properties = $("#node-input-properties-container").editableList('items'); var node = this; node.properties = []; properties.each(function(i) { var property = $(this); var nameValue = property.find(".node-input-property-name").val(); var valueType = property.find(".node-input-property-value").typedInput('type'); var valueValue = property.find(".node-input-property-value").typedInput('value'); if (nameValue !== '') { node.properties.push({ n: nameValue, v: valueValue, vt: valueType }); } }); }, }); </script> <script type="text/x-red" data-template-name="tekos-chatbase"> <div class="form-row"> <label for="node-input-name"><i class="icon-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-row"> <label for="node-input-config"><i class="fa fa-lock"></i> Config</label> <input type="text" id="node-input-config"> </div> <div class="form-row"> <label for="node-input-platform"><i class="fa fa-globe"></i> Platform</label> <input type="text" id="node-input-platform" placeholder="google" style="width:70%;"> <input type="hidden" id="node-input-platformType"> </div> <div class="form-row"> <label for="node-input-user"><i class="fa fa-user"></i> User</label> <input type="text" id="node-input-user" placeholder="user" style="width:70%;"> </div> <div class="form-row"> <label for="node-input-chatbaseType"><i class="fa fa-crop"></i> Type</label> <select id="node-input-chatbaseType" style="width:70%;"> <option value="generic">Generic</option> <option value="custom">Custom</option> </select> </div> <div class="section chatbase-custom"> <label for="node-input-properties-container"><i class="fa fa-list"></i> Properties</label> <ol id="node-input-properties-container" style="width: calc( 70% + 105px );"></ol> </div> <div class="section chatbase-generic"> <div class="form-row"> <label for="node-input-chatbaseSender"><i class="fa fa-user"></i> Sender</label> <select id="node-input-chatbaseSender" style="width:70%;"> <option value="user">User</option> <option value="agent">Self</option> </select> </div> <div class="form-row" id="notHandled-row"> <label for="node-input-notHandled"><i class="fa fa-question-circle"></i> Not handled</label> <input type="checkbox" id="node-input-notHandled" style="width: unset; margin-left:20px;"> </div> <div class="form-row"> <label for="node-input-message"><i class="fa fa-edit"></i> Message</label> <input type="text" id="node-input-message" style="width:70%;"> <input type="hidden" id="node-input-messageType"> </div> </div> <div class="form-row" id="chatbaseIntent-row"> <label for="node-input-chatbaseIntent"><i class="fa fa-comment"></i> Intent</label> <input type="text" id="node-input-chatbaseIntent" style="width:70%;"> <input type="hidden" id="node-input-chatbaseIntentType"> </div> </script> <script type="text/x-red" data-help-name="tekos-chatbase"> <!-- <p>Sends events to Chatbase.</p> <h3>Details</h3> <p>This node sends logs to Chatbase with the given information.</p> <p>Properties</p> <dl class="message-properties"> <dt>Config <span class="property-type">config</span></dt> <dd>token to access the Chatbase application</dd> </dl> <h3>References</h3> <ul> <li><a href="https://chatbase.com/documentation/generic">Chatbase</a> - generic events</a></li> <li><a href="https://chatbase.com/documentation/events">Chatbase</a> - custom events</a></li> <li><a href="https://github.com/NGRP/node-red-contrib-viseo/">VISEO BotMaker</a> - the nodes github repository</li> </ul> --> </script>