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
105 lines (97 loc) • 4.44 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('chatbot-rivescript', {
category: 'RedBot Parsers',
color: '#FFCC66',
defaults: {
name: {
value: ''
},
script: {
value: '! version = 2.0\n\n'
},
debug: {
value: false
}
},
inputs: 1,
outputs: 2,
paletteLabel: 'Rivescript',
icon: 'chatbot-rivescript.png',
label: function() {
return this.name || 'RiveScript';
},
oneditprepare: function() {
$('#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 dialogForm = $('#dialog-form');
var rowName = $('.form-row-name', dialogForm);
var rowInfo = $('.form-row-info', dialogForm);
var rowDebug = $('.form-row-debug', dialogForm);
var height = dialogForm.height() - rowName.height() - rowInfo.height() - rowDebug.height() - 30;
$('.node-text-editor').css('height', height + 'px');
this.editor.resize();
}
});
</script>
<script type="text/x-red" data-template-name="chatbot-rivescript">
<div class="form-row form-row-name">
<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 form-row-info">
<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>
<div class="form-row form-row-debug">
<label for="node-input-answer"><i class="icon-wrench"></i> Debug</label>
<input type="checkbox" value="true" id="node-input-debug">
<span style="max-width: 460px;font-size: 12px;color: #999999;line-height: 14px;display:block;">
Show <b>Rivescript</b> debug information in the Node-RED debug panel
</span>
</div>
</script>
<script type="text/x-red" data-help-name="chatbot-rivescript"><p>Reply to an incoming message using <strong>RiveScript</strong>.</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 output is generally connected to a <code>Message Node</code>. The node will not try to parse command-like sentences (for example <code>/my_command</code>).</p>
<p>A <strong>RiveScript</strong> file looks like</p>
<pre><code>! version = 2.0
+ hello bot
- Hello, human!
</code></pre><p>It's also able to parse the sentence and store data to the chat context</p>
<pre><code>! 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;
</code></pre><p><strong>RiveScript</strong> can get/set variables in the chat context.</p>
<p>You can use the chat context variable <em>topic</em> to scope some <strong>RiveScript</strong> triggers into specific subjects</p>
<pre><code>! version = 2.0
> topic name_ok
+ *
+ hello!
< topic
</code></pre><p>In this case the trigger <em>"*"</em> will be executed only if the topic is _name_ok_
(it's possible to set the intent using a <code>Context node</code> or in <strong>RiveScript</strong> with
<code>{topic=new_topic}</code>). Note that <strong>RiveScript</strong>'s <em>topic</em> and <strong>RedBot</strong>'s <em>intent</em> are the same thing.</p>
<p>Read a <strong>RiveScript</strong> tutorial <a href="https://www.rivescript.com/docs/tutorial">tutorial here</a></p>
<p><img src="https://img.shields.io/badge/platform-Telegram-blue.svg?colorB=7cbaea" alt="Telegram">
<img src="https://img.shields.io/badge/platform-Facebook-blue.svg" alt="Facebook">
<img src="https://img.shields.io/badge/platform-Slack-green.svg" alt="Slack">
<img src="https://img.shields.io/badge/platform-Smooch-orange.svg" alt="Smooch"></p>
</script>