Website SDK JavaScript APIs

We have following JavaScript API available in chat SDK.

open()

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

window.gleenWidget.open()

close()

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

window.gleenWidget.close()

toggle()

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

window.gleenWidget.toggle()

sendMessage(messageText)

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

window.gleenWidget.toggle()

on(eventName, callback)

Handles events triggered by the chat widget.

See Website SDK events for a full list of events available.

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

getFingerprint()

Get the unique user ID from the chat widget.

window.gleenWidget.getFingerPrint()

getTicketID()

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

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

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.

window.gleenWidget.initializeFAQWidget()

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 & Checkout Event API for more details.

closeTicket()

Close the current conversation. As a result, the next message sent by the user will be part of a new conversation.

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.

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 for an example.

Last updated