@corto-ai/integrations-messenger

中文文档
0.0.12发布于 2026/11/04TypeScriptES Module近 30 天下载 1万

@corto-ai/integrations-messenger provides messaging utilities for communication between host applications and embedded integrations.

原始使用文档
文档目录11 节
  1. Intended use
  2. Status
  3. Installation
  4. Capabilities
  5. Usage
  6. Initialization
  7. Actions
  8. Forwarding
  9. Demo Repository
  10. Development
  11. License

@corto-ai/integrations-messenger

@corto-ai/integrations-messenger provides messaging utilities for communication between host applications and embedded integrations.

This package is currently in early development and is being published to npm to support internal/dev workflows.

Intended use

This package is intended for teams adding applications into the CORTO platform (for example, iframe-based integrations).

Status

  • Early development
  • API may change between dev releases
  • Documentation will be expanded over time

Installation

npm install @corto-ai/integrations-messenger

Capabilities

  • Handshake & identity -- every window (host or integration) registers itself with a unique id. Nested windows automatically perform a handshake with their parent so both sides know who they're talking to before any action is sent.
  • Origin-checked messaging -- once the handshake completes, messages from a given source are only accepted if they come from the origin observed during that handshake, protecting against messages from unexpected origins.
  • Request/response actions -- typed helpers for the actions below, each with a send{{Action}} (caller side) and handle{{Action}} (implementer side) pair that resolves once a matching response is received.
  • Streaming/pubsub notifications -- a channel-based notification action that can be sent or handled repeatedly, useful for pushing multiple updates over time rather than a single request/response.
  • Automatic forwarding across nested iframes -- if a window has no handler registered for an action, the message is forwarded up/down the iframe tree automatically, so multi-level nesting doesn't require every level to implement every action.
  • Optional debug logging -- pass withLogging: true to init to log handshake and message activity to the console while integrating.

Usage

Initialization

Every window that uses this package -- host and embedded integrations alike -- must call init first:

import messenger from '@corto-ai/integrations-messenger';

