An easy to use full-stack component embedding Rocket.Chat into your webapp.
EmbeddedChat is a full-stack React component node module of the RocketChat application that is fully configurable, extensible, and flexible for use. It is tightly bound with the RocketChat server using Rocket.Chat nodejs SDK and its UI fully customisable.
npm install @embeddedchat/react
# or
yarn add @embeddedchat/react
Import the EmbeddedChat
component into your file:
import { EmbeddedChat } from '@embeddedchat/react';
To use the EmbeddedChat
component, include it in your component's render method or return statement. Here's a basic example:
<EmbeddedChat
host="http://your-rocketchat-server.com"
roomId="YOUR_ROOM_ID"
/>
-
isClosable
(boolean): Iftrue
, the chat window can be closed. Defaults tofalse
. -
setClosableState
(function): Callback to handle the closable state. -
moreOpts
(boolean): It adds a kebab menu with added functionalities like showing pinned, starred, thread messages. Defaults tofalse
. -
width
(string): Width of the chat window. Defaults to'100%'
. -
height
(string): Height of the chat window. Defaults to'50vh'
. -
host
(string): The URL of your RocketChat server. -
roomId
(string): ID of the chat room. -
channelName
(string): The fallback channel name to be present on the chat. -
anonymousMode
(boolean): Enable anonymous mode. Defaults tofalse
. -
toastBarPosition
(string): Position of the toast bar. Defaults to'bottom right'
. -
showRoles
(boolean): Display user roles. Defaults tofalse
. -
showAvatar
(boolean): Show user avatars. Defaults tofalse
. -
enableThreads
(boolean): Enable chat threads. Defaults tofalse
. -
theme
(object): Theme object for styling. -
className
(string): Additional CSS class for styling. -
style
(object): Inline styles for the chat window. -
hideHeader
(boolean): Hide the chat header. Defaults tofalse
. -
auth
(object): Authentication configuration.
The EmbeddedChat
component offers three distinct authentication modes to cater to different requirements for accessing RocketChat. Below is a detailed guide on how to implement each authentication flow.
Token authentication allows users to authenticate using a service-specific access token. There are two ways to use token authentication:
auth: {
flow: 'TOKEN',
credentials: {
serviceName: "your-service-name",
accessToken: "accessToken",
expiresIn: 3600,
},
}
-
serviceName
: The name of your authentication service. -
accessToken
: The access token obtained from your authentication service. -
expiresIn
: The duration in seconds for which the token is valid.
auth: {
flow: 'TOKEN',
credentials: {
resume: 'resumeToken',
},
}
-
resume
: A resume token to be used for authentication.
In both cases, the credentials are posted to the /api/v1/login
endpoint of the RocketChat server.
The password method displays a modal where users can enter their username and password:
auth: {
flow: 'PASSWORD',
}
This method is straightforward and does not require additional configuration for the auth
prop. When this flow is active, a modal dialog prompts users for their RocketChat username and password.
To use RocketChat's OAuth authentication, ensure the EmbeddedChat app is installed and configured on your RocketChat server:
auth: {
flow: 'OAUTH',
}
This method utilizes the OAuth configuration set up in RocketChat, providing a seamless authentication experience.
When implementing any of these authentication methods in EmbeddedChat
, include the auth
prop with the desired configuration:
<EmbeddedChat
host="http://your-rocketchat-server.com"
roomId="YOUR_ROOM_ID"
auth={{
flow: 'TOKEN', // or 'PASSWORD' or 'OAUTH'
credentials: {
// Include if using TOKEN flow
},
}}
/>
Ensure that the host
and roomId
props are set according to your RocketChat server and the specific room you want to connect to.
You can pass a theme
object to customize the appearance according to your application's design:
<EmbeddedChat
// ...other props
theme={myCustomTheme}
/>
Follow theming.md to know more about EmbeddedChat's theming.
If isClosable
is true
, provide a setClosableState
function to manage the state when the chat window is closed:
<EmbeddedChat
isClosable={true}
setClosableState={handleClose}
// ...other props
/>
Follow this EmbeddedChat Readme to setup EmbeddedChat for development.
The EmbeddedChat
component offers a flexible and feature-rich solution for integrating RocketChat into your application. Customize it according to your needs to enhance your app's chat functionality.