Skip to main content

Communicating with the platform

The app and ConsulPoint are on different domains, so they can only communicate through messages (postMessage). With them, the app asks the platform for actions it cannot do on its own.

Four rules​

  1. Send to the parent window with target '*'. The message only reaches ConsulPoint, which is what shows the app.
  2. Mark every message with source: 'aku-iframe'. Without that mark, it is ignored.
  3. Accept a response only if it comes from the parent window and carries source: 'aku-parent'.
  4. Send nothing outside ConsulPoint: if the app is not inside the platform, there is no one to talk to.
src/services/platform.ts
const isEmbedded = () => window !== window.parent;

export function sendToPlatform(message: Record<string, unknown>) {
if (!isEmbedded()) return;
window.parent.postMessage({ source: 'aku-iframe', ...message }, '*');
}

export function onPlatformMessage(type: string, handler: (data: any) => void) {
const listener = (event: MessageEvent) => {
if (event.source !== window.parent) return;
if (event.data?.source !== 'aku-parent' || event.data.type !== type) return;
handler(event.data);
};
window.addEventListener('message', listener);
return () => window.removeEventListener('message', listener);
}
The app's own domain

Do not use the app's own address (window.location.origin) as the target of a message or to validate a response: the platform is on another domain and the message would be lost without an error.

Available messages​

MessageWhat forResponse
INVALIDATE_TAGSReport that the app changed data the platform also shows—
NAVIGATEOpen a ConsulPoint page—
OPEN_URLOpen an external link in a new tabOPEN_URL_RESULT
PREVIEW_EMAILShow a Smart Inbox email over the appPREVIEW_EMAIL_RESULT
INSERT_MESSAGE_TEXTWrite text in the message box of the open conversation—
REFRESH_SESSIONRenew the sessionSESSION_REFRESHED · SESSION_REFRESH_FAILED

The fields of each message are in the Reference.

Refresh the platform's data​

sendToPlatform({
type: 'INVALIDATE_TAGS',
api: 'knowledgeHub',
tags: [{ type: 'KnowledgeHub', id: folderId }],
});

Open a ConsulPoint page​

sendToPlatform({ type: 'NAVIGATE', path: '/contacts/<id>' });

Only allowed paths are followed: the Smart Inbox (/smart-inbox) and Contacts (/contacts). When navigating, the app closes.

Open an external link​

An integrated app cannot open windows or tabs. To open a link, it asks the platform:

sendToPlatform({ type: 'OPEN_URL', url: 'https://example.com/document' });
  • Only https addresses are opened.
  • It must be sent directly from the user's click; otherwise, the browser may block the tab.
  • It cannot be used to open the app's own pages: outside ConsulPoint they have no session.

Show an email​

sendToPlatform({ type: 'PREVIEW_EMAIL', integrationId, messageId });

The platform opens the email in a panel over the app, without leaving it.

Write in the conversation​

Available when the app is opened in the side panel of Conversations:

sendToPlatform({ type: 'INSERT_MESSAGE_TEXT', chatId, text: 'Suggested text' });

The text replaces whatever was in the message box. The person decides whether to send it.

Best practices​

Wait with a limit

When waiting for a response, set a maximum time and remove the listener when the response arrives or the time runs out.

Frequency

The platform discards the messages of an app that sends too many per second. Do not send messages in a loop.