Skip to content

Conversation

@ShigrafS
Copy link

Closes #1029

Description

This PR introduces experimental support for connecting EmbeddedChat directly to a Matrix homeserver, including the new Rocket.Chat native Matrix homeserver (see RocketChat/homeserver).

Key goals achieved:

  • EmbeddedChat can now operate in two modes: classic direct Rocket.Chat access (default) or Matrix backend.
  • When in Matrix mode, it connects to a configured Matrix homeserver (e.g. the Rocket.Chat native one or any standard homeserver like matrix.org), joins a single room, and supports core send/receive messaging + typing indicators.
  • This enables federation benefits across the Matrix network without requiring a full Rocket.Chat backend in many embed scenarios.
  • Maintains full backward compatibility with existing Rocket.Chat mode.

This is marked experimental due to partial feature parity (many Rocket.Chat-specific features like edits, deletes, threads, pinning, reactions, search, etc., are stubbed or return "not supported" in Matrix mode). Future iterations can close the gap.

Acceptance Criteria Fulfillment

  • Checked out and referenced the Rocket.Chat native Matrix homeserver: https://github.com/RocketChat/homeserver
  • Added a configuration option to choose between native Matrix homeserver and direct Rocket.Chat access → new mode prop ('rocketchat' | 'matrix')
  • When configured for native Matrix homeserver / Matrix mode: EmbeddedChat can connect to a single configured room, join it (if needed), and send/receive messages successfully → implemented via new MatrixProvider using matrix-js-sdk
  • Documentation added explaining how to configure for native Matrix homeserver and switch modes → updated README.md with example JSX + notes on experimental status

Changes Summary

  • New mode prop on <EmbeddedChat /> (defaults to 'rocketchat')
    • When mode="matrix", requires host (Matrix homeserver URL) and roomId
  • New MatrixProvider class implementing IChatProvider interface (590+ lines)
    • Uses matrix-js-sdk@^39.3.0-rc.0 for client creation, sync, room join, timeline listening, sending messages, typing
    • Maps Matrix events to Rocket.Chat-compatible message format for UI reuse
    • Handles basic login/token flow (reuses @embeddedchat/auth but passes token to Matrix client)
  • Extracted IChatProvider interface for clean abstraction between Rocket.Chat and Matrix implementations
  • Conditional instantiation in EmbeddedChatApi based on mode
  • UI adjustments:
    • Skips optimistic message UI in ChatInput for Matrix mode (relies on real-time timeline events to avoid duplicates)
    • Graceful fallbacks / "not supported" errors for unsupported features (edit/delete/threads/etc.)
  • New Storybook story for testing Matrix mode
  • Dependency added: matrix-js-sdk@^39.3.0-rc.0
  • Documentation: README updated with Matrix mode example + warnings

Limitations (Experimental Phase)

  • No support yet for: message editing/deletion, threads, starring/pinning, reactions, file uploads, search, reporting, slash commands, full pagination, E2EE decryption (shows placeholder for encrypted messages)
  • Authentication reuses Rocket.Chat-style token flow → best suited for bridged/custom setups or when using Rocket.Chat's native homeserver federation bundle
  • Tested primarily with public rooms on matrix.org; Rocket.Chat native homeserver compatibility should be validated in follow-up

How to Test

  1. Use the preview deployment after merge/approval: https://rocketchat.github.io/EmbeddedChat/pulls/pr-1030
  2. Try classic mode (no mode prop or mode="rocketchat") → should work as before
  3. Try Matrix mode:
    <EmbeddedChat
      mode="matrix"
      host="https://matrix.org"           // or your Rocket.Chat native homeserver URL
      roomId="!exampleRoomId:matrix.org"  // replace with real public room ID
      channelName="Matrix Test Room"
    />

Aryan-Verma-999 and others added 8 commits December 2, 2025 03:34
Previously, Matrix login failures would throw exceptions that weren't
caught by the UI error handling. Now returns error in Rocket.Chat format ({ error: 403 }) to trigger proper toast notifications.
- Add proper error returns for channelInfo/getRoomInfo for toast messages
- Add try-catch to sendMessage for error handling
- Add stub methods (star, pin, react, etc.) to prevent UI errors
- Fix edit message to show toast instead of triggering logout
- Add null-safety checks in connect() method
@CLAassistant
Copy link

CLAassistant commented Jan 30, 2026

CLA assistant check
All committers have signed the CLA.

@Aryan-Verma-999
Copy link

Aryan-Verma-999 commented Jan 31, 2026

Hi @ShigrafS,

Great to see work continuing on Matrix integration!

Quick question : I see this PR uses matrix-js-sdk@^39.3.0-rc.0. Are you authenticating with Rocket.Chat credentials or Matrix credentials?

The reason I ask is that when I was working on #1030, @Spiral-Memory mentioned we should use Rocket.Chat credentials and integrate with the Rocket.Chat-built homeserver rather than direct Matrix authentication (see #1030 (comment)).

I'm curious how you approached this, did you find a way to use the Matrix SDK while still authenticating through Rocket.Chat? That would be really helpful to understand!

@ShigrafS
Copy link
Author

ShigrafS commented Feb 1, 2026

Hi @Aryan-Verma-999 !
Yes, that is exactly the approach I took.

I am authenticating with Rocket.Chat credentials, not Matrix credentials. I refactored the MatrixProvider to use the
RocketChatAuth class first.

The flow is:

  • Log in to Rocket.Chat using the provided credentials.
  • Retrieve the authToken and userId from the Rocket.Chat session.
  • Initialize the matrix-js-sdk client by passing that Rocket.Chat authToken as the Matrix accessToken.

This allows us to keep the authentication native to Rocket.Chat while still leveraging the Matrix SDK for messaging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Epic: EmbeddedChat integration with Rocket.Chat native Matrix homeserver

3 participants