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

This howto describes how to setup the Matrix (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 :slight_smile:

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 plugin topic.

Set up Matrix

These instructions assume you are using the element.io web client. Equivalent steps should be possible using other interfaces.

  1. Open 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 :wink:

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

    !cdGUowUAqlgLHVerqE:matrix.org
    

    Note: Newer Matrix Room v12 IDs may not include the :server suffix (e.g. !abcdefghijkl). Both formats are supported.

  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 instructions.

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 documentPerform check on document:
19개의 좋아요

The test is not working for us:

422 No Reason Phrase

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

4개의 좋아요

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 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.

4개의 좋아요

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

4개의 좋아요

I have absolutely the same issue as @almereyda has.
@david, can you update obtaing “Access Token”, please? (Riot seems to be intensively developed :+1:)
+“Doctor log”

2개의 좋아요

액세스 토큰을 발급받는 방법에 대한 최신 안내도 궁금합니다…

1개의 좋아요

현재 Element(Riot의 리브랜딩)에서는 Room settings(방 설정)라고 표시됩니다.

완벽하게 작동합니다.

2개의 좋아요

이 변경 사항을 반영하도록 이 페이지를 업데이트했습니다.

접근 토큰은 이제 설정 하단의 "도움말 및 정보"에 있는 것으로 보입니다.

저도 동일한 무한 로딩 스피너 문제를 겪고 있습니다. :frowning:

matrix.org와 fedora.im의 방을 모두 시도해 보았습니다.

1개의 좋아요

저도 직접 설정 과정을 다시 진행해 보았는데, 문제없이 잘 작동하는 것 같습니다. 몇 가지 추측을 해 보면 다음과 같습니다.

  • 방이 암호화되어 있나요? 암호화된 방을 지원하기 위해 추가 작업이 필요한지 확신이 서지 않습니다.

  • 액세스 토큰이 일정 시간 후에 만료되는 것일 수도 있습니다. 2017년에 이 통합을 만들었을 때는 이런 일이 없었지만, 꽤 오래전의 일입니다 :older_man:. 이번 주 후반에 로컬 설정을 다시 시도해 보겠습니다.

1개의 좋아요

아니요, 암호화되어 있지 않습니다.

그럴 수도 있지만, 저는 액세스 토큰을 복사한 뒤 거의 즉시 사용했는데도 도움이 되지 않았습니다.

3개의 좋아요

기록을 위해 말씀드리면, @mattdm와 저는 이 문제를 Discourse 설정의 Homeserver URL 뒤에 붙은 슬래시 때문인 것으로 파악했습니다.

OP의 설명서에 이에 대한 내용을 추가했으며, 최신 element.io UI와 호환되도록 액세스 토큰 설명도 업데이트했습니다.

5개의 좋아요

스레드 지원에 대해 성공적인 경험을 하신 분이 계신가요?

최신 버전의 채팅 플러그인(커밋 ba40ede510986f74a23345082ac578e126467b97)을 설치하고, 테스트용 Matrix 방(암호화되지 않은 공개 방)을 구성한 후, 위와 같이 설명된대로 테스트를 시도하면 500 HTTP 오류가 발생합니다. 페이지 새로고침이 필요한 동일한 무한 로딩 스피너 증상이 나타납니다.

봇 계정 액세스 토큰은 자체 Matrix 서버로 API(_matrix/client/r0/rooms/{room_id}/send/m.room.message)를 사용하여 방에 메시지를 보내는 방식으로 독립적으로 검증되었습니다.

Discourse 로그에는 다음과 같이 표시됩니다.

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'
1개의 좋아요

직접 시도해 보지는 않았지만, 흥미로운 제안입니다. 채널의 혼란을 줄이기 위해 모든 게시물을 하나의 스레드에 넣는 것을 의미하시나요, 아니면 토픽 답글을 매트릭스 스레드에 게시하는 것을 말씀하시는 건가요?

2개의 좋아요

매트릭스 스레드에 토픽 답변을 게시하는 것입니다.
(현재 슬랙과 동일한 흐름)

1개의 좋아요

Matrix에 스레드형 답변 지원 기능이 추가되었는지 궁금합니다. 일부 사용자분들이 이 기능을 환영할 것 같습니다.

3개의 좋아요