1.0.1 • Published 5 months ago
rocket-chat-widget-integration v1.0.1
Rocket.Chat Web Integration
A lightweight JavaScript library for seamlessly integrating Rocket.Chat into web applications with additional auto-reply capabilities.
Features
- 🚀 Easy integration with Rocket.Chat
- 🎨 Customizable configuration
- 🔒 Secure with api key
- 🔑 Easy to use with session storage or a path to get the user context
Installation
npm install rocket-chat-web-integration or yarn add rocket-chat-web-integration
Quick Start
- Import the RocketChatIntegration class:
html
Configuration Options
Option | Type | Required | Default | Description |
---|---|---|---|---|
rocketChatUrl | string | Yes | - | URL of your Rocket.Chat server |
autoReplyServerUrl | string | No | null | URL of your auto-reply server |
userEmail | string | No | null | User's email for identification |
logoutFormId | string | No | 'logoutForm' | ID of the logout form element |
userContextPath | string | No | null | Path to user context in window object |
getUserContext | function | No | null | Function to get user context |
useSessionStorage | boolean | No | false | Use session storage for user context |
sessionStorageKey | string | No | 'userContext' | Key for session storage |
fieldMappings | object | No | {} | Custom field mappings for user data |
Basic Integration
With Auto-Reply Feature
<script type="module">
import { RocketChatIntegration } from 'rocket-chat-web-integration';
const chatWidget = new RocketChatIntegration({
rocketChatUrl: 'https://chat.example.com',
autoReplyServerUrl: 'https://autoreply.example.com',
userEmail: 'user@example.com'
});
</script>
Auto-register the user in Rocket.Chat widget if the user is logged in
Using Session Storage
<script type="module">
import { RocketChatIntegration } from 'rocket-chat-web-integration';
// Store user context in session storage (pass in the session storage key)
const chatWidget = new RocketChatIntegration({
rocketChatUrl: "http://localhost:3000",
autoReplyServerUrl: "http://localhost:5800",
useSessionStorage: true,
sessionStorageKey: "customUserContextKey"
});
</script>
Using Context Path
<script type="module">
import { RocketChatIntegration } from 'rocket-chat-web-integration';
// Define user context in window object
window.testUser = {
identity: {
email: "user@example.com",
name: "Test User"
}
};
const chatWidget = new RocketChatIntegration({
rocketChatUrl: "http://localhost:3000",
autoReplyServerUrl: "http://localhost:5800",
userContextPath: "testUser.identity"
});
</script>
Using Custom Context Function
<script type="module">
import { RocketChatIntegration } from 'rocket-chat-web-integration';
const chatWidget = new RocketChatIntegration({
rocketChatUrl: "http://localhost:3000",
autoReplyServerUrl: "http://localhost:5800",
getUserContext: () => {
// Return a promise that resolves with the user context
return fetch("http://localhost:5800/api/v1/users/me")
.then((response) => {
if (!response.ok) {
throw new Error("Failed to fetch user context");
}
return response.json();
})
.then((data) => ({
email: data.email,
name: data.name || data.username,
username: data.username,
}))
.catch((error) => {
console.error("Error fetching user context:", error);
return null;
});
},
});
</script>
With Logout Handling
<form id="customLogoutForm" action="/logout" method="POST">
<button type="submit">Logout</button>
</form>
<script type="module">
import { RocketChatIntegration } from 'rocket-chat-web-integration';
const chatWidget = new RocketChatIntegration({
rocketChatUrl: 'https://chat.example.com',
logoutFormId: 'customLogoutForm'
});
</script>
License
This project is licensed under the Aevoco Sdn Bhd.
Support
If you encounter any problems or have questions, please feel free to contact us at hello@aevoco.com.