UNPKG

node-red-node-watson

Version:
601 lines (559 loc) 22.3 kB
<!-- Copyright 2017, 2022 IBM Corp. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <script type="text/x-red" data-template-name="watson-conversation-v1-workspace-manager"> <div id="credentials-check" class="form-row"> <div class="form-tips"> <i class="fa fa-question-circle"></i><b> Please wait: </b> Checking for bound service credentials... </div> </div> <div> <label id="node-label-message"><i class="fa fa-exclamation-triangle"></i></label> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"></input> </div> <div class="form-row credentials" style="display: none;"> <label for="node-input-apikey"><i class="fa fa-key"></i> API Key</label> <input type="password" id="node-input-apikey" placeholder="API Key"></input> </div> <div class="form-row credentials"> <label for="node-input-cwm-service-endpoint"><i class="fa fa-tag"></i> Service Endpoint</label> <input type="text" id="node-input-cwm-service-endpoint" placeholder="https://gateway.watsonplatform.net/assistant/api"> </div> <div class="form-row"> <label for="node-input-cwm-custom-mode"><i class="fa fa-book"></i> Mode: </label> <select type="text" id="node-input-cwm-custom-mode" style="display: inline-block; width: 70%;"> <option value="listWorkspaces">List Workspaces</option> <option value="getWorkspace">Get Workspace Details</option> <option value="createWorkspace">Create Workspace</option> <option value="updateWorkspace">Update Workspace</option> <option value="deleteWorkspace">Delete Workspace</option> <option disabled>______________</option> <option value="listIntents">List Intents</option> <option value="getIntent">Get Intent Details</option> <option value="createIntent">Create Intent</option> <option value="updateIntent">Update Intent</option> <option value="deleteIntent">Delete Intent</option> <option disabled>______________</option> <option value="listExamples">List Examples</option> <option value="createExample">Create Example</option> <option value="deleteExample">Delete Example</option> <option disabled>______________</option> <option value="listCounterExamples">List Counter Examples</option> <option value="createCounterExample">Create Counter Example</option> <option value="deleteCounterExample">Delete Counter Example</option> <option disabled>______________</option> <option value="listEntities">List Entities</option> <option value="getEntity">Get Entity Details</option> <option value="createEntity">Create Entity</option> <option value="updateEntity">Update Entity</option> <option value="deleteEntity">Delete Entity</option> <option disabled>______________</option> <option value="listEntityValues">List Entity Values</option> <option value="getEntityValue">Get Entity Value Details</option> <option value="addEntityValue">Add Entity Value</option> <option value="updateEntityValue">Update Entity Value</option> <option value="deleteEntityValue">Delete Entity Value</option> <option disabled>______________</option> <option value="listDialogNodes">List Dialog Nodes</option> <option value="getDialogNode">Get Dialog Node Details</option> <option value="createDialogNode">Create Dialog Node</option> <option value="updateDialogNode">Update Dialog Node</option> <option value="deleteDialogNode">Delete Dialog Node</option> </select> </div> <div class="form-row"> <label for="node-input-cwm-workspace-id"><i class="fa fa-book"></i> Workspace ID</label> <input type="text" id="node-input-cwm-workspace-id" placeholder=""> </div> <div class="form-row"> <label for="node-input-cwm-intent"><i class="fa fa-book"></i> Intent</label> <input type="text" id="node-input-cwm-intent" placeholder=""> </div> <div class="form-row"> <label for="node-input-cwm-example"><i class="fa fa-book"></i> Example Input</label> <input type="text" id="node-input-cwm-example" placeholder=""> </div> <div class="form-row"> <label for="node-input-cwm-entity"><i class="fa fa-book"></i> Entity</label> <input type="text" id="node-input-cwm-entity" placeholder=""> </div> <div class="form-row"> <label for="node-input-cwm-entity-value"><i class="fa fa-book"></i> Entity Value</label> <input type="text" id="node-input-cwm-entity-value" placeholder=""> </div> <div class="form-row"> <label for="node-input-cwm-dialog-node"><i class="fa fa-book"></i> Dialog Node ID</label> <input type="text" id="node-input-cwm-dialog-node" placeholder=""> </div> <div class="form-row"> <label for="node-input-cwm-export-content"><i class="fa fa-book"></i> Export All Content</label> <input type="checkbox" id="node-input-cwm-export-content" placeholder=""> </div> </script> <script type="text/x-red" data-help-name="watson-conversation-v1-workspace-manager"> <p>The Conversation Workspace Manager is used to ... </p> <ul> <li>list Workspaces <p>In this mode a list of all workspaces a that you have created in the conversation services are returned on <code>msg.workspaces</code> </p> </li> <li>Get Workspace <p>In this mode all information about a workspace, optionally including all workspace content, is retrieved. The information is returned on <code>msg.workspace</code> </p> </li> <li>Create Workspace <p>In this mode, a new worskpace is created. The input json structure defining the content of the new workspace should be passed in as <code>msg.payload</code> </p> </li> <li>Update Workspace <p>In this mode, the specified worskpace is updated. The input json structure defining the content of the updates should be passed in as <code>msg.payload</code>. Only the elements need to be included in the json. Any included element will override the existing setting for the element. ie. If only updating entities, then only entities need to be included in the json. Any existing entities in the workspace will be overridden. ie. If any entity is not mentioned in the json, then it will be deleted from the workspace. </p> </li> <li>Delete Workspace <p>In this mode the selected workspace is deleted. </p> </li> <li>list Intents <p>In this mode a list of all intents for the specified conversation workspace are returned on <code>msg.intents</code> </p> </li> <li>Get Intent <p>In this mode all information about the specified intent is retrieved. The information is returned on <code>msg.intent</code> </p> </li> <li>Create Intent <p>In this mode, a new intent is created in the specified workspace. The input json structure defining the content of the new intent should be passed in as <code>msg.payload</code> </p> </li> <li>Update Intent <p>In this mode, the specified intent is updated. The input json structure defining the content of the updates should be passed in as <code>msg.payload</code>. Only the elements need to be included in the json. Any included element will override the existing setting for the element. ie. If only updating examples, then only the examples need be included in the json. Any existing examples will be overridden. ie. If any example is not mentioned in the json, then it will be deleted. You can use this mode to rename an intent. </p> </li> <li>Delete Intent <p>In this mode the selected intent is removed from the worskpace. </p> </li> <li>List Examples <p>In this mode a list of all user input examples for an intent in the specified conversation workspace are returned on <code>msg.examples</code> </p> </li> <li>Create Example <p>In this mode a new example is created for an intent in the specified conversation workspace. </p> </li> <li>Delete Example <p>In this mode the selected example for an intent is removed. </p> </li> <li>List Counter Examples <p>In this mode a list of all counter examples in the specified conversation workspace are returned on <code>msg.counterexamples</code>. Counterexamples are examples that have been marked as irrelevant input. </p> </li> <li>Create Counter Example <p>In this mode a new counter example is created in the specified conversation workspace. </p> </li> <li>Delete Counter Example <p>In this mode an existing counter example is deleted from the specified conversation workspace. </p> </li> <li>list Entities <p>In this mode a list of all entities for the specified conversation workspace are returned on <code>msg.entities</code> </p> </li> <li>Get Entity <p>In this mode all information about the specified entity is retrieved. The information is returned on <code>msg.entity</code> </p> </li> <li>Create Entity <p>In this mode, a new entity is created in the specified workspace. The input json structure defining the content of the new entity should be passed in as <code>msg.payload</code> </p> </li> <li>Update Entity <p>In this mode, the specified entity is updated. The input json structure defining the content of the updates should be passed in as <code>msg.payload</code>. Only the elements need to be included in the json. Any included element will override the existing setting for the element. ie. Any existing elements will be overridden. ie. If any element is not mentioned in the json, then it will be deleted. You can use this mode to rename an entity. </p> </li> <li>Delete Entity <p>In this mode the selected entity is removed from the worskpace. </p> </li> <li>list Entity Values <p>In this mode a list of all values for an entitu for the specified conversation workspace are returned on <code>msg.values</code> </p> </li> <li>Get Entity Value <p>In this mode all information about the specified entity value is retrieved. The information is returned on <code>msg.value</code> </p> </li> <li>Add Entity Value <p>In this mode, a new entity value is created in the specified workspace. The input json structure defining the content of the new entity value should be passed in as <code>msg.value</code> </p> </li> <li>Update Entity Value <p>In this mode, the specified entity value is updated. The input json structure defining the content of the updates should be passed in as <code>msg.payload</code>. Only the elements need to be included in the json. Any included element will override the existing setting for the element. ie. Any existing elements will be overridden. ie. If any element is not mentioned in the json, then it will be deleted. You can use this mode to rename an entity value. </p> </li> <li>Delete Entity Value <p>In this mode the selected entity value is removed from the worskpace. </p> </li> <li>list Dialog Nodes <p>In this mode a list of all dialog nodes for the specified conversation workspace are returned on <code>msg.dialog_nodes</code> </p> </li> <li>Get Dialog Node <p>In this mode all information about the dialog node is retrieved. The information is returned on <code>msg.dialog_node</code> </p> </li> <li>Create Dialog Node <p>In this mode, a new dialog node is created. The input json structure defining the content of the node should be passed in as <code>msg.payload</code>. </p> </li> <li>Update Dialog Node <p>In this mode, the specified dialog node is updated. The input json structure defining the content of the updates should be passed in as <code>msg.payload</code>. Fields to be updated need a <code>new_</code> prefix as part of their key. </p> </li> <li>Delete Dialog Node <p>In this mode the selected dialog node is removed from the worskpace. </p> </li> </ul> <p>The node configurations can be overridden by setting <ul> <li> <code>msg.params.apikey</code> </li> <li> <code>msg.params.endpoint</code> </li> <li> <code>msg.params.workspace_id</code> </li> <li> <code>msg.params.intent</code> </li> <li> <code>msg.params.example</code> </li> <li> <code>msg.params.entity</code> </li> <li> <code>msg.params.entity_value</code> </li> <li> <code>msg.params.dialog_node</code> </li> <li> <code>msg.params.method</code> <p>to one of the following values: <select> <option> listWorkspaces </option> <option> getWorkspace </option> <option> createWorkspace </option> <option> updateWorkspace </option> <option> deleteWorkspace </option> <option> listIntents </option> <option> getIntent </option> <option> createIntent </option> <option> updateIntent </option> <option> deleteIntent </option> <option> listExamples </option> <option> createExample </option> <option> deleteExample </option> <option> listCounterExamples </option> <option> createCounterExample</option> <option> deleteCounterExample </option> <option> listEntities </option> <option> getEntity </option> <option> createEntity </option> <option> updateEntity </option> <option> deleteEntity </option> <option> listEntityValues </option> <option> getEntityValue </option> <option> addEntityValue </option> <option> updateEntityValue </option> <option> deleteEntityValue </option> <option> listDialogNodes </option> <option> getDialogNode </option> <option> createDialogNode </option> <option> updateDialogNode </option> <option> deleteDialogNode </option> </select> </p> </li> </ul> </p> <p>For more information about the conversation service, read the <a href="https://console.bluemix.net/docs/services/conversation/index.html"> documentation</a>.</p> </script> <script type="text/javascript"> // Need to simulate a namespace, as some of the variables had started to leak across nodes function CV1WM () { } // This is the namespace for cv1wm. Currently only contains models, but more vars and functions may need to be // moved in if there is a clash with other nodes. var cv1wm = new CV1WM(); cv1wm.mode_selected = null; cv1wm.showSelectedFields = function(fields) { for (i = 0; i < fields.length; i++) { $(fields[i]).parent().show(); } } cv1wm.hideSelectedFields = function(fields) { for (i = 0; i < fields.length; i++) { $(fields[i]).parent().hide(); } } // Function to be used at the start, as don't want to expose any fields, unless the models are // available. The models can only be fetched if the credentials are available. cv1wm.hideEverything = function () { var fields = []; fields.push('#node-input-cwm-workspace-id' + ', #node-input-cwm-intent' + ', #node-input-cwm-example' + ', #node-input-cwm-entity' + ', #node-input-cwm-entity-value' + ', #node-input-cwm-dialog-node' + ', #node-input-cwm-export-content'); cv1wm.hideSelectedFields(fields); } cv1wm.processSelectedMethod = function(method) { var fields = []; cv1wm.hideEverything(); switch (method) { case 'getWorkspace': case 'listIntents': case 'listEntities': fields.push('#node-input-cwm-workspace-id' + ', #node-input-cwm-export-content'); break; case 'getIntent': fields.push('#node-input-cwm-workspace-id' + ', #node-input-cwm-intent' + ', #node-input-cwm-export-content'); break; case 'updateIntent': case 'deleteIntent': case 'listExamples': fields.push('#node-input-cwm-workspace-id' + ', #node-input-cwm-intent'); break; case 'createExample': case 'deleteExample': fields.push('#node-input-cwm-workspace-id' + ', #node-input-cwm-intent' + ', #node-input-cwm-example'); break; case 'createCounterExample': case 'deleteCounterExample': fields.push('#node-input-cwm-workspace-id' + ', #node-input-cwm-example'); break; case 'getEntity': case 'listEntityValues': fields.push('#node-input-cwm-workspace-id' + ', #node-input-cwm-entity' + ', #node-input-cwm-export-content'); break; case 'getEntityValue': fields.push('#node-input-cwm-workspace-id' + ', #node-input-cwm-entity' + ', #node-input-cwm-entity-value' + ', #node-input-cwm-export-content'); break; case 'updateEntity': case 'deleteEntity': fields.push('#node-input-cwm-workspace-id' + ', #node-input-cwm-entity'); break; case 'getDialogNode': case 'updateDialogNode': case 'deleteDialogNode': fields.push('#node-input-cwm-workspace-id' + ', #node-input-cwm-dialog-node'); break; case 'addEntityValue': case 'updateEntityValue': case 'deleteEntityValue': fields.push('#node-input-cwm-workspace-id' + ', #node-input-cwm-entity' + ', #node-input-cwm-entity-value'); break; case 'deleteWorkspace': case 'updateWorkspace': case 'createIntent': case 'createEntity': case 'listCounterExamples': case 'listDialogNodes': case 'createDialogNode': fields.push('#node-input-cwm-workspace-id'); break; case 'listWorkspaces': case 'createWorkspace': break; } cv1wm.showSelectedFields(fields); } // Register the handlers for the fields cv1wm.handlersUI = function () { $('#node-input-cwm-custom-mode').change(function() { cv1wm.mode_selected = $('#node-input-cwm-custom-mode').val(); cv1wm.processSelectedMethod(cv1wm.mode_selected); }); } // This is the on edit prepare function, which will be invoked everytime the dialog // is shown. function cv1wmoneditprepare() { cv1wm.hideEverything(); cv1wm.handlersUI(); $.getJSON('watson-conversation-v1-workspace-manager/vcap/') // for some reason the getJSON resets the vars so need to restoreFromHidden again // so again. .done(function (service) { $('.credentials').toggle(!service); }) .fail(function () { $('.credentials').show(); }).always(function () { $('#credentials-check').hide(); }); } // Save the values in the dyanmic lists to the hidden fields. function cv1wmoneditsave(){ } (function() { RED.nodes.registerType('watson-conversation-v1-workspace-manager', { category: 'IBM Watson', defaults: { name: {value: ''}, 'cwm-custom-mode': {value:"listWorkspaces"}, 'cwm-workspace-id': {value:""}, 'cwm-intent': {value:""}, 'cwm-example': {value:""}, 'cwm-entity': {value:""}, 'cwm-entity-value': {value:""}, 'cwm-dialog-node': {value:""}, 'cwm-export-content': {value:false}, 'cwm-service-endpoint' :{value: ''} }, credentials: { apikey: {type: 'password'} }, color: 'rgb(84,149,180)', inputs: 1, outputs: 1, icon: 'conversation-v1-25x25.png', paletteLabel: 'assistant workspace manager', label: function() { return this.name || 'assistant workspace manager'; }, labelStyle: function() { return this.name ? 'node_label_italic' : ''; }, oneditprepare: cv1wmoneditprepare, oneditsave: cv1wmoneditsave }); })(); </script>