-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetslots.html
174 lines (147 loc) · 8.81 KB
/
setslots.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!-- node-red-contrib-rasa-actionserver v1.3.0
Copyright (c) 2023 Irene Weber
MIT License (http://www.opensource.org/licenses/mit-license.php)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -->
<script type="text/html" data-template-name="setslots">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i>name</label>
<input type="text" id="node-input-name" >
</div>
<div class="form-row" id="node-once">
<label for="node-input-once">add from msg</label>
<input type="checkbox" id="node-input-addcheck" style="display:inline-block; width:15px; vertical-align:baseline;">
</div>
<div class="form-row" id="node-once">
<label for="node-input-once">send errors to catch node</label>
<input type="checkbox" id="node-input-senderr" style="display:inline-block; width:15px; vertical-align:baseline;">
</div>
<div class="form-row node-input-slot-container-row">
<ol id="node-input-slot-container"></ol>
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('setslots',{
color: "#baaff9",
category: 'rasaas',
defaults: {
name: {value:""},
text: {value:""},
addcheck: {value:false},
slots: {value:[{slotname:"", "slotname-type":null, slotvalue:"", "slotvalue-type":null }]},
senderr: {value:false}
},
inputs: 1,
outputs: 1,
icon: "font-awesome/fa-th-list",
label: function() {
return this.name||"setslots";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
var node = this;
var slots = node.slots;
$("#node-input-slot-container").css('min-height','100px').css('min-width','450px').editableList({
addslot: true,
header: $("<div>").append($.parseHTML("<div style='width:65%; display: inline-grid'>slot name</div><div style='display: inline-grid'>slot value</div>")),
addItem: function(row, index, data) {
var slt = {}
if (data.hasOwnProperty("slot")) {
slt.slotname = data.slot.slotname;
slt["slotname-type"] = data.slot["slotname-type"];
slt.slotvalue = data.slot.slotvalue;
slt["slotvalue-type"] = data.slot["slotvalue-type"];
} else {
slt.slotname = "";
slt.slotvalue = "";
slt["slotname-type"] = "str";
slt["slotvalue-type"] = "str";
}
row.css({
overflow: 'hidden',
whiteSpace: 'nowrap'
});
var slotnameField = $('<slotname/>',{class:"node-input-slot-slotname",type:"text",style: "margin-left: 5px; width:200px;"}).appendTo(row).typedInput({default:'str',types:['msg','str']});
slotnameField.typedInput('value', slt.slotname);
slotnameField.typedInput('type',slt["slotname-type"]);
var slotvalueField = $('<slotvalue/>',{class:"node-input-slot-slotvalue",type:"text",style:"width:200px; padding-right:10px; box-sizing:border-box;"}).appendTo(row).typedInput({default:'str',types:['msg','str']});
slotvalueField.typedInput('type',slt["slotvalue-type"]);
slotvalueField.typedInput('value', slt.slotvalue);
var finalspan = $('<span/>',{style:"float: right;margin-top: 6px;"}).appendTo(row);
},
sortable: true,
removable: true
});
for (var i=0;i<node.slots.length;i++) {
var slot = node.slots[i];
$("#node-input-slot-container").editableList('addItem',{slot:slot,i:i});
};
},
oneditsave: function() {
var node = this;
$("ol.node-input-slot-container").editableList('height', '200px');
var slts = $("#node-input-slot-container").editableList('items');
node.slots = [];
slts.each(function(i) {
var slt = $(this);
var s = {};
s.slotname = slt.find(".node-input-slot-slotname").typedInput('value');
s["slotname-type"] = slt.find(".node-input-slot-slotname").typedInput('type');
s.slotvalue = slt.find(".node-input-slot-slotvalue").typedInput('value');
s["slotvalue-type"] = slt.find(".node-input-slot-slotvalue").typedInput('type');
node.slots.push(s);
});
},
oneditresize: function(size) {
var rows = $("#dialog-form>div:not(.node-input-slot-container-row)");
var height = size.height;
for (var i=0;i<rows.length;i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-input-slot-container-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
height += 16;
$("#node-input-slot-container").editableList('height',height);
}
});
</script>
<script type="text/html" data-help-name="setslots">
<p>Sets Rasa slots to specific values.
<h3>Inputs</h3>
<dl class="message-properties">
<dt>msg.payload.slots
<span class="property-type">object</span>
</dt>
<dd> an array of objects <code>[{slotname:"name1", slotvalue:"value1"}, {slotname:"name2", slotvalue:"value2"} ]</code>, e.g., <code>[{slotname:"likes_music", slotvalue:true},{slotname:"mood", slotvalue: "happy"}] </dd>
</dl>
<h3>Outputs</h3>
<dl class="message-properties">
<dt>msg.events <span class="property-type">object</span></dt>
<dd>an array of objects <code>[{"event":"slot","timestamp":...,"name":"likes_music","value":true},{"event":"slot","timestamp":...,"name":"mood","value":"happy"}]</code></dd>
</dl>
<h3>Details</h3>
<p>Rasa slots are set via events. This nodes takes slot names and slot values and generates events
that set these slots to the values accordingly.</p>
There are three ways to provide slot names and values to the node:
<ul>
<li> specify fixed slot name and value pairs in the config of the node /li>
<li> specify in the node config how to retrieve slot name and value pairs from the msg object of the flow</li>
<li> provide an array of <code>{slotname:"name", slotvalue:"value"} </code>objects in the message payload </li>
</ul>
<p>The node adds the events to the events list that was initialized by <code>init</code> node and is
carried along the flow as <code>msg.events</code>.
The <code>finish</code> node will finally hand the events list over to Rasa chatbot. </p>
<p>There are no checks whether the slot names really exist in the Rasa domain or
whether there are multiple slot setting events for one slot.</p>
<p>
With Send errors to Catch node unchecked, the flow ignores errors in this node with a warning. For developping and debugging.
</p>
<h3>References</h3>
<ul>
<li><a href="https://rasa.com/docs/action-server/http-api-spec">Rasa Action Server HTTP API</a></li>
<li><a href="https://github.com/weberi/node-red-contrib-rasa-actionserver.git">GitHub</a> - the nodes github repository</li>
</ul>
</script>