forked from guidone/node-red-contrib-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatbot-topic.html
107 lines (101 loc) · 3.67 KB
/
chatbot-topic.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
<script type="text/javascript">
RED.nodes.registerType('chatbot-topic', {
category: 'RedBot Flow',
color: '#FFCC66',
defaults: {
rules: {
value: [{topic: ''}]
},
outputs: {
value: 1
}
},
inputs: 1,
outputs: 1,
paletteLabel: 'Topic',
icon: 'chatbot-topic.png',
label: function() {
return 'Topic';
},
oneditsave: function() {
var rules = $('#node-input-rule-container').editableList('items');
var node = this;
node.rules = [];
rules.each(function(i) {
var rule = $(this);
var topic = rule.find('input').val();
if (topic != null && topic != '') {
node.rules.push({topic: topic});
}
});
this.outputs = node.rules.length;
},
oneditprepare: function() {
var node = this;
$("#node-input-rule-container").css('min-height','250px').css('min-width','450px').editableList({
addItem: function (container, i, opt) {
var rule = opt;
var row = $('<div/>').appendTo(container);
var selectField = $('<input/>', {style:"width:80%; margin-left: 5px; text-align: left;"})
.attr('placeholder', 'Insert topic')
.attr('type', 'text')
.appendTo(row);
if (rule.topic != null) {
selectField.val(rule.topic);
}
var finalspan = $('<span/>',{style:"float: right;margin-top: 6px;"}).appendTo(row);
finalspan.append(' → <span class="node-input-rule-index">' + (i + 1) + '</span>');
},
removeItem: function(opt) {
var rules = $('#node-input-rule-container').editableList('items');
rules.each(function(i) {
$(this).find('.node-input-rule-index').html(i + 1);
});
},
sortItems: function() {
var rules = $('#node-input-rule-container').editableList('items');
rules.each(function(i) {
$(this).find('.node-input-rule-index').html(i + 1);
});
},
sortable: true,
removable: true
});
for (var i=0; i < node.rules.length; i++) {
var rule = this.rules[i];
$('#node-input-rule-container').editableList('addItem', rule);
}
}
});
</script>
<script type="text/x-red" data-template-name="chatbot-topic">
<div class="form-row">
<label for="node-input-name" style="width:100%;"><i class="fa fa-tag"></i> Forward message based on topic:</label>
</div>
<div class="form-row node-input-rule-container-row">
<ol id="node-input-rule-container"></ol>
</div>
<div style="max-width: 460px;font-size: 12px;color: #999999;line-height: 14px;clear:both;margin-top:5px;">
Insert the topic to match (or a comma delimited list of topics).<br>
The first matched topic skips the rest of the matching strings. To get a else-like behaviour, use a <code>*</code>
at the end of the list to capture all messages that don't match any topic.
</p>
</div>
</script>
<script type="text/x-red" data-help-name="chatbot-topic">
<p>
Control the flow based on the topic. Use the topic to restrict the working area of your bot's parsers based on
the user intentions.
</p>
<p>
The first matched topic skips the rest of the matching strings. To get a else-like behaviour, use a <code>*</code>
at the end of the list to capture all messages that don't match any topic.
</p>
<p>
Chat topic is stored in the chat context <em>"topic"</em>, use the <code>Context node</code> to change it or the
<code>{topic=my_topic}</code> directive in <em>RiveScript</em>.
</p>
<p>
The chat context could have more than one topic (in that case is an array of string).
</p>
</script>