Skip to content
Dashboard
Open .md fileOpen llms.txtA list of every page, for AI tools

Guides

Send a message from your code

Send a message to Iris from your own button, such as "Report issue", without opening the widget.

Call Iris.sendMessage from your own button. The message comes from the current contact, anonymous or identified, and starts a new conversation. Agents see it in the inbox like a message typed in the widget.

app.js
reportButton.addEventListener("click", async () => {
try {
await Iris.sendMessage({
body: `There is an issue with video ${video.title}`,
context: { videoId: video.id },
});
showToast("Thanks, we got your report");
} catch {
showToast("Could not send the report. Try again.");
}
});
  • The widget stays closed, and an open widget stays on its screen. Show your own confirmation, like the toast above.
  • Each call starts a new conversation, so each report gets its own triage and topic.
  • The new conversation shows in the widget’s conversation list. An agent reply counts in the unread event like any reply.

Every option is in Iris.sendMessage.

The message gets the page context of the page: the values from Iris.setPageContext, plus url and title. Iris adds context to them for this message only, and a key in context wins over the same key there. Later messages do not get context. In this example, the message gets plan, videoId, url and title.

app.js
Iris.setPageContext({ plan: "pro" });
await Iris.sendMessage({
body: "The video does not play",
context: { videoId: "abc" },
});

The page context and context together keep to the page context limits: up to 48 of your own keys. context cannot set url or title.

The Promise rejects, and the console shows a warning, when:

  • Iris.sendMessage ran before Iris.init;
  • body or context is outside the limits;
  • the request to Iris failed, for example because the network dropped.

Iris sends nothing in the first two cases.

MessageWhat happenedFix
Iris: <method> ran before Iris.init, so nothing changed.#identify, logout, update or sendMessage ran before Iris.init. After an early identify, the contact stays anonymous. An early sendMessage sends nothing, and its Promise rejects.Call Iris.init({ appId }) first. Calls made before iris.js loads wait in a queue, in order.
Iris: sendMessage sent nothing, because the message or its context is outside the limits.#body is empty or longer than 5,000 characters, or context is not a flat object, has url or title, or goes over the page context limits together with the page context. The Promise rejects.Keep to the Iris.sendMessage limits.
Iris: <action> failed: <reason>.#A request to Iris failed, for example because the network dropped or Iris had an error.Check your connection and the network tab of your browser, then reload the page.

A call made before iris.js loads waits in a queue and runs when iris.js loads.