A snippet code sample for integrating an Ethora powered chat screen into internal web portal or dashboard.
- Install dependencies:
npm install- Start the development server:
npm run dev- Build for production:
npm run buildsrc/pages/Chat.tsx- Main chat page component using@ethora/chatcomponentsrc/App.tsx- Main app componentsrc/main.tsx- Application entry point
The chat component is configured with:
- XMPP provider settings for connecting to Ethora's chat servers
- Test user credentials (replace with JWT login from your dedicated server)
- Room JID format:
userJID_doctorJID@conference.xmpp.ethoradev.com
The Chat component accepts the following props:
The XMPP room JID (Jabber ID) where the chat session will be established.
- Format:
userJID_doctorJID@conference.xmpp.ethoradev.comorroomJID@conference.xmpp.ethoradev.com - Example:
646cc8dc96d4a4dc8f7b2f2d_693228d5f05487ee2e332024@conference.xmpp.ethoradev.com - Note: Replace with proper room JID based on your user and doctor identifiers
User authentication credentials. In production, this should come from JWT login response from your dedicated server.
- Properties:
email(string): User's email addresspassword(string): User's password
- Note: Replace test credentials with actual user data from JWT login
Configuration object for the chat component.
XMPP server connection settings for Ethora's chat infrastructure.
- Properties:
devServer(string): WebSocket URL for XMPP connection (e.g.,wss://xmpp.ethoradev.com:5443/ws)host(string): XMPP server hostname (e.g.,xmpp.ethoradev.com)conference(string): Conference/MUC (Multi-User Chat) server domain (e.g.,conference.xmpp.ethoradev.com)
- Note: Update with your dedicated server URLs
Base URL for the Ethora API endpoints.
- Example:
https://api.ethoradev.com/v1 - Note: Update with your dedicated server API base URL
Enables the new architecture features of the chat component.
- Default:
true - Purpose: Activates enhanced chat functionality and improved performance
Token refresh configuration for maintaining authentication sessions.
- Properties:
enabled(boolean): Whether token refresh is enabled
- Note: Required to be enabled (
true) for media sending functionality
Controls whether room functionality is disabled in the chat interface.
- Default:
false - Purpose: Set to
trueto see how the chat looks for patient view (rooms disabled) - Note: Typically set to
falsefor full chat functionality
Hides the chat header component.
- Default:
false - Purpose: Remove the header bar from the chat interface
Disables media file sending capabilities (images, videos, documents).
- Default:
false - Purpose: Restrict chat to text-only messages
Custom color scheme for the chat interface.
- Properties:
primary(string): Primary color (hex, rgb, or named color)secondary(string): Secondary color (hex, rgb, or named color)
- Purpose: Customize the visual appearance of the chat component
Google authentication integration using Firebase.
- Properties:
enabled(boolean): Enable/disable Google loginfirebaseConfig(FBConfig): Firebase configuration object
- Purpose: Allow users to authenticate using Google accounts
JWT-based authentication configuration.
- Properties:
enabled(boolean): Enable/disable JWT logintoken(string): JWT authentication tokenhandleBadlogin(React.ReactElement, optional): Custom component to display on login failure
- Purpose: Authenticate users using JSON Web Tokens from your backend
Direct user credentials login configuration.
- Properties:
enabled(boolean): Enable/disable user loginuser(User | null): User object with credentials
- Purpose: Authenticate using email/password credentials directly
Custom authentication function implementation.
- Properties:
enabled(boolean): Enable/disable custom loginloginFunction(function): Async function that returns User object or null
- Purpose: Implement your own authentication logic
Custom application token for API authentication.
- Purpose: Provide additional authentication token for API requests
Enables default login behavior.
- Default:
false - Purpose: Use the default login flow provided by the component
Disables all user interactions with the chat (read-only mode).
- Default:
false - Purpose: Create a view-only chat interface
Shows/hides the burger menu icon in the chat header.
- Default:
false - Purpose: Control visibility of the hamburger menu button
Forces the room to be set programmatically.
- Default:
false - Purpose: Override automatic room selection
Custom CSS styles for the room list component.
- Purpose: Style the room list sidebar/panel
Custom CSS styles for the chat room component.
- Purpose: Style the main chat room area
Updates the browser URL path with the current room JID.
- Default:
false - Purpose: Enable deep linking to specific chat rooms
Disables the room menu/options.
- Default:
false - Purpose: Hide room-specific menu options
Array of default rooms to display.
- Purpose: Pre-populate the room list with specific rooms
Custom function to refresh authentication tokens.
- Returns: Promise resolving to
{ accessToken: string, refreshToken?: string } | null - Purpose: Implement custom token refresh logic when
refreshTokens.enabledistrue
Custom background styling for the chat interface.
- Properties:
color(string, optional): Background colorimage(string | File, optional): Background image URL or file
- Purpose: Customize the chat background appearance
Custom message bubble component configuration.
- Purpose: Override default message bubble styling/component
Custom logo to display in the chat header.
- Purpose: Brand the chat interface with your logo
Callback function for header menu click.
- Purpose: Handle custom header menu interactions
Callback function for chat menu in header.
- Purpose: Handle custom chat menu interactions
Configuration for custom room management.
- Properties:
rooms(PartialRoomWithMandatoryKeys[]): Array of custom roomsdisableGetRooms(boolean, optional): Disable automatic room fetchingsingleRoom(boolean): Whether to show only a single room
- Purpose: Provide custom room list instead of fetching from server
Translation/localization configuration.
- Properties:
enabled(boolean): Enable/disable translationstranslations(Iso639_1Codes, optional): Translation object with language codes
- Purpose: Support multiple languages in the chat interface
Disables room configuration options.
- Default:
false - Purpose: Hide room settings and configuration options
Disables user profile interactions.
- Default:
false - Purpose: Prevent users from viewing/editing profiles
Hides the user count display in rooms.
- Default:
false - Purpose: Remove user count indicators
Clears the application store before initialization.
- Default:
false - Purpose: Reset state when reinitializing the chat component
Disables the sent message confirmation logic.
- Default:
false - Purpose: Remove sent status indicators from messages
Initializes the component before fully loading.
- Default:
false - Purpose: Start initialization process earlier in the component lifecycle
URL for QR code generation/display.
- Purpose: Display QR codes in the chat interface
Configuration for an additional send button with custom functionality.
- Properties:
enabled(boolean): Enable/disable secondary send buttonmessageEdit(string): Text to append/edit when using secondary buttonlabel(React.ReactNode, optional): Custom label for the buttonbuttonStyles(React.CSSProperties, optional): Custom styles for the buttonhideInputSendButton(boolean, optional): Hide the default send buttonoverwriteEnterClick(boolean, optional): Override Enter key behavior
- Purpose: Add a second send button with different message handling
Enables retry functionality for failed room loading.
- Properties:
enabled(boolean): Enable/disable retry mechanismhelperText(string): Text to display when retry is available
- Purpose: Provide retry option when room loading fails
Hides the "New Chat" button.
- Default:
false - Purpose: Prevent users from creating new chat rooms
Adds custom elements to the chat header.
- Properties:
enabled(boolean): Enable/disable additional header elementselement(any): React element to render in header
- Purpose: Extend header functionality with custom components
Automatically scrolls to bot messages when received.
- Default:
false - Purpose: Ensure bot messages are visible immediately
Custom text filtering for messages before sending.
- Properties:
enabled(boolean): Enable/disable text filteringfilterFunction(function): Function that takes message text and returns filtered text
- Purpose: Sanitize, censor, or transform message text
Event handler callbacks for chat events.
- Properties:
onMessageSent(function, optional): Called when a message is successfully sent- Parameters:
{ message: string, roomJID: string, user: any, messageType: 'text' | 'media', metadata?: any }
- Parameters:
onMessageFailed(function, optional): Called when message sending fails- Parameters:
{ message: string, roomJID: string, error: Error, messageType: 'text' | 'media' }
- Parameters:
onMessageEdited(function, optional): Called when a message is edited- Parameters:
{ messageId: string, newMessage: string, roomJID: string, user: any }
- Parameters:
- Purpose: Track and handle chat events in your application
Hides the typing indicator when users are typing.
- Default:
false - Purpose: Remove typing status indicators
Blocks message sending while a message is being processed.
- Type:
booleanorobject - Object Properties (when object):
enabled(boolean): Enable/disable blockingtimeout(number, optional): Timeout duration in millisecondsonTimeout(function, optional): Callback when timeout occurs
- Purpose: Prevent sending multiple messages while one is processing
Custom typing indicator component and configuration.
- Properties:
enabled(boolean): Enable/disable custom typing indicatortext(string | function, optional): Custom text or function returning text based on typing usersposition('bottom' | 'top' | 'overlay' | 'floating', optional): Position of the indicatorstyles(React.CSSProperties, optional): Custom stylescustomComponent(React.ComponentType, optional): Custom React component for typing indicator
- Purpose: Customize the typing indicator appearance and behavior
Array of system message types to display (whitelist).
- Purpose: Filter which system messages are shown to users
Custom React component for rendering system messages.
- Purpose: Override default system message rendering with custom component
<Chat
roomJID="userJID_doctorJID@conference.xmpp.ethoradev.com"
config={{
xmppSettings: {
devServer: "wss://xmpp.ethoradev.com:5443/ws",
host: "xmpp.ethoradev.com",
conference: "conference.xmpp.ethoradev.com",
},
baseUrl: "https://api.ethoradev.com/v1",
newArch: true,
refreshTokens: { enabled: true },
disableRooms: false,
}}
user={{
email: "user@example.com",
password: "userpassword",
}}
/>