-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.html
More file actions
312 lines (290 loc) · 12.4 KB
/
matrix.html
File metadata and controls
312 lines (290 loc) · 12.4 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<!-- Config Node "matrix-server" -->
<script type="text/javascript">
RED.nodes.registerType('matrix-server',{
category: 'config',
defaults: {
name: {type:"text"},
server: {type:"text",value:"http://localhost:8008",required:true},
token: {type:"text",required:true},
userid: {type:"text",required:true},
room: {type:"text"},
},
label: function() {
return this.name;
},
oneditprepare: function() {
$("#node-config-input-generate").click(function() {
var server = $("#node-config-input-server").val();
var user = $("#node-config-input-user").val();
var pass = $("#node-config-input-pass").val();
var r = new XMLHttpRequest();
r.open('POST', server + '/_matrix/client/r0/login', true);
r.onload = function() {
console.log(this.responseText);
var res = JSON.parse(this.responseText);
if (res.error) {
RED.notify("Error: " + res["error"]);
} else if (res.access_token) {
$("#node-config-input-token").val(res["access_token"]);
$("#node-config-input-userid").val(res["user_id"]);
}
}
r.send(' {"type":"m.login.password", "user":"' + user + '", "password":"' + pass + '", "initial_device_display_name":"NodeRed Bot Node"}');
});
}
});
</script>
<script type="text/x-red" data-template-name="matrix-server">
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-config-input-name">
</div>
<div class="form-row">
<label for="node-config-input-server"><i class="fa fa-globe"></i> Server</label>
<input type="text" id="node-config-input-server">
</div>
<hr align="middle">
<div class="form-row">
<i class="fa fa-wrench"></i> Generate Token
</div>
<div class="form-row">
<label for="node-config-input-user"><i class="fa fa-user"></i> Username</label>
<input type="text" id="node-config-input-user">
<label for="node-config-input-pass"><i class="fa fa-lock"></i> Password</label>
<input type="text" id="node-config-input-pass">
<button type="button" id="node-config-input-generate" class="red-ui-button"><i class='fa fa-refresh'></i></button>
</div>
<hr align="middle">
<div class="form-row">
<label for="node-config-input-userid"><i class="fa fa-user"></i> UserId</label>
<input type="text" id="node-config-input-userid">
</div>
<div class="form-row">
<label for="node-config-input-token"><i class="fa fa-tag"></i> Token</label>
<input type="text" id="node-config-input-token">
</div>
<div class="form-row">
<label for="node-config-input-room"><i class="fa fa-tag"></i> Default Room</label>
<input type="text" id="node-config-input-room">
</div>
</script>
<script type="text/x-red" data-help-name="matrix-server">
<h2>Matrix server configuration</h2>
<h3>The configuration of your matrix homeserver</h3>
<p>The configuration needs a server URL, a userid and an access token:</p>
<dl class="message-properties">
<dt>server<span class="property-type">string</span></dt>
<dd>the matrix server URL to connect to.</dd>
<dt>userid<span class="property-type">string</span></dt>
<dd>the matrix id of the user. Usually @user:server.</dd>
<dt>token<span class="property-type">string</span></dt>
<dd>the access token.</dd>
</dl>
<p>If your server supports logging in useing userid and password, you can fill in
server, user and password and press the generate button. This will make your browser
log in to your matrix account and pull matrix id and access token automatically.</p>
<p>Optionally, a default room might be specified:</p>
<dl class="message-properties">
<dt>room<span class="property-type">string</span></dt>
<dd>default matrix room to use.</dd>
</dl>
</script>
<!-- INPUT Node "matrix-input" -->
<script type="text/javascript">
RED.nodes.registerType('matrix-input',{
category: 'function',
color: '#a6bbcf',
defaults: {
name: {value:""},
room: {value:""},
server: {value:"", type:"matrix-server"},
filterself: {value:true}
},
inputs:0,
outputs:1,
icon: "matrix.png",
label: function() {
return this.name||"matrix-input";
}
});
</script>
<script type="text/x-red" data-template-name="matrix-input">
<div class="form-row">
<label for="node-input-server"><i class="fa fa-globe"></i> Server</label>
<input type="text" id="node-input-server" placeholder="Server">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-room"><i class="fa fa-tag"></i> Room</label>
<input type="text" id="node-input-room" placeholder="Room">
</div>
<input type="checkbox" id="node-input-filterself" placeholder="Filterself"> Filter events sent by self
</script>
<script type="text/x-red" data-help-name="matrix-input">
<h2>Matrix input node</h2>
<h3>This node receives matrix events of type org.nodered.msg and emits the content as a node-red msg.</h3>
<p>The configuration has there parameters:</p>
<dl class="message-properties">
<dt>server<span class="property-type">matrix server configuration</span></dt>
<dd>the matrix server URL to connect to.</dd>
<dt>name<span class="property-type">string</span></dt>
<dd>the name of the node.</dd>
<dt>room<span class="property-type">string</span></dt>
<dd>the room to receive messages from. If empty, all rooms are used the matrix user has joined.</dd>
<dt>Events sent by self<span class="property-type">boolean</span></dt>
<dd>If uncheked, the node will receive its own messages.</dd>
</dl>
</script>
<!-- INPUT Node "matrix-recvtext" -->
<script type="text/javascript">
RED.nodes.registerType('matrix-recvtext',{
category: 'function',
color: '#a6bbcf',
defaults: {
name: {value:""},
room: {value:""},
server: {value:"", type:"matrix-server"},
filterself: {value:true}
},
inputs:0,
outputs:1,
icon: "matrix.png",
label: function() {
return this.name||"matrix-recvtext";
}
});
</script>
<script type="text/x-red" data-template-name="matrix-recvtext">
<div class="form-row">
<label for="node-input-server"><i class="fa fa-globe"></i> Server</label>
<input type="text" id="node-input-server" placeholder="Server">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-room"><i class="fa fa-tag"></i> Room</label>
<input type="text" id="node-input-room" placeholder="Room">
</div>
<input type="checkbox" id="node-input-filterself" placeholder="Filterself"> Filter events sent by self
</script>
<script type="text/x-red" data-help-name="matrix-recvtext">
<h2>Matrix receive text node</h2>
<h3>This node receives messages of type m.text and emits the content is a node-red msg.payload</h3>
<p>The configuration has there parameters:</p>
<dl class="message-properties">
<dt>server<span class="property-type">matrix server configuration</span></dt>
<dd>the matrix server URL to connect to.</dd>
<dt>name<span class="property-type">string</span></dt>
<dd>the name of the node.</dd>
<dt>room<span class="property-type">string</span></dt>
<dd>the room to receive messages from. If empty, all rooms are used the matrix user has joined.</dd>
<dt>Events sent by self<span class="property-type">boolean</span></dt>
<dd>If uncheked, the node will receive its own messages.</dd>
</dl>
</script>
<!-- OUTPUT Node "matrix-output" -->
<script type="text/javascript">
RED.nodes.registerType('matrix-output',{
category: 'function',
color: '#a6bbcf',
defaults: {
name: {value:""},
room: {value:""},
server: {value:"", type:"matrix-server"}
},
inputs:1,
outputs:0,
icon: "matrix.png",
label: function() {
return this.name||"matrix-output";
}
});
</script>
<script type="text/x-red" data-template-name="matrix-output">
<div class="form-row">
<label for="node-input-server"><i class="fa fa-globe"></i> Server</label>
<input type="text" id="node-input-server" placeholder="Server">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-room"><i class="fa fa-tag"></i> Room</label>
<input type="text" id="node-input-room" placeholder="Room">
</div>
</script>
<script type="text/x-red" data-help-name="matrix-output">
<h2>Matrix output node</h2>
<h3>This node sends node-red msg messages to matrix as content of org.nodered.msg matrix events.</h3>
<p>The configuration has there parameters:</p>
<dl class="message-properties">
<dt>server<span class="property-type">matrix server configuration</span></dt>
<dd>the matrix server URL to connect to.</dd>
<dt>name<span class="property-type">string</span></dt>
<dd>the name of the node.</dd>
<dt>room<span class="property-type">string</span></dt>
<dd>the room to send messages to. If empty, the default room will be used. If this is empty, too, the message won't be sent.</dd>
</dl>
</script>
<!-- OUTPUT Node "matrix-sendtext" -->
<script type="text/javascript">
RED.nodes.registerType('matrix-sendtext',{
category: 'function',
color: '#a6bbcf',
defaults: {
name: {value:""},
room: {value:""},
server: {value:"", type:"matrix-server"},
notice: {value:true}
},
inputs:1,
outputs:0,
icon: "matrix.png",
label: function() {
return this.name||"matrix-sendtext";
}
});
</script>
<script type="text/x-red" data-template-name="matrix-sendtext">
<div class="form-row">
<label for="node-input-server"><i class="fa fa-globe"></i> Server</label>
<input type="text" id="node-input-server" placeholder="Server">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-room"><i class="fa fa-tag"></i> Room</label>
<input type="text" id="node-input-room" placeholder="Room">
</div>
<input type="checkbox" id="node-input-notice" placeholder="Notice"> Send Text as m.notice (silent)
</script>
<script type="text/x-red" data-help-name="matrix-sendtext">
<h2>Matrix send text node</h2>
<h3>This node sends messages to matrix as m.text matrix events.</h3>
<p>The configuration has there parameters:</p>
<dl class="message-properties">
<dt>server<span class="property-type">matrix server configuration</span></dt>
<dd>the matrix server URL to connect to.</dd>
<dt>name<span class="property-type">string</span></dt>
<dd>the name of the node.</dd>
<dt>room<span class="property-type">string</span></dt>
<dd>the room to send messages to. The order to choose the room to send message to is:
<ul>
<dd>msg.roomId</dd>
<dd>The room specified here</dd>
<dd>The default room specified in the server</dd>
</ul>
If no room can be found, the message won't be sent.
</dd>
<dt>send text as m.notice<span class="property-type">boolean</span></dt>
<dd>Use m.notice sub type to send messages silent</dd>
</dl>
</script>