UNPKG

prisme-flow

Version:

prisme platform flow engine

121 lines (110 loc) 3.54 kB
<!-- Created by prisme.io on 09/06/2017. @author <a href="mailto:hello@prisme.io">savane vamara</a> (prisme.io) --> <script type="text/javascript"> RED.nodes.registerType('bot-rivescript', { category: 'bot-parsers', color: '#FFCC66', defaults: { name: { value: '' }, script: { value: '! version = 2.0\n\n' } }, inputs: 1, outputs: 2, paletteLabel: 'rivescript', icon: 'rivescript.png', label: function() { return this.name || 'RiveScript'; }, oneditprepare: function() { var that = this; $( "#node-input-outputs" ).spinner({ min:1 }); this.editor = RED.editor.createEditor({ id: 'node-input-script-editor', mode: 'ace/mode/text', value: $("#node-input-script").val(), globals: { } }); this.editor.focus(); }, oneditsave: function() { $("#node-input-script").val(this.editor.getValue()); delete this.editor; }, oneditresize: function(size) { var rows = $("#dialog-form>div:not(.node-text-editor-row)"); var height = $("#dialog-form").height(); for (var i=0;i<rows.size();i++) { height -= $(rows[i]).outerHeight(true); } var editorRow = $("#dialog-form>div.node-text-editor-row"); height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom"))); $(".node-text-editor").css("height",height+"px"); this.editor.resize(); } }); </script> <script type="text/x-red" data-template-name="bot-rivescript"> <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"> <input type="hidden" id="node-input-script" autofocus="autofocus"> </div> <div class="form-row"> <div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-script-editor"></div> </div> <div class="form-row"> <div style="font-size: 12px;color: #999999;line-height: 14px;"> <b>RiveScript</b> used to elaborate the answer, read the <a target="_blank" href="https://www.rivescript.com/docs/tutorial">tutorial here</a> </div> </div> </script> <script type="text/x-red" data-help-name="bot-rivescript"> <p>Reply to an incoming message using RiveScript</p> <p> This node answers with a string to the first output if the script is able to elaborate a reply, otherwise a string error is sent to the second output. This node is generally connected to a message node. </p> <p> A RiveScript looks like <pre> ! version = 2.0 + hello bot - Hello, human! </pre> It's also able to parse the sentence and store data to the chat context <pre> ! version = 2.0 + my name is guido - &lt;set name=&lt;star&gt;&gt;ok, I'll remember your name as &lt;get name&gt; </pre> RiveScript can get/set variables in the chat context. </p> <p> You can use the chat context variable <em>topic</em> to scope some RiveScript triggers into topics <p> <pre> ! version = 2.0 > topic name_ok + * + hello! < topic </pre> <p> In this case the trigger <em>"*"</em> will be executed only if the topic is <em>name_ok</em> (it's possible to set the intent using a <code>Context node</code> or in <b>RiveScript</b> with <code>{topic=new_topic}</code>). Note that <b>RiveScript</b>'s <em>topic</em> and <b>RedBot</b>'s <em>intent</em> are the same thing. </p> <p> Read a RiveScript tutorial <a href="https://www.rivescript.com/docs/tutorial" target="_blank">tutorial here</a> </p> </script>