forked from guidone/node-red-contrib-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatbot-message.html
138 lines (132 loc) · 4.31 KB
/
chatbot-message.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
<script type="text/javascript">
RED.nodes.registerType('chatbot-message', {
category: 'RedBot',
color: '#FFCC66',
defaults: {
name: {
value: ''
},
message: {
value: ['']
},
answer: {
value: false
},
track: {
value: false
},
parse_mode: {
value: ''
}
},
inputs: 1,
outputs: 1,
paletteLabel: 'Text',
icon: 'chatbot-message.png',
label: function() {
return this.name || 'Text';
},
oneditsave: function() {
var messages = $("#node-input-message-container").editableList('items');
var node = this;
node.message = [];
var idx;
for(idx = 0; idx < messages.length; idx++) {
node.message.push({
message: messages[idx].find('textarea').val()
});
}
},
oneditprepare: function() {
$('#node-input-message-container')
.css('min-height','300px')
.css('min-width','450px')
.editableList({
addButton: 'Add message version',
addItem: function (container, i, item) {
var row = $('<div/>').appendTo(container);
var content = '';
if (typeof item == 'string') {
content = item;
} else if (item.message != null) {
content = item.message;
}
$('<textarea placeholder="Message">' + content + '</textarea>')
.css({
width: '93%',
height: '100px'
})
.appendTo(row);
},
removable: true,
sortable: true
});
var message = this.message;
if (typeof message == 'string') {
message = [message];
}
var idx;
for (idx = 0; idx < message.length; idx++) {
$("#node-input-message-container").editableList('addItem', message[idx]);
}
}
});
</script>
<script type="text/x-red" data-template-name="chatbot-message">
<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">
</div>
<div class="form-row node-input-rule-container-row">
<ol id="node-input-message-container"></ol>
<div style="max-width: 460px;font-size: 12px;color: #999999;line-height: 14px;clear:both;margin-top:5px;">
Supports handlebars-like variables for chat context like {{firstName}}, {{lastName}}, etc. and emoticons (:smile:, etc.).
In case of multiple version of the content, one will be randomly chosen.
</div>
</div>
<div class="form-row">
<label for="node-input-answer"><i class="icon-share-alt"></i> Answer</label>
<input type="checkbox" value="true" id="node-input-answer">
<span style="max-width: 460px;font-size: 12px;color: #999999;line-height: 14px;">Quote the previous message <i>[Telegram]</i></span>
</div>
<div class="form-row">
<label for="node-input-parse_mode"><i class="icon-cog"></i> Parse</label>
<select id="node-input-parse_mode" placeholder="Select parse mode">
<option value="">None</option>
<option value="Markdown">Markdown</option>
<option value="HTML">HTML</option>
</select>
<div style="max-width: 460px;font-size: 12px;color: #999999;line-height: 14px;clear:both;margin-top:5px;">
Render the message with Markdown or HTML <i>[Telegram]</i>
</div>
</div>
</script>
<script type="text/x-red" data-help-name="chatbot-message">
<p>Plain text message with templating capabilities <em>[Telegram, Facebook, Smooch, Slack]</em></p>
<p>
Used to send a plain text message to the chatbot's user, a handlebars-like syntax can be used to insert values from the
chat context, for example:
<pre>
Hi {{firstName}}, your check is {{total}} euros
</pre>
Some <a href="https://github.com/guidone/node-red-contrib-chatbot#template-variables" target="_blank">special values</a> (like {{firstName}}, {{lastName}}, {{chatId}}, etc) are always available.
</p>
<p>
It's possible to specify more content versions for the same message, one will we randomly chosen with an even distribution.
</p>
<p>
The text message can be passed through the payload by the upstream node:
</p>
<pre>
msg.payload = 'I am a message';
return msg;
</pre>
or for multiple versions of the message
<pre>
msg.payload = [
'First version of the message',
'Second version of the message'
];
return msg;
</pre>
</script>