# Set up Matrix (element.io) notifications using the discourse-chat-integration plugin

**URL:** https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944
**Category:** Integrations
**Tags:** chat-integration, how-to
**Created:** [July 27, 2017, 4:31pm UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944 "2017-07-27T16:31:03Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [July 27, 2017, 4:31pm UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/1 "2017-07-27T16:31:03Z")

</div>

This #howto describes how to setup the [Matrix](http://matrix.org) ([element.io](http://element.io)) provider included in `discourse-chat-integration`.

> Thanks to @ara4n and members of the `#matrix-dev:matrix.org` room for their help with this integration 🙂

# Install

The `discourse-chat-integration` plugin is bundled with Discourse. Ensure it is enabled by setting `chat_integration_enabled` to true in your site settings. For more details, see the [discourse-chat-integration](https://meta.discourse.org/t/chatroom-integration-plugin-discourse-chat-integration/66522) plugin topic.

# Set up Matrix

These instructions assume you are using the [element.io](https://app.element.io/) web client. Equivalent steps should be possible using other interfaces.

1. Open [https://app.element.io/](https://app.element.io/) in a new **incognito window** (you’ll see why later)

2. Create a user account for your bot. You’ll probably want to write down the password somewhere in case you want to log back in later. Discourse does not need it.  

3. Use the interface to join any rooms that you want to be able to send notifications to

4. Open the user settings by clicking your avatar in the top left, then All Settings

5. Configure the bot’s display name and avatar

6. Switch to the “Help and About” tab, scroll down to “Advanced”, and copy the Homeserver address and your “Access Token” - you’ll need them later.

7. **DO NOT CLICK LOG OUT.** If you do, the Access Token will be invalidated, and it won’t work. Instead, just close the incognito window. If you forgot to open an incognito window, go back to step 1 😉

# Set up Discourse

1. In your Discourse site settings, enter your home server address in the `chat_integration_matrix_homeserver` setting. Make sure to include the protocol. (e.g. `https://matrix.org`). Do **not** include a trailing slash.

2. Paste the access token you copied earlier into the `chat_integration_matrix_access_token` site setting

3. Enable `chat_integration_matrix_enabled`

4. Go to the Plugins tab, then Chat Integrations

5. Go to the Matrix tab, then Create Channel

6. Enter a name for the channel (this is only displayed in the admin interface, it can be anything)

7. Enter the “Room ID” for a room that you want to send notifications to. In the Element web client, you can find it by opening your room, clicking the name at the top, then scroll to the bottom. It will look something like

8. Save Channel

9. Use the Test button on the channel you just created to check that everything’s working. You should see something like this:  

10. Set up some “Rules” for your channel, according to the [discourse-chat-integration](https://meta.discourse.org/t/chatroom-integration-plugin-discourse-chat-integration/66522) instructions.

11. 

> **Technical Notes**
>
> - At the time of writing, there does not seem to be a way of obtaining an “access token” for a “bot” in a user-friendly way. The incognito window solution is the most user-friendly way I could find
> 
> - This plugin sends rich text messages using the `org.matrix.custom.html` format, which is part of the Matrix spec. Clients that do not support formatted messages will fall back to a plain text message.
> 
> - By default, messages are sent as `m.notice` (which Matrix clients typically render more quietly). You can change this to `m.text` by disabling the `chat_integration_matrix_use_notice` site setting.
> 
> - There is no provision in this implementation for ‘refreshing’ access tokens. This is based on the understanding that the majority of homeservers currently in use do not expire tokens. If this changes in the future, this will need to be revisited.

> Last edited by @JammyDodger 2024-05-26T07:09:39Z
> 
> > **Check document**
> >
> > Perform check on document:

---

<div class="post-metadata">

### Author: ![almereyda](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/almereyda/32/367792_2.png) [@almereyda](https://meta.discourse.org/u/almereyda)
#### Post date: [January 25, 2019, 11:46pm UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/2 "2019-01-25T23:46:55Z")

</div>

> [@david](#):
>
> Use the Test button on the channel you just created to check that everything’s working. You should see something like this:

The test is not working for us:

> ![image](https://global.discourse-cdn.com/meta/original/3X/a/a/aaff59d2b5deb25575edfb7bedb5940ae5c771ca.png)
> 
> 422 No Reason Phrase

and the spinner will keep on turning indefinitely until full page reload. How can we triage the error?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [January 27, 2019, 5:37pm UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/3 "2019-01-27T17:37:19Z")

</div>

I just tried setting up a matrix integration using the instructions above, and it all worked ok. Can you confirm that you’re running the latest version of Discourse and this plugin?

Are you using the [matrix.org](http://matrix.org) homeserver, or your own homeserver? The 422 error is coming from that server.

I would suggest double checking your channel identifier, and also your matrix access token in your Discourse site settings.

---

<div class="post-metadata">

### Author: ![almereyda](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/almereyda/32/367792_2.png) [@almereyda](https://meta.discourse.org/u/almereyda)
#### Post date: [January 28, 2019, 9:17pm UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/4 "2019-01-28T21:17:29Z")

</div>

Thanks for the hints. I’ll try that out, before reporting back here.

---

<div class="post-metadata">

### Author: ![nesnera](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nesnera/32/120466_2.png) [@nesnera](https://meta.discourse.org/u/nesnera)
#### Post date: [July 21, 2019, 9:18pm UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/5 "2019-07-21T21:18:24Z")

</div>

I have absolutely [the same issue](https://meta.discourse.org/t/set-up-matrix-riot-im-notifications-using-the-discourse-chat-integration-plugin/66944/2) as @almereyda has.  
@david, can you update obtaing “Access Token”, please? (Riot seems to be intensively developed 👍)  
+“[Doctor log](https://forum.otevrenamesta.cz/OTNjMjI2NmM3OTc2N2Iw.txt)”

---

<div class="post-metadata">

### Author: ![efeefe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/efeefe/32/117710_2.png) [@efeefe](https://meta.discourse.org/u/efeefe)
#### Post date: [June 8, 2020, 10:13pm UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/6 "2020-06-08T22:13:38Z")

</div>

I’m also interested in updated instructions about getting an access token…

---

<div class="post-metadata">

### Author: ![sunjam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sunjam/32/175682_2.png) [@sunjam](https://meta.discourse.org/u/sunjam)
#### Post date: [September 20, 2021, 4:18am UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/7 "2021-09-20T04:18:33Z")

</div>

> [@david](#):
>
> Under Settings (cog icon in bottom left), you can set the bot’s display name and avatar

Currently called `Room settings` in Element (rebranding of Riot).

Works perfectly.

---

<div class="post-metadata">

### Author: ![mattdm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mattdm/32/216484_2.png) [@mattdm](https://meta.discourse.org/u/mattdm)
#### Post date: [January 3, 2022, 8:54pm UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/10 "2022-01-03T20:54:15Z")

</div>

> [@sunjam](#):
>
> Element (rebranding of Riot).

I’ve updated this page to reflect that change.

The access token is, apparently, now under “Help and About” at the bottom of Settings.

I have the same infinite-spinner problem. ☹

I tried with rooms on both [matrix.org](http://matrix.org) and fedora.im.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [January 4, 2022, 9:30pm UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/11 "2022-01-04T21:30:19Z")

</div>

I just ran through the setup myself and it seemed to work ok. A couple of theories:

- Are your rooms encrypted? I’m not sure if we need to do extra work to support encrypted rooms

- Maybe the access tokens expire after some time. This didn’t used to happen when I build the integration in 2017, but that was a long time ago 👴. I’ll try my local config again later this week and see if it still works.

---

<div class="post-metadata">

### Author: ![mattdm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mattdm/32/216484_2.png) [@mattdm](https://meta.discourse.org/u/mattdm)
#### Post date: [January 4, 2022, 9:41pm UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/12 "2022-01-04T21:41:40Z")

</div>

> [@david](#):
>
> Are your rooms encrypted? I’m not sure if we need to do extra work to support encrypted rooms

They are not.

> [@david](#):
>
> Maybe the access tokens expire after some time. This didn’t used to happen when I build the integration in 2017, but that was a long time ago 👴. I’ll try my local config again later this week and see if it still works.

Maybe, but I was copying the access token and then using it basically immediately and that didn’t help.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [January 4, 2022, 11:04pm UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/13 "2022-01-04T23:04:07Z")

</div>

For the record, @mattdm and I were able to track this down to a trailing slash on the Homeserver URL in the Discourse settings.

I’ve added a note about this to the instructions in the OP, and also updated the access token instructions to work with the latest [element.io](http://element.io) UI.

---

<div class="post-metadata">

### Author: ![sunjam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sunjam/32/175682_2.png) [@sunjam](https://meta.discourse.org/u/sunjam)
#### Post date: [August 24, 2022, 12:00am UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/14 "2022-08-24T00:00:04Z")

</div>

Has anyone had any luck with thread support?

---

<div class="post-metadata">

### Author: ![manning-ncsa](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/manning-ncsa/32/282163_2.png) [@manning-ncsa](https://meta.discourse.org/u/manning-ncsa)
#### Post date: [November 16, 2022, 6:30pm UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/15 "2022-11-16T18:30:23Z")

</div>

Installing the latest version of the chat plugin (commit `ba40ede510986f74a23345082ac578e126467b97`), and configuring a test Matrix room (unencrypted, public room), I receive a 500 HTTP error when I attempt a test [as described above](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/2). Same endless spinner symptom requiring page refresh.

The bot account access token was independently verified by sending a message to the room using the API (`_matrix/client/r0/rooms/{room_id}/send/m.room.message`) to our own Matrix server.

The Discourse logs show

```plaintext
Started POST "/admin/plugins/chat-integration/test" for 141.142.60.55 at 2022-11-16 18:16:47 +0000
Processing by DiscourseChatIntegration::ChatController#test as */*
  Parameters: {"channel_id"=>"107", "topic_id"=>"466"}
Completed 500 Internal Server Error in 62ms (ActiveRecord: 0.0ms | Allocations: 10109)
NameError (uninitialized constant FinalDestination::HTTP)
app/controllers/application_controller.rb:387:in `block in with_resolved_locale'
app/controllers/application_controller.rb:387:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:71:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:361:in `call'
config/initializers/100-quiet_logger.rb:23:in `call'
config/initializers/100-silence_logger.rb:31:in `call'
lib/middleware/enforce_hostname.rb:23:in `call'
lib/middleware/request_tracker.rb:198:in `call'

```

---

<div class="post-metadata">

### Author: ![mattdm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mattdm/32/216484_2.png) [@mattdm](https://meta.discourse.org/u/mattdm)
#### Post date: [November 20, 2022, 6:40pm UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/16 "2022-11-20T18:40:37Z")

</div>

> [@sunjam](#):
>
> Has anyone had any luck with thread support?

I have not tried, but that would be interesting. Do you mean putting all posts into one thread to reduce channel clutter, or would this be posting topic replies to a matrix thread?

---

<div class="post-metadata">

### Author: ![sunjam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sunjam/32/175682_2.png) [@sunjam](https://meta.discourse.org/u/sunjam)
#### Post date: [December 8, 2022, 2:15pm UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/17 "2022-12-08T14:15:53Z")

</div>

> [@mattdm](#):
>
> would this be posting topic replies to a matrix thread?

Posting topic replies to a matrix thread.  
(Same flow as Slack has currently)

---

<div class="post-metadata">

### Author: ![mattdm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mattdm/32/216484_2.png) [@mattdm](https://meta.discourse.org/u/mattdm)
#### Post date: [May 20, 2023, 5:26pm UTC](https://meta.discourse.org/t/set-up-matrix-element-io-notifications-using-the-discourse-chat-integration-plugin/66944/18 "2023-05-20T17:26:20Z")

</div>

I’m curious if there has been any development on adding threaded reply support for matrix. Some of our users would appreciate it.
