---
updatedAt: 2026-07-29T18:29:36.000Z
agentTools:
  projectIndex: https://docs.endearhq.com/llms.txt
---

# Javascript API: Methods

Loading the Endear SDK provides an endear JavaScript object that responds to a few methods. These allow you to track activity happening within the SalesChat widget & trigger certain commands.

### `endear("onReady")`

To perform an operation only *after* the SDK has fully booted, add your logic to the callback of the 'onReady' method. You can access the initialState (available as `endear.initialState` or `e.detail.initialState`. The type of the `initialState` is `WidgetInitialState`

```Text JavaScript
window.endear("onReady", (e) => {
  console.log("The widget is ready", e.detail.initialState)
});
```

### `endear("open")`

Calling this method will open & show the SalesChat widget.

```Text JavaScript
window.endear("open");
```

### `endear("close")`

Calling this method will close the SalesChat widget, but it will not hide it.

```Text JavaScript
window.endear("close");
```

### `endear("show")`

Calling this method will show the SalesChat widget, but it will not open it.

```Text JavaScript
window.endear("show");
```

### `endear("hide")`

Calling this method will close & hide the SalesChat widget.

```Text JavaScript
window.endear("hide");
```

### `endear("onOpen")`

Your callback will be triggered when the widget is opened.

```Text JavaScript
window.endear("onOpen", () => {
  console.log("The widget was opened")
});
```

### `endear("onClose")`

Your callback will be triggered when the widget is closed.

```Text JavaScript
window.endear("onClose", () => {
  console.log("The widget was closed")
});
```

### `endear("onMessage")`

Your callback will be triggered when a message is sent or received. **This method may trigger for the same message multiple times.**

```Text JavaScript
window.endear("onMessage", (e) => {
  console.log("Message was sent or received", e.detail)
});
```

### `endear("onConversationUpdated")`

Your callback will be triggered when a conversation received an update. **This method may trigger for the same conversation update multiple times.**

```Text JavaScript
window.endear("onConversationUpdated", (e) => {
  console.log("Conversation was updated", e.detail)
});
```

### `endear("onConversationClaimed")`

Your callback will be triggered when a conversation is claimed. **This method will only trigger if the conversation is claimed within the current session.**

```Text JavaScript
window.endear("onConversationClaimed", (e) => {
  console.log("Conversation was claimed", e.detail)
});
```

### `endear("onConversationStatusChanged")`

Your callback will be triggered when a conversation's status changes. **This method will only trigger if the conversation status changes within the current session.**

```Text JavaScript
window.endear("onConversationStatusChanged", (e) => {
  console.log("Conversation status was changed", e.detail)
});
```

### `endear("setCustomAttribute", payload)`

Calling this method will update a custom attribute field on the Conversation. **Do not use this method within an`onConversationUpdated` callback without a short-circuit as it will trigger an infinite loop.**

```Text JavaScript (text)
window.endear("setCustomAttribute", {
  type: "TEXT",
  key: "foo",
  value: "bar"
});
```
```text JavaScript (url)
window.endear("setCustomAttribute", {
  type: "URL",
  key: "foo",
  value: { url: "https://example.com", name: document.title }
});
```
```text JavaScript (boolean)
window.endear("setCustomAttribute", {
  type: "BOOLEAN",
  key: "foo",
  value: true
});
```
```text JavaScript (date)
window.endear("setCustomAttribute", {
  type: "DATE",
  key: "foo",
  label: "bar",
  value: "2025-12-31T23:59:59Z"
});
```
```text JavaScript (money)
window.endear("setCustomAttribute", {
  type: "MONEY",
  key: "foo",
  label: "bar",
  value: { amount: 1000, precision: 2, currency: "USD" }
});
```