Skip to main content

Controlling sessions on the eesel Inline Chat

Patrick Teen avatar
Written by Patrick Teen
Updated over 2 weeks ago

The inline chat widget operates within an iframe and supports session management through the postMessage API. This allows parent windows to control the chat session state.

Available Commands

Reset Session

Creates a new chat session with a fresh UUID.

const chatIframe = document.querySelector('#chat-iframe');

chatIframe.contentWindow.postMessage({
type: 'RESET_SESSION'
}, '*');

Load Existing Session

Loads an existing chat session using a specific session ID.

const chatIframe = document.querySelector('#chat-iframe');

chatIframe.contentWindow.postMessage({
type: 'LOAD_SESSION',
sessionId: 'your-uuid-here'
}, '*');

Note: The sessionId must be a valid UUID. Invalid session IDs will be rejected with a console error.

Receiving Session Updates

The chat widget will notify the parent window when session changes occur:

// In the parent window
window.addEventListener('message', (event) => {
// Optional: Verify the message is from your iframe domain
// if (event.origin !== "https://your-chat-domain.com") return;

if (event.data.type === 'SESSION_ID_UPDATE') {
const { sessionId } = event.data;
// Handle the new session ID
}
});
Did this answer your question?