# Methods

> Every method on window.Iris. Calls made before iris.js loads wait in a queue.

contextValuesSchema,
  irisInitOptionsSchema,
  sendMessageOptionsSchema,
} from "../../../schemas";

## Iris.init(options)

Starts the widget on your page. Every option is in [`Iris.init`](/reference/init/).

```js title="index.html"
Iris.init({ appId: "app_7Hq2xK9mPz" });
```

## Iris.identify({ token })

Signs the contact in as one of your signed-in users. `token` is an identity token that your server signs. See [Identify users](/guides/identify-users/).

```js title="app.js"
Iris.identify({ token });
```

## Iris.logout()

Signs the contact out and starts a new anonymous session. Call it when the user signs out of your product.

```js title="app.js"
Iris.logout();
```

## Iris.open()

Opens the widget. To open it from a link with no code, see [Open from a link](/guides/open-from-a-link/).

```js title="app.js"
document.querySelector("#help").addEventListener("click", () => Iris.open());
```

## Iris.close()

Closes the widget and moves the focus back to where it was before the widget opened.

```js title="app.js"
Iris.close();
```

## Iris.setPageContext(values)

Sets the page context: facts about where the contact is in your product, for agents and triage. Each call replaces the earlier page context. See [Page context](/guides/page-context/).

```js title="app.js"
Iris.setPageContext({ plan: "pro", cartTotal: 42.5 });
```

| Name | Type | Required | Default | Description | Example |
| --- | --- | --- | --- | --- | --- |
| `<key>` | `string \| number \| boolean \| null` | No |  | Iris keeps the keys in the order you send them. Key: up to 64 characters. String value: up to 500 characters. | `plan: "pro"` |

## Iris.sendMessage(options)

Sends a message from the contact, as if they typed it in the widget. Use it for your own buttons, such as "Report issue" on a video. See [Send a message from your code](/guides/send-a-message/).

- The widget does not open, and the screen it shows does not change.
- Each call starts a new conversation. Triage runs on it like on any new conversation.
- It returns a Promise. The Promise resolves when Iris saves the message, and rejects when the message is not sent.

```js title="app.js"
await Iris.sendMessage({
  body: "There is an issue with video ABC",
  context: { videoId: "abc" },
});
```

| Name | Type | Required | Default | Description | Example |
| --- | --- | --- | --- | --- | --- |
| `body` | `string` | Yes |  | The text of the message, as the contact would type it. Text only. Length: 1 to 5000 characters. | `body: "There is an issue with video ABC"` |
| `context` | `object` | No |  | Page context for this message only. Iris adds it to the page context from `Iris.setPageContext`, and a key here wins over the same key there. Iris sets `url` and `title` itself. Size: up to 48 keys. | `context: { videoId: "abc" }` |
| `context.<key>` | `string \| number \| boolean \| null` | No |  | Iris keeps the keys in the order you send them. Key: up to 64 characters. String value: up to 500 characters. | `videoId: "abc"` |

## Iris.update(options)

Changes widget options after `Iris.init`. See [`Iris.update`](/reference/update/).

```js title="app.js"
Iris.update({ launcher: false });
```

| Name | Type | Required | Default | Description | Example |
| --- | --- | --- | --- | --- | --- |
| `launcher` | `boolean` | No | `true` | Shows the launcher. Pass `false` to hide it and open the widget from your own button with [`data-iris-open`](/guides/open-from-a-link/) or `Iris.open()`. To change it later, call [`Iris.update`](/reference/update/). | `launcher: false` |

## Iris.on(event, listener)

With `"unread"`, calls `listener` with the number of unread agent messages. With `"close"`, calls it when the contact closes the widget. See [Events](/reference/events/).

```js title="app.js"
Iris.on("unread", (count) => console.log(count));
```
