From 4ca2b63bccc5248d09927f51bb25115afc684d9c Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Mon, 16 Nov 2020 01:42:57 -0500 Subject: [PATCH] :zap: Feature/matrix extended (#1162) * added Matrix option to send notice and emote messages * added Matrix option to send HTML messages * :zap: Small text changes Co-authored-by: Sabine --- .../nodes/Matrix/GenericFunctions.ts | 10 ++- .../nodes/Matrix/MessageDescription.ts | 88 ++++++++++++++++++- 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/packages/nodes-base/nodes/Matrix/GenericFunctions.ts b/packages/nodes-base/nodes/Matrix/GenericFunctions.ts index d52eb63506..204d613259 100644 --- a/packages/nodes-base/nodes/Matrix/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Matrix/GenericFunctions.ts @@ -127,10 +127,18 @@ export async function handleMatrixCall(this: IExecuteFunctions | IExecuteSingleF if (operation === 'create') { const roomId = this.getNodeParameter('roomId', index) as string; const text = this.getNodeParameter('text', index) as string; + const msgType = this.getNodeParameter('msgType', index) as string; + const format = this.getNodeParameter('format', index) as string; const body: IDataObject = { - msgtype: 'm.text', + msgtype: msgType, body: text, }; + if (format === 'org.matrix.custom.html') { + const fallbackText = this.getNodeParameter('fallbackText', index) as string; + body.format = format; + body.formatted_body = text; + body.body = fallbackText; + } const messageId = uuid(); return await matrixApiRequest.call(this, 'PUT', `/rooms/${roomId}/send/m.room.message/${messageId}`, body); } else if (operation === 'getAll') { diff --git a/packages/nodes-base/nodes/Matrix/MessageDescription.ts b/packages/nodes-base/nodes/Matrix/MessageDescription.ts index 63ab4a2bcb..445a0e719c 100644 --- a/packages/nodes-base/nodes/Matrix/MessageDescription.ts +++ b/packages/nodes-base/nodes/Matrix/MessageDescription.ts @@ -79,10 +79,96 @@ export const messageFields = [ }, description: 'The text to send.', }, + { + displayName: 'Message type', + name: 'msgType', + displayOptions: { + show: { + operation: [ + 'create', + ], + resource: [ + 'message', + ], + }, + }, + type: 'options', + options: [ + { + name: 'Text', + value: 'm.text', + description: 'Send a text message.', + }, + { + name: 'Emote', + value: 'm.emote', + description: 'Perform an action (similar to /me in IRC).', + }, + { + name: 'Notice', + value: 'm.notice', + description: 'Send a notice.', + }, + ], + default: 'm.text', + description: 'The type of message to send.', + }, + { + displayName: 'Message Format', + name: 'format', + displayOptions: { + show: { + operation: [ + 'create', + ], + resource: [ + 'message', + ], + }, + }, + type: 'options', + options: [ + { + name: 'Plain Text', + value: 'plain', + description: 'Text only', + }, + { + name: 'HTML', + value: 'org.matrix.custom.html', + description: 'HTML-formatted text', + }, + ], + default: 'plain', + description: "The format of the message's body.", + }, + { + displayName: 'Fallback Text', + name: 'fallbackText', + displayOptions: { + show: { + resource: [ + 'message', + ], + operation: [ + 'create', + ], + format: [ + 'org.matrix.custom.html', + ], + }, + }, + type: 'string', + typeOptions: { + alwaysOpenEditWindow: true, + }, + placeholder: 'HTML message could not be displayed.', + description: 'A plain text message to display in case the HTML cannot be rendered by the Matrix client.', + }, /* ----------------------------------------------------------------------- */ - /* message:getAll */ + /* message:getAll */ /* ----------------------------------------------------------------------- */ { displayName: 'Room ID',