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
- Send to the parent window with target
'*'. The message only reaches ConsulPoint, which is what shows the app. - Mark every message with
source: 'aku-iframe'. Without that mark, it is ignored. - Accept a response only if it comes from the parent window and carries
source: 'aku-parent'. - Send nothing outside ConsulPoint: if the app is not inside the platform, there is no one to talk to.
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);
}
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
| Message | What for | Response |
|---|---|---|
INVALIDATE_TAGS | Report that the app changed data the platform also shows | — |
NAVIGATE | Open a ConsulPoint page | — |
OPEN_URL | Open an external link in a new tab | OPEN_URL_RESULT |
PREVIEW_EMAIL | Show a Smart Inbox email over the app | PREVIEW_EMAIL_RESULT |
INSERT_MESSAGE_TEXT | Write text in the message box of the open conversation | — |
REFRESH_SESSION | Renew the session | SESSION_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
httpsaddresses 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
When waiting for a response, set a maximum time and remove the listener when the response arrives or the time runs out.
The platform discards the messages of an app that sends too many per second. Do not send messages in a loop.