mirror of
https://github.com/Skylar-Tech/node-red-contrib-matrix-chat.git
synced 2025-04-20 13:03:12 -06:00
- Reduce margin between checkboxes for matrix-receive node
- matrix-send-message node can now be used to reply in a thread (closes #104) - matrix-receive node now returns msg.mentions for easier access to who was mentioned in message - matrix-receive node now returns boolean msg.isThread based on whether the message is a thread reply or not
This commit is contained in:
parent
fd174e32ff
commit
000c28e3b8
@ -45,7 +45,7 @@
|
|||||||
<div class="form-row" style="margin-left: 100px;margin-top:10px;font-weight:bold;">
|
<div class="form-row" style="margin-left: 100px;margin-top:10px;font-weight:bold;">
|
||||||
Timeline event filters
|
Timeline event filters
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row" style="margin-bottom:0;">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id="node-input-acceptText"
|
id="node-input-acceptText"
|
||||||
@ -55,7 +55,7 @@
|
|||||||
Accept text <code style="text-transform: none;">m.text</code>
|
Accept text <code style="text-transform: none;">m.text</code>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row" style="margin-bottom:0;">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id="node-input-acceptEmotes"
|
id="node-input-acceptEmotes"
|
||||||
@ -65,7 +65,7 @@
|
|||||||
Accept emotes <code style="text-transform: none;">m.emote</code>
|
Accept emotes <code style="text-transform: none;">m.emote</code>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row" style="margin-bottom:0;">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id="node-input-acceptStickers"
|
id="node-input-acceptStickers"
|
||||||
@ -75,7 +75,7 @@
|
|||||||
Accept stickers <code style="text-transform: none;">m.sticker</code>
|
Accept stickers <code style="text-transform: none;">m.sticker</code>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row" style="margin-bottom:0;">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id="node-input-acceptReactions"
|
id="node-input-acceptReactions"
|
||||||
@ -85,7 +85,7 @@
|
|||||||
Accept reactions <code style="text-transform: none;">m.reaction</code>
|
Accept reactions <code style="text-transform: none;">m.reaction</code>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row" style="margin-bottom:0;">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id="node-input-acceptFiles"
|
id="node-input-acceptFiles"
|
||||||
@ -95,7 +95,7 @@
|
|||||||
Accept files <code style="text-transform: none;">m.file</code>
|
Accept files <code style="text-transform: none;">m.file</code>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row" style="margin-bottom:0;">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id="node-input-acceptAudio"
|
id="node-input-acceptAudio"
|
||||||
@ -105,7 +105,7 @@
|
|||||||
Accept files <code style="text-transform: none;">m.audio</code>
|
Accept files <code style="text-transform: none;">m.audio</code>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row" style="margin-bottom:0;">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id="node-input-acceptImages"
|
id="node-input-acceptImages"
|
||||||
@ -115,7 +115,7 @@
|
|||||||
Accept images <code style="text-transform: none;">m.image</code>
|
Accept images <code style="text-transform: none;">m.image</code>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row" style="margin-bottom:0;">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id="node-input-acceptVideos"
|
id="node-input-acceptVideos"
|
||||||
@ -125,7 +125,7 @@
|
|||||||
Accept videos <code style="text-transform: none;">m.video</code>
|
Accept videos <code style="text-transform: none;">m.video</code>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row" style="margin-bottom:0;">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id="node-input-acceptLocations"
|
id="node-input-acceptLocations"
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
const {RelationType} = require("matrix-js-sdk");
|
||||||
module.exports = function(RED) {
|
module.exports = function(RED) {
|
||||||
function MatrixReceiveMessage(n) {
|
function MatrixReceiveMessage(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
outputLabels: ["success", "error"],
|
outputLabels: ["success", "error"],
|
||||||
inputs:1,
|
inputs:1,
|
||||||
outputs:2,
|
outputs:2,
|
||||||
|
paletteLabel: 'Send Message',
|
||||||
defaults: {
|
defaults: {
|
||||||
name: { value: null },
|
name: { value: null },
|
||||||
server: { type: "matrix-server-config" },
|
server: { type: "matrix-server-config" },
|
||||||
@ -13,12 +14,24 @@
|
|||||||
message: { value: null },
|
message: { value: null },
|
||||||
messageType: { value: 'm.text' },
|
messageType: { value: 'm.text' },
|
||||||
messageFormat: { value: '' },
|
messageFormat: { value: '' },
|
||||||
replaceMessage : { value: false }
|
replaceMessage : { value: false },
|
||||||
|
threadReplyType: { value: "msg" },
|
||||||
|
threadReplyValue: { value: "isThread" },
|
||||||
},
|
},
|
||||||
label: function() {
|
label: function() {
|
||||||
return this.name || "Send Message";
|
return this.name || "Send Message";
|
||||||
},
|
},
|
||||||
paletteLabel: 'Send Message'
|
oneditprepare: function() {
|
||||||
|
$("#node-input-threadReply").typedInput({
|
||||||
|
types:['msg','flow','global','bool'],
|
||||||
|
})
|
||||||
|
.typedInput('value', this.threadReplyValue || "isThread")
|
||||||
|
.typedInput('type', this.threadReplyType || "msg");
|
||||||
|
},
|
||||||
|
oneditsave: function() {
|
||||||
|
this.threadReplyType = $("#node-input-threadReply").typedInput('type');
|
||||||
|
this.threadReplyValue = $("#node-input-threadReply").typedInput('value');
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -72,6 +85,11 @@
|
|||||||
It's recommended to use m.notice for bots because the message will render in a lighter text (at least in Element client) for users to distinguish bot and real user messages.
|
It's recommended to use m.notice for bots because the message will render in a lighter text (at least in Element client) for users to distinguish bot and real user messages.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-threadReply"><i class="fa fa-commenting-o"></i> Thread Reply</label>
|
||||||
|
<input type="text" id="node-input-threadReply">
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-messageFormat">
|
<label for="node-input-messageFormat">
|
||||||
Message Format
|
Message Format
|
||||||
|
@ -13,6 +13,8 @@ module.exports = function(RED) {
|
|||||||
this.messageFormat = n.messageFormat;
|
this.messageFormat = n.messageFormat;
|
||||||
this.replaceMessage = n.replaceMessage;
|
this.replaceMessage = n.replaceMessage;
|
||||||
this.message = n.message;
|
this.message = n.message;
|
||||||
|
this.threadReplyType = n.threadReplyType || null;
|
||||||
|
this.threadReplyValue = n.threadReplyValue || null;
|
||||||
|
|
||||||
// taken from https://github.com/matrix-org/synapse/blob/master/synapse/push/mailer.py
|
// taken from https://github.com/matrix-org/synapse/blob/master/synapse/push/mailer.py
|
||||||
this.allowedTags = [
|
this.allowedTags = [
|
||||||
@ -67,8 +69,27 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
node.on("input", function (msg) {
|
node.on("input", function (msg) {
|
||||||
|
function getToValue(msg, type, property) {
|
||||||
|
let value = property;
|
||||||
|
if (type === "msg") {
|
||||||
|
value = RED.util.getMessageProperty(msg, property);
|
||||||
|
} else if ((type === 'flow') || (type === 'global')) {
|
||||||
|
try {
|
||||||
|
value = RED.util.evaluateNodeProperty(property, type, node, msg);
|
||||||
|
} catch(e2) {
|
||||||
|
throw new Error("Invalid value evaluation");
|
||||||
|
}
|
||||||
|
} else if(type === "bool") {
|
||||||
|
value = (property === 'true');
|
||||||
|
} else if(type === "num") {
|
||||||
|
value = Number(property);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
let msgType = node.messageType,
|
let msgType = node.messageType,
|
||||||
msgFormat = node.messageFormat;
|
msgFormat = node.messageFormat,
|
||||||
|
threadReply = getToValue(msg, node.threadReplyType, node.threadReplyValue);
|
||||||
|
|
||||||
if (!node.server || !node.server.matrixClient) {
|
if (!node.server || !node.server.matrixClient) {
|
||||||
node.warn("No matrix server selected");
|
node.warn("No matrix server selected");
|
||||||
@ -143,6 +164,25 @@ module.exports = function(RED) {
|
|||||||
event_id: msg.eventId
|
event_id: msg.eventId
|
||||||
};
|
};
|
||||||
content['body'] = ' * ' + content['body'];
|
content['body'] = ' * ' + content['body'];
|
||||||
|
} else if(threadReply) {
|
||||||
|
// if incoming message is a reply to a thread we fetch the thread parent from the m.relates_to property
|
||||||
|
// otherwise fallback to msg.eventId
|
||||||
|
console.log(msg);
|
||||||
|
console.log(msg?.content?.['m.relates_to']?.rel_type);
|
||||||
|
console.log(msg?.content?.['m.relates_to']?.event_id);
|
||||||
|
let threadParent = (msg?.content?.['m.relates_to']?.rel_type === RelationType.Thread ? msg?.content?.['m.relates_to']?.event_id : null) || msg.eventId;
|
||||||
|
if(threadParent) {
|
||||||
|
content["m.relates_to"] = {
|
||||||
|
"rel_type": RelationType.Thread,
|
||||||
|
"event_id": threadParent,
|
||||||
|
"is_falling_back": true,
|
||||||
|
};
|
||||||
|
if(msg.eventId !== threadParent) {
|
||||||
|
content["m.relates_to"]["m.in_reply_to"] = {
|
||||||
|
"event_id": msg.eventId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
const {RelationType} = require("matrix-js-sdk");
|
||||||
|
|
||||||
global.Olm = require('olm');
|
global.Olm = require('olm');
|
||||||
const fs = require("fs-extra");
|
const fs = require("fs-extra");
|
||||||
const sdk = require("matrix-js-sdk");
|
const sdk = require("matrix-js-sdk");
|
||||||
@ -225,16 +227,18 @@ module.exports = function(RED) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let msg = {
|
let msg = {
|
||||||
encrypted : event.isEncrypted(),
|
encrypted : event.isEncrypted(),
|
||||||
redacted : event.isRedacted(),
|
redacted : event.isRedacted(),
|
||||||
content : event.getContent(),
|
content : event.getContent(),
|
||||||
type : (event.getContent()['msgtype'] || event.getType()) || null,
|
type : (event.getContent()['msgtype'] || event.getType()) || null,
|
||||||
payload : (event.getContent()['body'] || event.getContent()) || null,
|
payload : (event.getContent()['body'] || event.getContent()) || null,
|
||||||
isDM : isDmRoom(room),
|
isDM : isDmRoom(room),
|
||||||
userId : event.getSender(),
|
isThread : event.getContent()?.['m.relates_to']?.rel_type === RelationType.Thread,
|
||||||
topic : event.getRoomId(),
|
mentions : event.getContent()["m.mentions"] || null,
|
||||||
eventId : event.getId(),
|
userId : event.getSender(),
|
||||||
event : event
|
topic : event.getRoomId(),
|
||||||
|
eventId : event.getId(),
|
||||||
|
event : event,
|
||||||
};
|
};
|
||||||
|
|
||||||
node.log("Received" + (msg.encrypted ? ' encrypted' : '') +" timeline event [" + msg.type + "]: (" + room.name + ") " + event.getSender() + " :: " + msg.content.body + (toStartOfTimeline ? ' [PAGINATED]' : ''));
|
node.log("Received" + (msg.encrypted ? ' encrypted' : '') +" timeline event [" + msg.type + "]: (" + room.name + ") " + event.getSender() + " :: " + msg.content.body + (toStartOfTimeline ? ' [PAGINATED]' : ''));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user