Added some examples

This commit is contained in:
Skylar Sadlier 2021-08-18 14:19:20 -06:00
parent b33595d5eb
commit 2b2c628904
16 changed files with 938 additions and 4 deletions

View File

@ -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!

90
examples/README.md Normal file
View File

@ -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)

View File

@ -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": []
}
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

View File

@ -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
}
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -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
}
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -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
}
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -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
}
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -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 <strong>HTML</strong> test. <div>New line with div element.</div>",
"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
}
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -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 = '<ul>';\nmsg.payload.users.forEach(function(user, index){\n new_payload += '<li>'+ JSON.stringify(user, null, 2).replace(/(?:\\r\\n|\\r|\\n)/g, \"\\n<br>\"); + '</li>'\n});\nmsg.payload = new_payload + '</ul>';\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
}
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB