forked from guidone/node-red-contrib-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatbot-rivescript.html
113 lines (106 loc) · 3.36 KB
/
chatbot-rivescript.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<script type="text/javascript">
RED.nodes.registerType('chatbot-rivescript', {
category: 'RedBot Parsers',
color: '#FFCC66',
defaults: {
name: {
value: ''
},
script: {
value: '! version = 2.0\n\n'
}
},
inputs: 1,
outputs: 2,
paletteLabel: 'Rivescript',
icon: 'chatbot-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="chatbot-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="chatbot-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
- <set name=<star>>ok, I'll remember your name as <get name>
</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>