diff --git a/README.md b/README.md index c449e3c..08bfa52 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ The following is supported from this package: Therefore, you can easily build a bot, chat relay, or administrate your Matrix server from within [Node-RED](https://nodered.org/). +### Examples +We have examples! [Check them out](examples) + ### Installing You can either install from within Node-RED by searching for `node-red-contrib-matrix-chat` or run this from within your Node-RED directory: @@ -29,10 +32,6 @@ You can either install from within Node-RED by searching for `node-red-contrib-m npm install node-red-contrib-matrix-chat ``` -### Examples -We don't have examples just yet but here is a picture of my flow I use for testing this module while creating it (gives you an idea of what is possible and how easy it is to chain things): -![img.png](example.png) - ### Usage Using this package is very straightforward. Examples coming soon! diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..dd41b05 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,90 @@ +# Examples +These are examples of what is possible with the [node-red-contrib-matrix-chat](https://github.com/Skylar-Tech/node-red-contrib-matrix-chat) module for [Node-RED](https://nodered.org/) + +If you want to try any of them out just copy their JSON contents from their .json file and use the hamburger menu in Node-RED to import the flow. + +Build something cool with these nodes? Feel free to submit a pull request to share it! + +## Index + +- [Respond to "ping" with "pong"](#respond-to-ping-with-pong) +- [Respond to "html" with an HTML message](#respond-to-html-with-an-html-message) +- [Create user using Synapse v1 API](#create-user-using-synapse-v1-api) +- [Respond to "image" with an uploaded image](#respond-to-image-with-an-uploaded-image) +- [Respond to "file" with an uploaded file](#respond-to-file-with-an-uploaded-file) +- [Respond to "react" with a reaction](#respond-to-react-with-a-reaction) +- [Respond to "users" with full list of server users](#respond-to-users-with-full-list-of-server-users) + +### Respond to "ping" with "pong" + +[View JSON](respond-to-html-with-html.json) + +Use this flow to respond to anyone that says "ping" with "pong" into the same room. + +![img.png](respond-ping-pong.png) + + + +### Respond to "html" with an HTML message + +[View JSON](respond-to-html-with-html.json) + +Use this flow to respond to anyone that says "html" with an example HTML message. This shows how easy it is to send HTML. + +![img.png](respond-to-html-with-html.png) + + + +### Create user using Synapse v1 API + +[View JSON](create-user-synapse-v1-api.json) + +Use this flow to create users on servers with closed registration. You also use this endpoint to create your first admin user as it is the same as running the local python script on the server. This requires your registration secret from your homeserver.yaml Synapse server configuration file. + +Edit the object on the inject node to the user/pass combo you want to create and hit the inject button (to the left of the inject node). + +**Note:** This only works on Synapse servers. + +![img.png](create-user-synapse-v1-api.png) + + + +### Respond to "image" with an uploaded image + +[View JSON](respond-image-with-image.json) + +You will need an image on the machine running Node-RED. In this case example.png exists inside the Node-RED directory. + +![img_1.png](respond-image-with-image.png) + + + +### Respond to "file" with an uploaded file + +[View JSON](respond-file-with-file.json) + +You will need a file on the machine running Node-RED. In this case sample.pdf exists inside the Node-RED directory. + +![img.png](respond-file-with-file.png) + + + +### Respond to "react" with a reaction + +[View JSON](respond-react-with-reaction.json) + +Give a 👍 reaction when someone says "react" + +![img.png](respond-react-with-reaction.png) + + + +### Respond to "users" with full list of server users + +[View JSON](respond-users-list.json) + +When someone sends the text "users" they get a HTML message back containing all the current users on the server. + +This requires admin privileges. + +![img.png](respond-users-list.png) \ No newline at end of file diff --git a/examples/create-user-synapse-v1-api.json b/examples/create-user-synapse-v1-api.json new file mode 100644 index 0000000..71a673f --- /dev/null +++ b/examples/create-user-synapse-v1-api.json @@ -0,0 +1,49 @@ +[ + { + "id": "dc757ef02529f228", + "type": "inject", + "z": "f025a8b9fbd1b054", + "name": "", + "props": [ + { + "p": "payload" + } + ], + "repeat": "", + "crontab": "", + "once": false, + "onceDelay": 0.1, + "topic": "", + "payload": "{\"username\":\"example\",\"password\":\"replaceme\"}", + "payloadType": "json", + "x": 130, + "y": 600, + "wires": [ + [ + "62f9049cf48342da" + ] + ] + }, + { + "id": "62f9049cf48342da", + "type": "matrix-synapse-register", + "z": "f025a8b9fbd1b054", + "name": "", + "x": 330, + "y": 600, + "wires": [ + [], + [] + ] + }, + { + "id": "3f9d486ca3c75bf2", + "type": "comment", + "z": "f025a8b9fbd1b054", + "name": "Register user using API v1", + "info": "", + "x": 170, + "y": 560, + "wires": [] + } +] \ No newline at end of file diff --git a/examples/create-user-synapse-v1-api.png b/examples/create-user-synapse-v1-api.png new file mode 100644 index 0000000..53980fd Binary files /dev/null and b/examples/create-user-synapse-v1-api.png differ diff --git a/examples/respond-file-with-file.json b/examples/respond-file-with-file.json new file mode 100644 index 0000000..c1555ef --- /dev/null +++ b/examples/respond-file-with-file.json @@ -0,0 +1,161 @@ +[ + { + "id": "a9b412957063b06c", + "type": "matrix-receive", + "z": "f025a8b9fbd1b054", + "name": "", + "server": "4de4e868e02a9051", + "roomId": "", + "ignoreText": false, + "ignoreReactions": false, + "ignoreFiles": false, + "ignoreImages": false, + "x": 460, + "y": 120, + "wires": [ + [ + "4aa45cd8653ba898" + ] + ] + }, + { + "id": "4aa45cd8653ba898", + "type": "switch", + "z": "f025a8b9fbd1b054", + "name": "msg.payload == \"file\"", + "property": "payload", + "propertyType": "msg", + "rules": [ + { + "t": "eq", + "v": "file", + "vt": "str" + } + ], + "checkall": "true", + "repair": false, + "outputs": 1, + "x": 660, + "y": 120, + "wires": [ + [ + "64be2c99ef9ea32f" + ] + ] + }, + { + "id": "195f346def928e16", + "type": "comment", + "z": "f025a8b9fbd1b054", + "name": "Respond to \"image\" with an uploaded image", + "info": "", + "x": 550, + "y": 80, + "wires": [] + }, + { + "id": "73fd7523a4ba670e", + "type": "change", + "z": "f025a8b9fbd1b054", + "name": "", + "rules": [ + { + "t": "set", + "p": "body", + "pt": "msg", + "to": "test body", + "tot": "str" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 1010, + "y": 120, + "wires": [ + [ + "a03b911e2b2e421b" + ] + ] + }, + { + "id": "86b92dea5e5ab056", + "type": "debug", + "z": "f025a8b9fbd1b054", + "name": "", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "true", + "targetType": "full", + "statusVal": "", + "statusType": "auto", + "x": 1290, + "y": 100, + "wires": [] + }, + { + "id": "f6826747cd96b814", + "type": "debug", + "z": "f025a8b9fbd1b054", + "name": "", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "true", + "targetType": "full", + "statusVal": "", + "statusType": "auto", + "x": 1290, + "y": 140, + "wires": [] + }, + { + "id": "64be2c99ef9ea32f", + "type": "file in", + "z": "f025a8b9fbd1b054", + "name": "", + "filename": "sample.pdf", + "format": "", + "chunk": false, + "sendError": false, + "encoding": "none", + "allProps": false, + "x": 850, + "y": 120, + "wires": [ + [ + "73fd7523a4ba670e" + ] + ] + }, + { + "id": "a03b911e2b2e421b", + "type": "matrix-send-file", + "z": "f025a8b9fbd1b054", + "name": "", + "server": "4de4e868e02a9051", + "roomId": "", + "contentType": "application/pdf", + "x": 1160, + "y": 120, + "wires": [ + [ + "86b92dea5e5ab056" + ], + [ + "f6826747cd96b814" + ] + ] + }, + { + "id": "4de4e868e02a9051", + "type": "matrix-server-config", + "name": "Your Server", + "autoAcceptRoomInvites": true + } +] \ No newline at end of file diff --git a/examples/respond-file-with-file.png b/examples/respond-file-with-file.png new file mode 100644 index 0000000..7cbc80b Binary files /dev/null and b/examples/respond-file-with-file.png differ diff --git a/examples/respond-image-with-image.json b/examples/respond-image-with-image.json new file mode 100644 index 0000000..bcc8de6 --- /dev/null +++ b/examples/respond-image-with-image.json @@ -0,0 +1,96 @@ +[ + { + "id": "a9b412957063b06c", + "type": "matrix-receive", + "z": "f025a8b9fbd1b054", + "name": "", + "server": "4de4e868e02a9051", + "roomId": "", + "ignoreText": false, + "ignoreReactions": false, + "ignoreFiles": false, + "ignoreImages": false, + "x": 460, + "y": 120, + "wires": [ + [ + "4aa45cd8653ba898" + ] + ] + }, + { + "id": "4aa45cd8653ba898", + "type": "switch", + "z": "f025a8b9fbd1b054", + "name": "msg.payload == \"image\"", + "property": "payload", + "propertyType": "msg", + "rules": [ + { + "t": "eq", + "v": "image", + "vt": "str" + } + ], + "checkall": "true", + "repair": false, + "outputs": 1, + "x": 670, + "y": 120, + "wires": [ + [ + "71dc8555d734f985" + ] + ] + }, + { + "id": "195f346def928e16", + "type": "comment", + "z": "f025a8b9fbd1b054", + "name": "Respond to \"image\" with an uploaded image", + "info": "", + "x": 550, + "y": 80, + "wires": [] + }, + { + "id": "71dc8555d734f985", + "type": "file in", + "z": "f025a8b9fbd1b054", + "name": "", + "filename": "example.png", + "format": "", + "chunk": false, + "sendError": false, + "encoding": "none", + "allProps": false, + "x": 870, + "y": 120, + "wires": [ + [ + "2e68b9ef45a84f48" + ] + ] + }, + { + "id": "2e68b9ef45a84f48", + "type": "matrix-send-image", + "z": "f025a8b9fbd1b054", + "name": "", + "server": "4de4e868e02a9051", + "roomId": "", + "contentType": "image/png", + "x": 1030, + "y": 120, + "wires": [ + [], + [] + ] + }, + { + "id": "4de4e868e02a9051", + "type": "matrix-server-config", + "name": "Your Server", + "autoAcceptRoomInvites": true + } +] \ No newline at end of file diff --git a/examples/respond-image-with-image.png b/examples/respond-image-with-image.png new file mode 100644 index 0000000..50bacfb Binary files /dev/null and b/examples/respond-image-with-image.png differ diff --git a/examples/respond-ping-pong.json b/examples/respond-ping-pong.json new file mode 100644 index 0000000..4609253 --- /dev/null +++ b/examples/respond-ping-pong.json @@ -0,0 +1,143 @@ +[ + { + "id": "a9b412957063b06c", + "type": "matrix-receive", + "z": "f025a8b9fbd1b054", + "name": "", + "server": "4de4e868e02a9051", + "roomId": "", + "ignoreText": false, + "ignoreReactions": false, + "ignoreFiles": false, + "ignoreImages": false, + "x": 460, + "y": 120, + "wires": [ + [ + "4aa45cd8653ba898" + ] + ] + }, + { + "id": "4aa45cd8653ba898", + "type": "switch", + "z": "f025a8b9fbd1b054", + "name": "msg.payload == \"ping\"", + "property": "payload", + "propertyType": "msg", + "rules": [ + { + "t": "eq", + "v": "ping", + "vt": "str" + } + ], + "checkall": "true", + "repair": false, + "outputs": 1, + "x": 660, + "y": 120, + "wires": [ + [ + "240492a035448ca6" + ] + ] + }, + { + "id": "240492a035448ca6", + "type": "change", + "z": "f025a8b9fbd1b054", + "name": "set msg.payload = \"pong\"", + "rules": [ + { + "t": "set", + "p": "payload", + "pt": "msg", + "to": "pong", + "tot": "str" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 890, + "y": 120, + "wires": [ + [ + "02973db9f86807b6" + ] + ] + }, + { + "id": "bbed21ccdb0cc394", + "type": "comment", + "z": "f025a8b9fbd1b054", + "name": "Respond to \"ping\" with \"pong\"", + "info": "", + "x": 500, + "y": 80, + "wires": [] + }, + { + "id": "02973db9f86807b6", + "type": "matrix-send-message", + "z": "f025a8b9fbd1b054", + "name": "", + "server": "4de4e868e02a9051", + "roomId": "", + "messageType": "m.text", + "messageFormat": "", + "x": 1100, + "y": 120, + "wires": [ + [ + "2b07fce769aacb0c" + ], + [ + "a3101646528cdea2" + ] + ] + }, + { + "id": "2b07fce769aacb0c", + "type": "debug", + "z": "f025a8b9fbd1b054", + "name": "", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "true", + "targetType": "full", + "statusVal": "", + "statusType": "auto", + "x": 1250, + "y": 100, + "wires": [] + }, + { + "id": "a3101646528cdea2", + "type": "debug", + "z": "f025a8b9fbd1b054", + "name": "", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "true", + "targetType": "full", + "statusVal": "", + "statusType": "auto", + "x": 1250, + "y": 140, + "wires": [] + }, + { + "id": "4de4e868e02a9051", + "type": "matrix-server-config", + "name": "Your Server", + "autoAcceptRoomInvites": true + } +] \ No newline at end of file diff --git a/examples/respond-ping-pong.png b/examples/respond-ping-pong.png new file mode 100644 index 0000000..f76b320 Binary files /dev/null and b/examples/respond-ping-pong.png differ diff --git a/examples/respond-react-with-reaction.json b/examples/respond-react-with-reaction.json new file mode 100644 index 0000000..fb92d81 --- /dev/null +++ b/examples/respond-react-with-reaction.json @@ -0,0 +1,141 @@ +[ + { + "id": "a9b412957063b06c", + "type": "matrix-receive", + "z": "f025a8b9fbd1b054", + "name": "", + "server": "4de4e868e02a9051", + "roomId": "", + "ignoreText": false, + "ignoreReactions": false, + "ignoreFiles": false, + "ignoreImages": false, + "x": 460, + "y": 120, + "wires": [ + [ + "4aa45cd8653ba898" + ] + ] + }, + { + "id": "4aa45cd8653ba898", + "type": "switch", + "z": "f025a8b9fbd1b054", + "name": "msg.payload == \"react\"", + "property": "payload", + "propertyType": "msg", + "rules": [ + { + "t": "eq", + "v": "react", + "vt": "str" + } + ], + "checkall": "true", + "repair": false, + "outputs": 1, + "x": 670, + "y": 120, + "wires": [ + [ + "35e92315a7ff4987" + ] + ] + }, + { + "id": "35e92315a7ff4987", + "type": "change", + "z": "f025a8b9fbd1b054", + "name": "", + "rules": [ + { + "t": "set", + "p": "payload", + "pt": "msg", + "to": "👍", + "tot": "str" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 880, + "y": 120, + "wires": [ + [ + "ab74f9b52a26435c" + ] + ] + }, + { + "id": "d5f35b3b5f64f413", + "type": "debug", + "z": "f025a8b9fbd1b054", + "name": "", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "true", + "targetType": "full", + "statusVal": "", + "statusType": "auto", + "x": 1150, + "y": 100, + "wires": [] + }, + { + "id": "07b598284bcadc58", + "type": "debug", + "z": "f025a8b9fbd1b054", + "name": "", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "true", + "targetType": "full", + "statusVal": "", + "statusType": "auto", + "x": 1150, + "y": 140, + "wires": [] + }, + { + "id": "46a9a333fe2c20f5", + "type": "comment", + "z": "f025a8b9fbd1b054", + "name": "Respond to \"react\" with a reaction (thumbs up)", + "info": "", + "x": 550, + "y": 80, + "wires": [] + }, + { + "id": "ab74f9b52a26435c", + "type": "matrix-react", + "z": "f025a8b9fbd1b054", + "name": "", + "server": "4de4e868e02a9051", + "roomId": "", + "x": 1030, + "y": 120, + "wires": [ + [ + "d5f35b3b5f64f413" + ], + [ + "07b598284bcadc58" + ] + ] + }, + { + "id": "4de4e868e02a9051", + "type": "matrix-server-config", + "name": "Your Server", + "autoAcceptRoomInvites": true + } +] \ No newline at end of file diff --git a/examples/respond-react-with-reaction.png b/examples/respond-react-with-reaction.png new file mode 100644 index 0000000..7616503 Binary files /dev/null and b/examples/respond-react-with-reaction.png differ diff --git a/examples/respond-to-html-with-html.json b/examples/respond-to-html-with-html.json new file mode 100644 index 0000000..5a041fd --- /dev/null +++ b/examples/respond-to-html-with-html.json @@ -0,0 +1,143 @@ +[ + { + "id": "a9b412957063b06c", + "type": "matrix-receive", + "z": "f025a8b9fbd1b054", + "name": "", + "server": "4de4e868e02a9051", + "roomId": "", + "ignoreText": false, + "ignoreReactions": false, + "ignoreFiles": false, + "ignoreImages": false, + "x": 460, + "y": 120, + "wires": [ + [ + "4aa45cd8653ba898" + ] + ] + }, + { + "id": "4aa45cd8653ba898", + "type": "switch", + "z": "f025a8b9fbd1b054", + "name": "msg.payload == \"html\"", + "property": "payload", + "propertyType": "msg", + "rules": [ + { + "t": "eq", + "v": "html", + "vt": "str" + } + ], + "checkall": "true", + "repair": false, + "outputs": 1, + "x": 660, + "y": 120, + "wires": [ + [ + "494174e295946f41" + ] + ] + }, + { + "id": "788e82fbd80fe4cf", + "type": "matrix-send-message", + "z": "f025a8b9fbd1b054", + "name": "Send HTML Message", + "server": "4de4e868e02a9051", + "roomId": "", + "messageType": "m.text", + "messageFormat": "html", + "x": 1080, + "y": 120, + "wires": [ + [ + "c8a970ff52092aeb" + ], + [ + "7747d0fb81341d04" + ] + ] + }, + { + "id": "494174e295946f41", + "type": "change", + "z": "f025a8b9fbd1b054", + "name": "", + "rules": [ + { + "t": "set", + "p": "payload", + "pt": "msg", + "to": "This is an HTML test.
New line with div element.
", + "tot": "str" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 860, + "y": 120, + "wires": [ + [ + "788e82fbd80fe4cf" + ] + ] + }, + { + "id": "c8a970ff52092aeb", + "type": "debug", + "z": "f025a8b9fbd1b054", + "name": "", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "true", + "targetType": "full", + "statusVal": "", + "statusType": "auto", + "x": 1270, + "y": 100, + "wires": [] + }, + { + "id": "7747d0fb81341d04", + "type": "debug", + "z": "f025a8b9fbd1b054", + "name": "", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "true", + "targetType": "full", + "statusVal": "", + "statusType": "auto", + "x": 1270, + "y": 140, + "wires": [] + }, + { + "id": "c4ab4b6d5386037d", + "type": "comment", + "z": "f025a8b9fbd1b054", + "name": "Respond to \"html\" with html message", + "info": "", + "x": 530, + "y": 80, + "wires": [] + }, + { + "id": "4de4e868e02a9051", + "type": "matrix-server-config", + "name": "Your Server", + "autoAcceptRoomInvites": true + } +] \ No newline at end of file diff --git a/examples/respond-to-html-with-html.png b/examples/respond-to-html-with-html.png new file mode 100644 index 0000000..830f057 Binary files /dev/null and b/examples/respond-to-html-with-html.png differ diff --git a/examples/respond-users-list.json b/examples/respond-users-list.json new file mode 100644 index 0000000..ab54fb2 --- /dev/null +++ b/examples/respond-users-list.json @@ -0,0 +1,112 @@ +[ + { + "id": "a9b412957063b06c", + "type": "matrix-receive", + "z": "f025a8b9fbd1b054", + "name": "", + "server": "4de4e868e02a9051", + "roomId": "", + "ignoreText": false, + "ignoreReactions": false, + "ignoreFiles": false, + "ignoreImages": false, + "x": 460, + "y": 120, + "wires": [ + [ + "4aa45cd8653ba898" + ] + ] + }, + { + "id": "4aa45cd8653ba898", + "type": "switch", + "z": "f025a8b9fbd1b054", + "name": "msg.payload == \"users\"", + "property": "payload", + "propertyType": "msg", + "rules": [ + { + "t": "eq", + "v": "users", + "vt": "str" + } + ], + "checkall": "true", + "repair": false, + "outputs": 1, + "x": 670, + "y": 120, + "wires": [ + [ + "b95a674179d93416" + ] + ] + }, + { + "id": "b95a674179d93416", + "type": "matrix-synapse-users", + "z": "f025a8b9fbd1b054", + "name": "", + "server": "4de4e868e02a9051", + "x": 890, + "y": 120, + "wires": [ + [ + "19b654e5f28d93c4" + ], + [] + ] + }, + { + "id": "8720c66e867f89f6", + "type": "matrix-send-message", + "z": "f025a8b9fbd1b054", + "name": "Send HTML Notice", + "server": "4de4e868e02a9051", + "roomId": "", + "messageType": "m.notice", + "messageFormat": "html", + "x": 1230, + "y": 120, + "wires": [ + [], + [] + ] + }, + { + "id": "19b654e5f28d93c4", + "type": "function", + "z": "f025a8b9fbd1b054", + "name": "", + "func": "let new_payload = '';\n\nreturn msg;", + "outputs": 1, + "noerr": 0, + "initialize": "", + "finalize": "", + "libs": [], + "x": 1060, + "y": 120, + "wires": [ + [ + "8720c66e867f89f6" + ] + ] + }, + { + "id": "563da45ab1747c2b", + "type": "comment", + "z": "f025a8b9fbd1b054", + "name": "Response to \"users\" with full server user list", + "info": "", + "x": 550, + "y": 80, + "wires": [] + }, + { + "id": "4de4e868e02a9051", + "type": "matrix-server-config", + "name": "Your Server", + "autoAcceptRoomInvites": true + } +] \ No newline at end of file diff --git a/examples/respond-users-list.png b/examples/respond-users-list.png new file mode 100644 index 0000000..bf1f768 Binary files /dev/null and b/examples/respond-users-list.png differ