commit
73d802ff0d
1275
package-lock.json
generated
1275
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-contrib-matrix-chat",
|
"name": "node-red-contrib-matrix-chat",
|
||||||
"version": "0.2.1",
|
"version": "0.2.4",
|
||||||
"description": "Matrix chat server client for Node-RED",
|
"description": "Matrix chat server client for Node-RED",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fs-extra": "^9.1.0",
|
"fs-extra": "^9.1.0",
|
||||||
@ -8,7 +8,8 @@
|
|||||||
"isomorphic-webcrypto": "^2.3.8",
|
"isomorphic-webcrypto": "^2.3.8",
|
||||||
"matrix-js-sdk": "^12.2.0",
|
"matrix-js-sdk": "^12.2.0",
|
||||||
"node-localstorage": "^2.2.1",
|
"node-localstorage": "^2.2.1",
|
||||||
"olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz",
|
"olm": "https://packages.matrix.org/npm/olm/olm-3.2.1.tgz",
|
||||||
|
"process": "^0.11.10",
|
||||||
"utf8": "^3.0.0"
|
"utf8": "^3.0.0"
|
||||||
},
|
},
|
||||||
"node-red": {
|
"node-red": {
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
<dt class="optional">msg.payload
|
<dt class="optional">msg.payload
|
||||||
<span class="property-type">string | object | null</span>
|
<span class="property-type">string | object | null</span>
|
||||||
</dt>
|
</dt>
|
||||||
<dd> a list of options to pass to the /createRoom API. <a href="https://matrix.org/docs/spec/client_server/r0.4.0#id266">Click here</a> for information about what can be passed. If this is a string it just sets the room name and ignores other options.</dd>
|
<dd> a list of options to pass to the /createRoom API. <a href="https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-createroom">Click here</a> for information about what can be passed. If this is a string it just sets the room name and ignores other options.</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
<h3>Outputs</h3>
|
<h3>Outputs</h3>
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
outputs: 2,
|
outputs: 2,
|
||||||
defaults: {
|
defaults: {
|
||||||
name: { value: null },
|
name: { value: null },
|
||||||
server: { value: "", type: "matrix-server-config" }
|
server: { value: "", type: "matrix-server-config" },
|
||||||
|
roomId: { value: null },
|
||||||
},
|
},
|
||||||
label: function() {
|
label: function() {
|
||||||
return this.name || "Room Invite";
|
return this.name || "Room Invite";
|
||||||
@ -27,6 +28,11 @@
|
|||||||
<label for="node-input-server"><i class="fa fa-user"></i> Matrix Server Config</label>
|
<label for="node-input-server"><i class="fa fa-user"></i> Matrix Server Config</label>
|
||||||
<input type="text" id="node-input-server">
|
<input type="text" id="node-input-server">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-roomId"><i class="fa fa-user"></i> Room ID</label>
|
||||||
|
<input type="text" id="node-input-roomId" placeholder="msg.topic">
|
||||||
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/html" data-help-name="matrix-invite-room">
|
<script type="text/html" data-help-name="matrix-invite-room">
|
||||||
|
@ -6,6 +6,7 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
this.name = n.name;
|
this.name = n.name;
|
||||||
this.server = RED.nodes.getNode(n.server);
|
this.server = RED.nodes.getNode(n.server);
|
||||||
|
this.roomId = n.roomId;
|
||||||
|
|
||||||
if(!this.server) {
|
if(!this.server) {
|
||||||
node.error('Server must be configured on the node.');
|
node.error('Server must be configured on the node.');
|
||||||
@ -47,7 +48,7 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
msg.topic = node.roomId || msg.topic;
|
msg.topic = node.roomId || msg.topic;
|
||||||
if(!msg.topic) {
|
if(!msg.topic) {
|
||||||
node.error("msg.topic must be defined or configured on the node.");
|
node.error("room must be defined in either msg.topic or in node config");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-contentType"><i class="fa fa-user"></i> Content-Type</label>
|
<label for="node-input-contentType"><i class="fa fa-user"></i> Content-Type</label>
|
||||||
<input type="text" id="node-input-contentType" placeholder="application/png">
|
<input type="text" id="node-input-contentType" placeholder="msg.contentType">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-tips">
|
<div class="form-tips">
|
||||||
Must be a valid <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types" target="_blank">MIME Type</a> (ex: image/png) or left empty
|
Must be a valid <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types" target="_blank">MIME Type</a> (ex: image/png) or left empty
|
||||||
|
@ -109,7 +109,10 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
if(msgFormat === 'html') {
|
if(msgFormat === 'html') {
|
||||||
content.format = "org.matrix.custom.html";
|
content.format = "org.matrix.custom.html";
|
||||||
content.formatted_body = msg.formatted_payload || msg.payload;
|
content.formatted_body =
|
||||||
|
(typeof msg.formatted_payload !== 'undefined' && msg.formatted_payload)
|
||||||
|
? msg.formatted_payload.toString()
|
||||||
|
: msg.payload.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
node.server.matrixClient.sendMessage(msg.topic, content)
|
node.server.matrixClient.sendMessage(msg.topic, content)
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
id="node-config-input-autoAcceptRoomInvites"
|
id="node-config-input-autoAcceptRoomInvites"
|
||||||
style="width: auto; margin-left: 125px; vertical-align: top"
|
style="width: auto; margin-left: 125px; vertical-align: top"
|
||||||
/>
|
/>
|
||||||
<label for="node-config-input-autoAcceptRoomInvites" style="width: auto">
|
<label for="node-config-input-autoAcceptRoomInvites" style="width: auto;max-width:50%;">
|
||||||
Auto join invited rooms
|
Auto join invited rooms
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
@ -64,13 +64,10 @@
|
|||||||
id="node-config-input-enableE2ee"
|
id="node-config-input-enableE2ee"
|
||||||
style="width: auto; margin-left: 125px; vertical-align: top"
|
style="width: auto; margin-left: 125px; vertical-align: top"
|
||||||
/>
|
/>
|
||||||
<label for="node-config-input-enableE2ee" style="width: auto">
|
<label for="node-config-input-enableE2ee" style="width: auto;max-width:50%;">
|
||||||
Enable end-to-end encryption (requires DeviceID)
|
Enable end-to-end encryption (requires a Device ID to be set.)
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-tips" style="margin-bottom: 12px;">
|
|
||||||
E2ee requires a Device ID to be set.
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<input
|
<input
|
||||||
@ -82,13 +79,23 @@
|
|||||||
Global access to Matrix Client
|
Global access to Matrix Client
|
||||||
</label>
|
</label>
|
||||||
<div class="form-tips" style="margin-bottom: 12px;">
|
<div class="form-tips" style="margin-bottom: 12px;">
|
||||||
If enabled this allows you to access the matrix client directly with a Function node. This way you can do whatever you want with the client.<br />
|
If enabled this allows you to access the matrix client directly with a Function node. This way you can do <a href="https://github.com/Skylar-Tech/node-red-contrib-matrix-chat/tree/master/examples#use-function-node-to-run-any-command" target="_blank">whatever you want</a> with the client. Example:<br>
|
||||||
Example: <code>let client = global.get("matrixClient['@bot:example.com']")</code>
|
<code style="white-space: normal;">let client = global.get("matrixClient['@bot:example.com']");</code>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/html" data-help-name="matrix-server-config">
|
<script type="text/html" data-help-name="matrix-server-config">
|
||||||
<h3>Details</h3>
|
<h3>Details</h3>
|
||||||
<p>Matrix client configuration node</p>
|
<p>Matrix client connection configuration</p>
|
||||||
|
|
||||||
|
<h3>Setting up an account</h3>
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
You need an account for your client to use. If you are going to be using End-to-End Encryption you should generate the bot and only use it within Node-RED otherwise if you have other clients connected on the same user it could cause problems with e2ee (key sharing is currently not supported).
|
||||||
|
</p>
|
||||||
|
<p>If you have access to the server directly you can use Shared Secret Registration as described <a href="https://github.com/Skylar-Tech/node-red-contrib-matrix-chat/tree/master/examples#create-user-with-shared-secret-registration" target="_blank" style="text-decoration: underline;">here</a>.</p>
|
||||||
|
<p>If this is a server you do not administrate/have access to follow these instructions:</p>
|
||||||
|
<ol><li>In a private/incognito browser window, open Element.</li><li>Log in to the account you want to get the access token for, such as the bot's account. <strong>Do not setup key storage</strong>.</li><li>Click on the bot's name in the top left corner then "Settings".</li><li>(Optional) Set your bot's display name and avatar.</li><li>Click the "Help & About" tab (left side of the dialog).</li><li>Scroll to the bottom and click the <code><click to reveal></code> part of <code>Access Token: <click to reveal></code>.</li><li>Copy your access token to a safe place, like the bot's configuration file.</li><li><strong>Do not log out.</strong> Instead, just close the window. If you used a private browsing session, you should be able to still use Element for your own account. Logging out deletes the access token from the server, making the bot unable to use it.</li></ol>
|
||||||
|
</div>
|
||||||
</script>
|
</script>
|
@ -43,9 +43,13 @@ module.exports = function(RED) {
|
|||||||
} else if(!this.userId) {
|
} else if(!this.userId) {
|
||||||
node.log("Matrix connection failed: missing user ID.");
|
node.log("Matrix connection failed: missing user ID.");
|
||||||
} else {
|
} else {
|
||||||
node.setConnected = function(connected) {
|
node.setConnected = function(connected, cb) {
|
||||||
if (node.connected !== connected) {
|
if (node.connected !== connected) {
|
||||||
node.connected = connected;
|
node.connected = connected;
|
||||||
|
if(typeof cb === 'function') {
|
||||||
|
cb(connected);
|
||||||
|
}
|
||||||
|
|
||||||
if (connected) {
|
if (connected) {
|
||||||
node.log("Matrix server connection ready.");
|
node.log("Matrix server connection ready.");
|
||||||
node.emit("connected");
|
node.emit("connected");
|
||||||
@ -131,20 +135,27 @@ module.exports = function(RED) {
|
|||||||
node.matrixClient.on("sync", async function(state, prevState, data) {
|
node.matrixClient.on("sync", async function(state, prevState, data) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case "ERROR":
|
case "ERROR":
|
||||||
node.error("Connection to Matrix server lost");
|
node.setConnected(false, function(){
|
||||||
node.setConnected(false);
|
node.error("Connection to Matrix server lost");
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "RECONNECTING":
|
case "RECONNECTING":
|
||||||
|
node.setConnected(false, function(){
|
||||||
|
node.log("Trying to reconnect to matrix server");
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "STOPPED":
|
case "STOPPED":
|
||||||
node.setConnected(false);
|
node.setConnected(false, function(){
|
||||||
|
node.log("Matrix client stopped");
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "SYNCING":
|
case "SYNCING":
|
||||||
break;
|
|
||||||
|
|
||||||
case "PREPARED":
|
case "PREPARED":
|
||||||
node.setConnected(true);
|
node.setConnected(true, function(){
|
||||||
|
node.log("Matrix client connected");
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// case "PREPARED":
|
// case "PREPARED":
|
||||||
|
@ -64,7 +64,7 @@ module.exports = function(RED) {
|
|||||||
'POST',
|
'POST',
|
||||||
node.encodeUri(
|
node.encodeUri(
|
||||||
"/_synapse/admin/v1/join/$room_id_or_alias",
|
"/_synapse/admin/v1/join/$room_id_or_alias",
|
||||||
{ $room_id_or_alias: roomId },
|
{ $room_id_or_alias: msg.topic },
|
||||||
),
|
),
|
||||||
undefined,
|
undefined,
|
||||||
{ "user_id": msg.userId },
|
{ "user_id": msg.userId },
|
||||||
|
@ -39,7 +39,7 @@ module.exports = function(RED) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if(msg.guests) {
|
if(msg.guests) {
|
||||||
queryParams['guests'] = msg.guests;
|
queryParams['guests'] = msg.guests ? 'true' : 'false';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(msg.order_by) {
|
if(msg.order_by) {
|
||||||
|
Loading…
Reference in New Issue
Block a user