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

If you haven’t already, install the discourse-chat-integration plugin

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 Integration

  5. Go to the Matrix tab, then Add 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
    
  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:
    17

  10. Set up some “Rules” for your channel, according to the discourse-chat-integration instructions.

  11. giphy-downsized (1)

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

  • The matrix spec does not currently define a way of providing “rich text” messages. There is a spec under development, but for now this plugin uses the “unofficial” method which has been adopted in the element.io client. Clients that do not support this will simply fall back to a plain text message

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

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

إعجاب واحد (1)

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

Works perfectly.

إعجابَين (2)

لقد قمت بتحديث هذه الصفحة لتعكس هذا التغيير.

يبدو أن رمز الوصول موجود الآن تحت “المساعدة والمعلومات” في أسفل الإعدادات.

لدي نفس مشكلة الدوران اللانهائي. :frowning:

لقد جربت مع غرف على كل من matrix.org و fedora.im.

إعجاب واحد (1)

لقد قمت بتشغيل الإعداد بنفسي للتو وبدا أنه يعمل بشكل جيد. بعض النظريات:

  • هل غرفك مشفرة؟ لست متأكدًا مما إذا كنا بحاجة إلى القيام بعمل إضافي لدعم الغرف المشفرة

  • ربما تنتهي صلاحية رموز الوصول بعد فترة زمنية معينة. لم يحدث هذا من قبل عندما قمت ببناء التكامل في عام 2017، ولكن هذا كان منذ وقت طويل جدًا :older_man:. سأحاول تكويني المحلي مرة أخرى في وقت لاحق من هذا الأسبوع وأرى ما إذا كان لا يزال يعمل.

إعجاب واحد (1)

إنها ليست كذلك.

ربما، لكنني كنت أنسخ رمز الوصول ثم أستخدمه على الفور تقريبًا ولم يساعد ذلك.

3 إعجابات

للتسجيل، تمكنت أنا و @mattdm من تتبع هذا إلى شرطة مائلة لاحقة في عنوان URL الخاص بالخادم المضيف في إعدادات Discourse. لقد أضفت ملاحظة حول هذا في التعليمات في المنشور الأصلي، وقمت أيضًا بتحديث تعليمات رمز الوصول للعمل مع أحدث واجهة مستخدم لـ element.io.

5 إعجابات

هل نجح أي شخص في الحصول على دعم للخيوط؟

عند تثبيت أحدث إصدار من المكون الإضافي للدردشة (commit ba40ede510986f74a23345082ac578e126467b97)، وتكوين غرفة اختبار Matrix (غرفة عامة غير مشفرة)، أتلقى خطأ HTTP 500 عند محاولة اختبار كما هو موضح أعلاه. نفس عرض المؤشر الدوار الذي لا ينتهي ويتطلب تحديث الصفحة.

تم التحقق من صحة رمز الوصول الخاص بحساب الروبوت بشكل مستقل عن طريق إرسال رسالة إلى الغرفة باستخدام واجهة برمجة التطبيقات (_matrix/client/r0/rooms/{room_id}/send/m.room.message) إلى خادم Matrix الخاص بنا.

تُظهر سجلات 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/middleware/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'

لم أجرب، لكن سيكون ذلك مثيرًا للاهتمام. هل تقصد وضع جميع المشاركات في خيط واحد لتقليل فوضى القناة، أم أن هذا سيكون نشر ردود الموضوع في خيط مصفوفة؟

إعجابَين (2)

نشر ردود على موضوع في سلسلة Matrix.
(نفس التدفق الذي لدى Slack حاليًا)

إعجاب واحد (1)

أنا فضولي لمعرفة ما إذا كان هناك أي تطور في إضافة دعم الردود المتسلسلة لمصفوفة. سيقدر بعض مستخدمينا ذلك.

3 إعجابات