- New option for matrix-send-message node that allows replacing existing message if enabled and `msg.eventId` is passed in.
This commit is contained in:
2022-03-17 15:37:10 -06:00
parent 27dd4d81a2
commit 380e548425
2 changed files with 40 additions and 1 deletions
+22
View File
@@ -1,3 +1,5 @@
const {RelationType} = require("matrix-js-sdk");
module.exports = function(RED) {
function MatrixSendImage(n) {
RED.nodes.createNode(this, n);
@@ -9,6 +11,7 @@ module.exports = function(RED) {
this.roomId = n.roomId;
this.messageType = n.messageType;
this.messageFormat = n.messageFormat;
this.replaceMessage = n.replaceMessage;
// taken from https://github.com/matrix-org/synapse/blob/master/synapse/push/mailer.py
this.allowedTags = [
@@ -116,6 +119,25 @@ module.exports = function(RED) {
: msg.payload.toString();
}
if((node.replaceMessage || msg.replace) && msg.eventId) {
content['m.new_content'] = {
msgtype: content.msgtype,
body: content.body
};
if('format' in content) {
content['m.new_content']['format'] = content['format'];
}
if('formatted_body' in content) {
content['m.new_content']['formatted_body'] = content['formatted_body'];
}
content['m.relates_to'] = {
rel_type: RelationType.Replace,
event_id: msg.eventId
};
content['body'] = ' * ' + content['body'];
}
node.server.matrixClient.sendMessage(msg.topic, content)
.then(function(e) {
node.log("Message sent: " + msg.payload);