await messenger.init({ id: 'my-integration-app' });
  • id is required and must be unique for the window calling init.
  • parentRef is optional and defaults to window.parent. Only override it if the page isn't communicating with its direct parent.
  • withLogging is optional and enables console logging for debugging the handshake/messaging flow.
  • If the window is nested (its parentRef isn't window itself), init also kicks off the handshake with the parent. init resolves once setup is complete; the handshake with the parent finishes asynchronously.

Host applications that embed an integration in an iframe must also call registerChild with a reference to the iframe's contentWindow and the same id the child passed to init:

messenger.registerChild(iframe.contentWindow, 'my-integration-app');

registerChild listens for the handshake from that child and resolves once it completes. Call it before the iframe's own init call runs, or the handshake may be missed.

Actions

messenger.actions groups all supported actions by the entity/flow they affect:

GroupActionDescription
mattersendOpenMatter / handleOpenMatterOpen a matter by matterId.
mattersendOpenChatSession / handleOpenChatSessionOpen a specific chat session (sessionId) on a matter.
mattersendOpenAgentSession / handleOpenAgentSessionOpen a specific agent session (sessionId) on a matter.
mattersendOpenDetails / handleOpenDetailsOpen the details view for a matter.
mattersendOpenEdit / handleOpenEditOpen the edit view for a matter.
mattersendOpenDocumentStatus / handleOpenDocumentStatusOpen the document status view for a matter.
mattersendOpenPrompt / handleOpenPromptOpen a specific prompt (promptId) on a matter.
mattersendOpenPromptLibrary / handleOpenPromptLibraryOpen the prompt library for a matter.
mattersendPreviewDocument / handlePreviewDocumentPreview a document by documentId or presignedUrl. documentName is required.
mattersendSetFullscreen / handleSetFullscreenShow/hide the matter nav and list. Clear automatically on navigation in the host application
contactsendOpenContact / handleOpenContactOpen a contact by contactId.
contactsendOpenEditContact / handleOpenEditContactOpen the edit view for a contact.
settingssendOpenSettings / handleOpenSettingsOpen the host application's settings.
brandingsendGetBranding / handleGetBrandingRequest the active brand name and logo URL, or pass an optional brandName to request a specific brand instead of the active one.
authsendExchangeTokenRequest / handleExchangeTokenRequestExchange a clientId for an auth token.
authsendUserDataRequest / handleUserDataRequestRequest the current user's data from the host (currently returns userId).
pubsubsendNotificationRequest / handleNotificationRequestSubscribe to (or publish) notifications on a channel, supporting multiple responses over time.
pubsubsendStatusRequest / handleStatusRequestSubscribe to the host SignalR hub connection state (Connected, Reconnecting, Disconnected, and the other hub states).
windowsendUpdateUrl / handleUpdateUrlUpdate the url in the host application without navigating. Used to support routing/refreshing within an integration
windowsendOpenModal / handleOpenModalOpens a modal overlay that can be used to host integration iframes. Appends the provided path to the root target origin.
windowsendCloseModal / handleCloseModalCloses a modal overlay that was previously opened with the sendOpenModal command
windowsendOpenConfirmation / handleOpenConfirmationOpens a confirmation dialog. Supports custom title, message, confirmLabel, and cancelLabel, and returns whether the user confirmed.
windowsendOpenToast / handleOpenToastOpen a toast message as either a success, error, info or warning type. Supports custom title, message, and override to detailed configuration. On click of the action button, a response will be returned.
windowsendSetUnsavedChanges / handleSetUnsavedChangesSets a flag on the parent application. When true, if the user tries to navigate away or close the tab, we will pop up a confirmation modal which interupts the navigation and allows the user to cancel
integrationssendGetList / handleGetListReturns a list of integration ids, label, and appNames that are integrated with the host app. Intended to be used in conjunction with integrations.sendOpen in order to trigger one integration from another
integrationssendOpen / handleOpenOpens the provided integration. Prioritizes staying in the same context (ex/ global -> global, matter -> matter), and will fail when navigating from global -> matter if no matterId is provided. Any parameters passed via extraParams will be appended to the target integration's url.

All matter, contact, and settings actions accept an optional newTab flag to indicate the host should open the target in a new tab, and matter actions also accept an optional matterId beyond what's called out above.

For each action, the send... function is intended for the embedded integration to call, to ask the host application to perform some action or return some data. The matching handle... function is intended to be implemented by the host application: it registers a callback that receives the request and returns the response to send back.

// in the host application
await messenger.init({ id: 'host' });

messenger.registerChild(iframe.contentWindow, 'child');

messenger.actions.matter.handleOpenChatSession(async ({ matterId, sessionId }) => {
  try {
    await someService.openSession(matterId, sessionId);
    return { success: true };
  } catch (err) {
    return { success: false, error: err.message };
  }
});

// in the embedded integration
await messenger.init({ id: 'child' });

const response = await messenger.actions.matter.sendOpenChatSession({
  matterId: '123',
  sessionId: 'abc'
});

if (response.success) {
  // happy path
} else {
  // sad path
}

Streaming actions (pubsub)

pubsub notifications differ from the other actions: instead of resolving once with a single response, sendNotificationRequest and handleNotificationRequest can fire their callback multiple times for the same channel, and both return a handle with a remove() function to stop listening.

// listen for notifications on a channel
const handle = messenger.actions.pubsub.sendNotificationRequest({ channel: 'documents' }, (notification) => {
  console.log('received', notification.data);
});

// later, stop listening
handle.remove();

const statusHandle = messenger.actions.pubsub.sendStatusRequest(({ status }) => {
  console.log(status);
});

statusHandle.remove();

Modal communication

As mentioned above, the window.sendOpenModal command allows integrations to trigger a modal overlay and display a custom modal from their application. Its worth noting though that this new modal will not be able to communicate with the parent application. Modals should instead communicate with their sibling integration (ie the integration which opened the modal) via the BroadcastChannelAPI. This way they can notify the sibling of whatever user interaction might be required, including closing the modal.

Forwarding

In order to support multiple levels of iframe nesting, the package inherently has a "forwarding" mechanic: for any action, if no handler is defined in a given window, the message continues up or down the iframe tree until a handler picks it up. This is enabled by default and requires no opt-in.

Adding a handler in a child application can shadow the same action's handling in a parent application, since forwarding only happens when a handler isn't defined. If you're not sure whether you should implement a handler for a given action, don't -- let it forward to the host.

Demo Repository

We have set up a demo repository with react/angular applications as an example of how to use this package.

Development

This library is maintained by CORTO and published as part of the regular package release workflow.

For more information, visit https://www.docorto.ai.

License

License details will be documented as this package moves toward stable releases.

版本与发布记录

@corto-ai/integrations-messenger 共发布 35 个版本,首次发布于 2026/06/05;过去 12 个月发布了 35 个版本。

版本发布日期距今
0.0.12latest2026/11/046 天前
0.0.12-test.0test2026/10/2913 天前
0.0.12-dev.0dev2026/10/2913 天前
0.0.112026/10/061 个月前
0.0.11-test.02026/09/251 个月前
0.0.11-dev.02026/09/251 个月前

关于 @corto-ai/integrations-messenger 的常见问题

@corto-ai/integrations-messenger 是什么?

@corto-ai/integrations-messenger provides messaging utilities for communication between host applications and embedded integrations.

如何安装 @corto-ai/integrations-messenger?

在项目目录运行 npm install @corto-ai/integrations-messenger,或使用 pnpm add / yarn add / bun add。

@corto-ai/integrations-messenger 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@corto-ai/integrations-messenger 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@corto-ai/integrations-messenger 可以商用吗?

@corto-ai/integrations-messenger 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@corto-ai/integrations-messenger 的下载量有多少?

根据 npm 官方下载统计,@corto-ai/integrations-messenger 在 2026/10/11 – 2026/11/09 这 30 天内被下载 10,465 次,日均约 349 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@corto-ai/integrations-messenger 还在维护吗?

最新版本 0.0.12 发布于 2026/11/04(6 天前);至今共发布 35 个版本,其中过去 12 个月发布了 35 个;首次发布于 2026/06/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。