Skip to content

Commit

Permalink
✨ Matrix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil1712 committed Oct 16, 2020
1 parent 91aa198 commit 93a9ec3
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/nodes/credentials/Matrix/README.md
@@ -0,0 +1,24 @@
---
permalink: /credentials/matrix
description: Learn to configure credentials for the Matrix node in n8n
---

# Matrix

You can use these credentials to authenticate the following nodes with Matrix.
- [Matrix](../../nodes-library/nodes/Matrix/README.md)

## Prerequisites

Create an account on a Matrix server.

## Using Access Token

1. Access the Matrix server.
2. Click on your username in the top left corner.
3. Select 'All settings' from the dropdown list.
4. Click on ***Help & About*** in the left sidebar.
5. Scroll down to the ***Advanced*** section.
6. Click on ***<click to reveal>*** next to 'Access Token'.
7. Copy the 'Homeserver URL' under the ***Advanced*** section if you are using a custom server.
8. Use this Homeserver URL and Access Token with your Matrix node credentials in n8n.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
152 changes: 152 additions & 0 deletions docs/nodes/nodes-library/nodes/Matrix/README.md
@@ -0,0 +1,152 @@
---
permalink: /nodes/n8n-nodes-base.matrix
description: Learn how to use the Matrix node in n8n
---

# Matrix

[Matrix](https://matrix.org) is an open standard for interoperable, decentralized, real-time communication over IP.

::: tip 🔑 Credentials
You can find authentication information for this node [here](../../../credentials/Matrix/README.md).
:::

## Basic Operations

::: details Account
- Get current user's account information
:::

::: details Event
- Get a single event by ID
:::

::: details Media
- Send media to a chat room
:::

::: details Message
- Send a message to a room
- Get all messages from a room
:::

::: details Room
- New chat room with defined settings
- Invite a user to a room
- Join a new room
- Kick a user from a room
- Leave a room
:::

::: details Room Member
- Get all members
:::

## Example Usage

This workflow allows you to create a room, invite members from a different room, and send a message in the room we create using the Matrix node. You can also find the [workflow](https://n8n.io/workflows/724) on n8n.io. This example usage workflow uses the following nodes.
- [Start](../../core-nodes/Start/README.md)
- [Matrix]()
- [IF](../../core-nodes/IF/README.md)

The final workflow should look like the following image.

![A workflow with the Matrix node](./workflow.png)

### 1. Start node

The Start node exists by default when you create a new workflow.

### 2. Matrix (create: room)

This node will create a new room called `n8n` on the Matrix server.
::: v-pre
1. First of all, you'll have to enter credentials for the Matrix node. You can find out how to do that [here](../../../credentials/Matrix/README.md).
2. Select 'Room' from the ***Resource*** dropdown list.
3. Enter a name for the room you want to create in the ***Room Name*** field.
4. Enter an alias for the room in the ***Room Alias*** field.
5. Click on ***Execute Node*** to run the node.
:::
In the screenshot below, you will notice that the node creates a room `n8n` with an alias `#discussion-n8n:matrix.org`.

![Using the Matrix node to create a room](./Matrix_node.png)

### 3. Matrix1 node (me: account)

This node will get your account information from the Matrix server.

1. Select the credentials that you entered in the previous node.
2. Select 'Account' from the ***Resource*** dropdown list.
3. Click on ***Execute Node*** to run the node.

In the screenshot below, you will notice that the node returns the user id.

![Using the Matrix node to get your account information](./Matrix1_node.png)

### 3. Matrix2 node (getAll: roomMember)

This node will return the information of all the members in a room. The output of this node will be passed on to the next nodes in the workflow.

1. Select the credentials that you entered in the previous node.
2. Select 'Room Member' from the ***Resource*** dropdown list.
3. Select a room from the ***Room ID*** dropdown list. We will send invites to the members of this room.
4. Click on ***Execute Node*** to run the node.

In the screenshot below, you will notice that the node returns the information of all the members in the room we specified. The output of this node will be passed on to the next nodes in the workflow.

![Using the Matrix node to get the information of the members in a room](./Matrix2_node.png)

### 4. IF node

This node will compare the user's id with your user id. If the user ids are not equal, the output will be true, otherwise false.

1. Click on ***Add Condition*** and select 'String'.
2. Click on the gears icon next to the ***Value 1*** field and click on ***Add Expression***.
3. Select the following in the ***Variable Selector*** section: Nodes > Matrix1 > Output Data > JSON > user_id. You can also add the following expression: `{{$node["Matrix1"].json["user_id"]}}`.
4. Select 'Not Equal' from the ***Operation*** dropdown list.
5. Click on the gears icon next to the ***Value 2*** field and click on ***Add Expression***.
6. Select the following in the ***Variable Selector*** section: Nodes > Matrix2 > Output Data > JSON > user_id. You can also add the following expression: `{{$node["Matrix2"].json["user_id"]}}`.
7. Click on ***Execute Node*** to run the node.

In the screenshot below, you will notice that the node returns the information of all the members of the room except your information.

![Using the IF node to compare your user id with the user id of the members in a room](./IF_node.png)

### 4. Matrix3 node (invite: room)

This node will send an invitation to the members returned by the previous node to join the room we created using the Matrix node.

1. Select the credentials that you entered in the previous node.
2. Select 'Room' from the ***Resource*** dropdown list.
3. Select 'Invite' from the ***Operation*** dropdown list.
4. Click on the gears icon next to the ***Room ID*** field and click on ***Add Expression***.
5. Select the following in the ***Variable Selector*** section: Nodes > Matrix > Output Data > JSON > room_id. You can also add the following expression: `{{$node["Matrix"].json["room_id"]}}`.
6. Click on the gears icon next to the ***User ID*** field and click on ***Add Expression***.
7. Select the following in the ***Variable Selector*** section: Nodes > IF > Output Data > JSON > user_id. You can also add the following expression: `{{$node["IF"].json["user_id"]}}`.
8. Click on ***Execute Node*** to run the node.

In the screenshot below, you will notice that the node sends an invite to join the room we created to the members of another room.

![Using the Matrix node to send an invite to join the room](./Matrix3_node.png)

### 5. Matrix4 node (create: message)

This node will send a message to the new room we created using the Matrix node.

1. Select the credentials that you entered in the previous node.
2. Click on the gears icon next to the ***Room ID*** field and click on ***Add Expression***.
3. Select the following in the ***Variable Selector*** section: Nodes > Matrix > Output Data > JSON > room_id. You can also add the following expression: `{{$node["Matrix"].json["room_id"]}}`.
4. Enter a message in the ***Text*** field.
5. Click on ***Execute Node*** to run the node.

In the screenshot below, you will notice that the node sends a `Welcome to n8n!` message to the `n8n` room we created with the Matrix node.

![Using the Matrix node to send a message to the room we created](./Matrix4_node.png)

### 6. NoOp node
Adding this node here is optional, as the absence of this node won't make a difference to the functioning of the workflow.

1. Create a ***NoOp*** node connected to the 'false' output of the IF node.
2. Click on ***Execute Node*** to run the node.

![Using the NoOp node](./NoOp_node.png)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 93a9ec3

Please sign in to comment.