Lausnir

Fyrirtækið

Hafa Samband

Lausnir

Fyrirtækið

Hafa Samband

Lausnir

Fyrirtækið

Hafa Samband

Integration Guide

|

Language Selector

|

Language Selector Integration Guide

Below is the guide to propagate the language you select on your webpage into the agent.

Note: The language must be a valid ISO 639-1 code with a country code.

Example formats:

en-US

en-US

en-US

en-US

en-US

en-GB

en-GB

en-GB

en-GB

en-GB

fr-FR

fr-FR

fr-FR

fr-FR

fr-FR

fr-CA

fr-CA

fr-CA

fr-CA

fr-CA

es-ES

da-DE

it-IT

ja-JP

ko-KR

pt-BR

STATE 1: Agent is already open

If your webpage has a language selector and does not reload when the language is changed, you can directly pass the selected language into the agent via the postMessage API.

const agentIframe = document.querySelector('.context-chatbot-widget iframe');
agentIframe.contentWindow.postMessage({ language }, 'https://agents.contextsuite.com/');

You should see the agent's language update immediately. Additionally, you’ll receive a notification event emitted by the agent, which you can listen for like this:

window.addEventListener('message', (event) => {
  const { notification } = event.data;
  console.log('notification', notification); // should log "notification language-selected"
});

STATE 2: Language is selected before agent is opened

If the language is chosen before the agent is opened, or your page reloads after selecting the language, you’ll need to wait until the agent has loaded before posting the language.

You can do this by attaching a listener to the element that opens the agent (typically a button):

const idleAgentEl = document.querySelector('.context-chatbot-open-button');

idleAgentEl?.addEventListener('click', () => {
  // Wait until the iframe is ready, then send the language
  const agentIframe = document.querySelector('.context-chatbot-widget iframe');
  agentIframe.contentWindow.postMessage({ language }, 'https://agents.contextsuite.com/');

  // Optional: use a timeout or interval to ensure agent is ready
});

Tip: If the agent is still loading, it may not receive the event.

You can work around this by using setTimeout or setInterval to retry sending the message until you receive the "notification language-selected" event — then clear the interval.