isomtrik-quickchat
Version:
isomtrik-quickchat is a lightweight, real-time chat component built with Stencil JS. It is designed to be seamlessly integrated into web applications, offering customizable and responsive chat functionalities. The module supports both CommonJS and ES modu
81 lines (80 loc) • 3.53 kB
JavaScript
/**
* @fileoverview entry point for your component library
*
* This is the entry point for your component library. Use this file to export utilities,
* constants or data structure that accompany your components.
*
* DO NOT use this file to export your components. Instead, use the recommended approaches
* to consume components of this package as outlined in the `README.md`.
*/
export { format } from './utils/utils';
export const initializeChat = function (props) {
if (!props.conversationId ||
!props.licenseKey ||
!props.appSecret ||
!props.userSecret ||
!props.userToken ||
!props.isometrikUserId ||
!props.projectId ||
!props.keysetId ||
!props.accountId) {
console.error('Missing required props to Initialize chat!');
return;
}
const existingChatComponent = document.getElementById(`${props.conversationId}`);
if (existingChatComponent) {
console.warn(`Chat component for ${props.conversationId} already exists.`);
return;
}
const chatComponent = document.createElement('chat-test');
chatComponent.id = props.conversationId;
chatComponent.baseUrl = (props === null || props === void 0 ? void 0 : props.baseUrl) || 'https://apis.isometrik.io';
chatComponent.hostUrl = (props === null || props === void 0 ? void 0 : props.hostUrl) || 'wss://connections.isometrik.io:2053/mqtt';
chatComponent.licenseKey = props.licenseKey;
chatComponent.appSecret = props.appSecret;
chatComponent.userSecret = props.userSecret;
chatComponent.userToken = props.userToken;
chatComponent.isometrikUserId = props.isometrikUserId;
chatComponent.projectId = props.projectId;
chatComponent.keysetId = props.keysetId;
chatComponent.accountId = props.accountId;
chatComponent.conversationId = props.conversationId;
chatComponent.isDark = props.defaultTheme == 'dark' ? true : false;
chatComponent.darkThemeUrl = props.darkThemeUrl || 'https://isometrik-website-bucket.s3.ap-south-1.amazonaws.com/styles/chat-dark-theme.css';
chatComponent.lightThemeUrl = props.lightThemeUrl || 'https://isometrik-website-bucket.s3.ap-south-1.amazonaws.com/styles/chat-light-theme.css';
document.body.appendChild(chatComponent);
};
export const closeChat = function (conversationId) {
if (!conversationId) {
console.error('conversationId is require to closeChat');
return;
}
const chatComponent = document.getElementById(conversationId);
if (chatComponent) {
chatComponent.baseUrl = null;
chatComponent.hostUrl = null;
chatComponent.licenseKey = null;
chatComponent.appSecret = null;
chatComponent.userSecret = null;
chatComponent.userToken = null;
chatComponent.isometrikUserId = null;
chatComponent.projectId = null;
chatComponent.keysetId = null;
chatComponent.accountId = null;
chatComponent.conversationId = null;
document.body.removeChild(chatComponent);
}
};
export const switchChatTheme = function (theme) {
const chatElements = document.getElementsByTagName('CHAT-TEST');
for (let i = 0; i < chatElements.length; i++) {
const chatTest = chatElements[i];
chatTest.isDark = theme == 'dark' ? true : false;
}
};
if (typeof window !== 'undefined') {
window.initializeChat = initializeChat;
window.closeChat = closeChat;
window.switchChatTheme = switchChatTheme;
}
//# sourceMappingURL=index.js.map