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

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

endear("open")

Calling this method will open & show the SalesChat widget.

window.endear("open");

endear("close")

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

window.endear("close");

endear("show")

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

window.endear("show");

endear("hide")

Calling this method will close & hide the SalesChat widget.

window.endear("hide");

endear("onOpen")

Your callback will be triggered when the widget is opened.

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

endear("onClose")

Your callback will be triggered when the widget is closed.

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.

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.

window.endear("onConversationUpdated", (e) => {
  console.log("Convesation 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.

window.endear("onConversationClaimed", (e) => {
  console.log("Convesation 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.

window.endear("onConversationStatusChanged", (e) => {
  console.log("Convesation 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 anonConversationUpdated callback without a short-circuit as it will trigger an infinite loop.

window.endear("setCustomAttribute", {
  conversationId: "current-conversation-id",
  type: "TEXT",
  key: "foo",
  value: "bar"
});
window.endear("setCustomAttribute", {
  conversationId: "current-conversation-id",
  type: "URL",
  key: "foo",
  value: "https://example.com"
});