How to Install Joci-Bot
Adding the chat assistant involves copying a small code snippet and pasting it into your website's HTML source. Follow these simple steps:
Step 1: Subscribe
To activate the full features of the Joci-Bot, please subscribe first.
Step 2: Copy the Chatbot Code Snippet
Once subscribed, copy the entire code block below. This script contains everything needed to display and operate the chatbot on your site.
<!-- Start Majestic Network Chatbot Embed Script -->
<script>
(function() {
// --- Configuration ---
const iframeId = 'majestic-chatbot-iframe';
const iframeBaseUrl = 'https://joci.themajesticnetwork.com/Joci-Bot/joci-origin.html'; // Chatbot URL
const expectedIframeOrigin = 'https://joci.themajesticnetwork.com'; // Origin of the chatbot code
// --- Initial Styles ---
const initialStyles = {
position: 'fixed',
bottom: '20px',
right: '20px',
width: '60px',
height: '60px',
border: 'none',
borderRadius: '50%',
overflow: 'hidden',
boxShadow: '0 4px 12px rgba(0, 0, 0, 0.3)',
zIndex: '9999', // Ensure high z-index
transition: 'width 0.3s ease-in-out, height 0.3s ease-in-out, border-radius 0.3s ease-in-out'
};
// --- Expanded Styles ---
const expandedStyles = {
width: '350px',
height: '450px',
borderRadius: '10px'
};
// --- Minimized Styles ---
const minimizedStyles = {
width: initialStyles.width,
height: initialStyles.height,
borderRadius: initialStyles.borderRadius
};
// --- Create and Inject Iframe ---
// Check if iframe already exists (prevents duplicates if script runs multiple times)
if (document.getElementById(iframeId)) {
console.warn('Majestic Chatbot Embed: Iframe already exists.');
return;
}
const iframeElement = document.createElement('iframe');
iframeElement.id = iframeId;
iframeElement.title = "The Majestic Network Chatbot";
// Apply initial styles
for (const property in initialStyles) {
iframeElement.style[property] = initialStyles[property];
}
// Construct the src URL with parent origin
const parentOrigin = window.location.origin;
if (!parentOrigin) {
console.error("Majestic Chatbot Embed: Could not determine parent window's origin. Chatbot functionality may be limited.");
// Decide fallback behavior - maybe don't append?
}
iframeElement.src = `${iframeBaseUrl}?parentOrigin=${encodeURIComponent(parentOrigin)}`;
console.log(`Majestic Chatbot Embed: Setting iframe src to: ${iframeElement.src}`);
// ** Crucial Step: Append directly to the body **
// This should happen after the body element is available.
// Running this script just before </body> ensures this.
document.body.appendChild(iframeElement);
console.log(`Majestic Chatbot Embed: Iframe appended to document body.`);
// --- Event Listener for Iframe Messages ---
window.addEventListener('message', function(event) {
// Security Check: Only accept messages from the expected iframe origin
if (event.origin !== expectedIframeOrigin) {
return;
}
const iframe = document.getElementById(iframeId); // Get reference again inside listener
if (!iframe) return; // Should exist, but check anyway
// Handle resizing messages
if (event.data === 'chatbot-opened') {
console.log("Parent Page: Received 'chatbot-opened' message. Expanding iframe.");
Object.assign(iframe.style, expandedStyles);
} else if (event.data === 'chatbot-closed') {
console.log("Parent Page: Received 'chatbot-closed' message. Minimizing iframe.");
Object.assign(iframe.style, minimizedStyles);
}
});
})(); // Immediately Invoke Function Expression (IIFE)
</script>
<!-- End Majestic Network Chatbot Embed Script -->
Step 3: Add the Snippet to Your Website
The best place to add this script is just before the closing tag in your site's HTML. This ensures your page content loads first, providing a smooth experience for your visitors.
Find the instructions below that match your website's platform:
A. Static HTML Websites (using plain .html
files)
- Open the
.html
file(s) for the pages where you want the chatbot using a text editor or code editor. - Scroll to the very bottom of each file.
- Locate the closing