---
description: We have following JavaScript API available in chat SDK.
---

# Website SDK JavaScript APIs

### **open()**&#x20;

Opens the chat window. If it is already opened it will leave the chat widget as it is

```javascript
window.gleenWidget.open()
```

### **close()**&#x20;

Closes the chat window. If it is already closed it will leave the chat sdk as it is on UI. &#x20;

```javascript
window.gleenWidget.close()
```

### **toggle()**&#x20;

Closes the chat window if it is opened and vice - versa.

```javascript
window.gleenWidget.toggle()
```

### **sendMessage(messageText)**&#x20;

Opens the widget with the given message send from the user's perspective.

```javascript
window.gleenWidget.sendMessage("Hello, world!")
```

### **on(eventName, callback)**&#x20;

Handles events triggered by the chat widget.

&#x20;See [website-sdk-events](website-sdk-javascript-apis/website-sdk-events "mention") for a full list of events available.

```javascript
window.gleenWidget.on('widget:opened', () => console.log("widget was opened")
```

### getFingerprint()

Get the unique user ID from the chat widget.

```javascript
window.gleenWidget.getFingerPrint()
```

### getTicketID()

Get the unique ticket ID as it appears in the Alhena conversations page for the current conversation.

```javascript
window.gleenWidget.getTicketID()
```

### getFAQFingerprint()

Get the unique user ID from the product FAQs widget. Returns a different value from the chat widget `getFingerprint`  function. Returns `undefined` if the FAQ widget is not installed on the page

```javascript
window.gleenWidget.getFAQFingerPrint()
```

### initializeFAQWidget()

Manually trigger the FAQ widget to render inside of the `#gleen-product-faqs` container. This is useful on single page app style websites where the FAQ widget might not load automatically on page change.

```javascript
window.gleenWidget.initializeFAQWidget()
```

### hideNudge()

Hide any active nudge. This is useful if you'd like to programmatically control the nudge's visibility, overriding the time and scroll based rules.&#x20;

Once you call this function, the rules you've configured in the dashboard will be ignored, and you must call `showNudge()` to make the nudge visible. You can call this function before `showNudge()` to disable the default triggers.

See [Broken link](broken-reference "mention")

```javascript
window.gleenWidget.hideNudge()
```

### showNudge()

Manually trigger the nudge to show, ignoring the time based and scroll based triggers. Note, if the user has dismissed the nudge, it still won't appear when you call this function. `hideNudge()` and `showNudge()` are meant for creating more complex triggers that the standard ones configured in dashboard don't allow.

```javascript
window.gleenWidget.showNudge()
```

### hideLauncher()

Manually set the widget launcher icon as hidden. This is useful if you'd like to set your own trigger for toggling the widget with `window.gleenWidget.toggle`()  (or with the `open()` and `close()`  methods).

```javascript
window.gleenWidget.hideLauncher()
```

You can also pass the `hideLauncher`  property to your configuration if you'd like it to default to hidden

```html
document.gleenConfig = {
  company: "gleen",
  apiBaseUrl: "https://app.alhena.ai",
  hideLauncher: true
};
```

### showLauncher()

Set the launcher to visible again after you've used `hideLauncher()` .

```javascript
window.gleenWidget.showLauncher()
```

### setCompanyKey()

Change the profile for your widget after it's already been loaded in the page. For example, if you have set your widget up like this:

```javascript
document.gleenConfig = {
  company: "gleen",
  apiBaseUrl: "https://app.alhena.ai",
};
```

Then you can use this code to change `gleen` to another profile.

```javascript
window.gleenWidget.setCompanyKey("gleen-aidemo")
```

### sendCartEvent() and sendCheckoutEvent()

You can send cart events and checkout events for revenue attribution purposes, and track in Alhena's analytics to attribute revenue driven by Alhena.

See [cart-and-checkout-event-api](website-sdk-javascript-apis/cart-and-checkout-event-api "mention") for more details.

### **closeTicket()**&#x20;

**C**lose the current conversation. As a result, the next message sent by the user will be part of a new conversation. &#x20;

If you are hiding the Alhena widget and showing some other wiget such as Gladly on human handoff, this is helpful to clear the conversation.&#x20;

To call this **closeTicket(),** recommended way is to listen for **ticket:agent\_handoff** or **ticket:agent\_handoff\_initiated event.** Then start a JS timer for few seconds and call **closeTicket()**

See [open-other-external-widget-once-human-transfer-is-initiated](chat-sdk-api-and-events-examples/open-other-external-widget-once-human-transfer-is-initiated "mention") for an example.

