Applet JS API Reference

Classes

ChatMessage

A general class from which more specific message classes inherit.OperatorAssistantMessageChatMessage

Message that is sent by an operator assistant to the human operator. The sender type of this message is SENDER_TYPES.OPERATOR_ASSISTANT.OperatorMessageChatMessage

A message sent by a human operator or a virtual assistant to the visitor. The sender type of this message is SENDER_TYPES.OPERATOR.SystemMessageChatMessage

Message generated by the system. E.g CoBrowsing started, etc. The sender type of this message is SENDER_TYPES.SYSTEM.VisitorMessageChatMessage

Message sent by the visitor. The sender type of this message is SENDER_TYPES.VISITOR.Engagement

Encapsulates the engagement information.Glia

Allows adding listeners to events that happen in Glia Hub as well as perform other global operations.Queue

Encapsulates the queue information.Visitor

Encapsulates the visitor information.

ChatMessage

A general class from which more specific message classes inherit.

Kind: global class

chatMessage.id

Kind: instance property of ChatMessage Properties

Name

Type

Description

id

string

Identifier of the message. This identifier can be used to track a single message's status updates through time and to avoid re-rendering the entire list of messages when the status of only a single message has changed.

chatMessage.content

Kind: instance property of ChatMessage Properties

Name

Type

Description

content

string

Content of the message.

chatMessage.SENDER_TYPES

Kind: instance property of ChatMessage Properties

Name

Type

Description

SENDER_TYPES

object

Possible message sender types.

SENDER_TYPES.OPERATOR

string

Refers to the human operator as the sender, used as sender type in [OperatorMessage](#OperatorMessage).

SENDER_TYPES.VISITOR

string

Refers to the visitor as the sender, used as sender type in [VisitorMessage](#VisitorMessage).

SENDER_TYPES.SYSTEM

string

Refers to the Glia system as the sender, used as sender type in [SystemMessage](#SystemMessage).

SENDER_TYPES.OPERATOR_ASSISTANT

string

Referes to the operator assistant as the sender, used as sender type in [OperatorAssistantMessage](#OperatorAssistantMessage).

chatMessage.sender

Kind: instance property of ChatMessage Properties

Name

Type

Description

sender

object

The sender of the message.

sender.type

string

The type refers to the originator of the message. See SENDER_TYPES. If the sender is an operator assistant, then the type would be SENDER.TYPE.OPERATOR_ASSISTANT.

OperatorAssistantMessage ⇐ ChatMessage

Message that is sent by an operator assistant to the human operator. The sender type of this message is SENDER_TYPES.OPERATOR_ASSISTANT.

Kind: global class Extends: ChatMessage

operatorAssistantMessage.id

Kind: instance property of OperatorAssistantMessage Overrides: id Properties

Name

Type

Description

id

string

Identifier of the message. This identifier can be used to track a single message's status updates through time and to avoid re-rendering the entire list of messages when the status of only a single message has changed.

operatorAssistantMessage.content

Kind: instance property of OperatorAssistantMessage Overrides: content Properties

Name

Type

Description

content

string

Content of the message.

operatorAssistantMessage.TYPES : Object

Kind: instance property of OperatorAssistantMessage Properties

Name

Type

Description

TYPES.SUGGESTION

string

Message that is suggested to the human operator for sending directly to the visitor.

TYPES.PROMPT

string

Message that is meant as a hint to operator on how to proceed with the engagement.

operatorAssistantMessage.type

Kind: instance property of OperatorAssistantMessage Properties

Name

Type

Description

type

string

Operator assistant's message type, see TYPES.

operatorAssistantMessage.SENDER_TYPES

Kind: instance property of OperatorAssistantMessage Overrides: SENDER_TYPES Properties

Name

Type

Description

SENDER_TYPES

object

Possible message sender types.

SENDER_TYPES.OPERATOR

string

Refers to the human operator as the sender, used as sender type in [OperatorMessage](#OperatorMessage).

SENDER_TYPES.VISITOR

string

Refers to the visitor as the sender, used as sender type in [VisitorMessage](#VisitorMessage).

SENDER_TYPES.SYSTEM

string

Refers to the Glia system as the sender, used as sender type in [SystemMessage](#SystemMessage).

SENDER_TYPES.OPERATOR_ASSISTANT

string

Referes to the operator assistant as the sender, used as sender type in [OperatorAssistantMessage](#OperatorAssistantMessage).

operatorAssistantMessage.sender

Kind: instance property of OperatorAssistantMessage Overrides: sender Properties

Name

Type

Description

sender

object

The sender of the message.

sender.type

string

The type refers to the originator of the message. See SENDER_TYPES. If the sender is an operator assistant, then the type would be SENDER.TYPE.OPERATOR_ASSISTANT.

OperatorMessage ⇐ ChatMessage

A message sent by a human operator or a virtual assistant to the visitor. The sender type of this message is SENDER_TYPES.OPERATOR.

Kind: global class Extends: ChatMessage

operatorMessage.STATUSES : Object

Kind: instance property of OperatorMessage Properties

Name

Type

Description

STATUSES.SENDING

string

The message is being sent but has not yet been received by the visitor.

STATUSES.DELIVERED

string

The message has been successfully sent and the visitor has received it.

STATUSES.FAILED

string

The message's delivery has failed. This may sometimes happen in poor network conditions.

operatorMessage.status

Kind: instance property of OperatorMessage Properties

Name

Type

Description

status

string

Message delivery status, see STATUSES.

operatorMessage.attachment

Kind: instance property of OperatorMessage Properties

Name

Type

Description

attachment

object

Conditional attachment block of the message. It allows enhancing UX by providing response cards, file attachments and other types of rich content.

operatorMessage.metadata

Kind: instance property of OperatorMessage Properties

Name

Type

Description

metadata

object

Any additional data that can be parsed by the receiver for additional context.

operatorMessage.id

Kind: instance property of OperatorMessage Overrides: id Properties

Name

Type

Description

id

string

Identifier of the message. This identifier can be used to track a single message's status updates through time and to avoid re-rendering the entire list of messages when the status of only a single message has changed.

operatorMessage.content

Kind: instance property of OperatorMessage Overrides: content Properties

Name

Type

Description

content

string

Content of the message.

operatorMessage.SENDER_TYPES

Kind: instance property of OperatorMessage Overrides: SENDER_TYPES Properties

Name

Type

Description

SENDER_TYPES

object

Possible message sender types.

SENDER_TYPES.OPERATOR

string

Refers to the human operator as the sender, used as sender type in [OperatorMessage](#OperatorMessage).

SENDER_TYPES.VISITOR

string

Refers to the visitor as the sender, used as sender type in [VisitorMessage](#VisitorMessage).

SENDER_TYPES.SYSTEM

string

Refers to the Glia system as the sender, used as sender type in [SystemMessage](#SystemMessage).

SENDER_TYPES.OPERATOR_ASSISTANT

string

Referes to the operator assistant as the sender, used as sender type in [OperatorAssistantMessage](#OperatorAssistantMessage).

operatorMessage.sender

Kind: instance property of OperatorMessage Overrides: sender Properties

Name

Type

Description

sender

object

The sender of the message.

sender.type

string

The type refers to the originator of the message. See SENDER_TYPES. If the sender is an operator assistant, then the type would be SENDER.TYPE.OPERATOR_ASSISTANT.

SystemMessage ⇐ ChatMessage

Message generated by the system. E.g CoBrowsing started, etc. The sender type of this message is SENDER_TYPES.SYSTEM.

Kind: global class Extends: ChatMessage

systemMessage.id

Kind: instance property of SystemMessage Overrides: id Properties

Name

Type

Description

id

string

Identifier of the message. This identifier can be used to track a single message's status updates through time and to avoid re-rendering the entire list of messages when the status of only a single message has changed.

systemMessage.content

Kind: instance property of SystemMessage Overrides: content Properties

Name

Type

Description

content

string

Content of the message.

systemMessage.TYPES : Object

Kind: instance property of SystemMessage Properties

Name

Type

Description

TYPES.USER

string

System messages of this type are notifications describing an action of the user, e.g. CoBrowsing start, media upgrade.

TYPES.VISITOR_AUTHENTICATION

string

Visitor authentication request message with authentication attributes generated by the system.

systemMessage.type

Kind: instance property of SystemMessage Properties

Name

Type

Description

type

string

System message type, see TYPES.

systemMessage.metadata

Kind: instance property of SystemMessage Properties

Name

Type

Description

metadata

object

Conditional metadata block of the message. For system messages will be only provided when dealing with VISITOR_AUTHENTICATION messages.

systemMessage.SENDER_TYPES

Kind: instance property of SystemMessage Overrides: SENDER_TYPES Properties

Name

Type

Description

SENDER_TYPES

object

Possible message sender types.

SENDER_TYPES.OPERATOR

string

Refers to the human operator as the sender, used as sender type in [OperatorMessage](#OperatorMessage).

SENDER_TYPES.VISITOR

string

Refers to the visitor as the sender, used as sender type in [VisitorMessage](#VisitorMessage).

SENDER_TYPES.SYSTEM

string

Refers to the Glia system as the sender, used as sender type in [SystemMessage](#SystemMessage).

SENDER_TYPES.OPERATOR_ASSISTANT

string

Referes to the operator assistant as the sender, used as sender type in [OperatorAssistantMessage](#OperatorAssistantMessage).

systemMessage.sender

Kind: instance property of SystemMessage Overrides: sender Properties

Name

Type

Description

sender

object

The sender of the message.

sender.type

string

The type refers to the originator of the message. See SENDER_TYPES. If the sender is an operator assistant, then the type would be SENDER.TYPE.OPERATOR_ASSISTANT.

VisitorMessage ⇐ ChatMessage

Message sent by the visitor. The sender type of this message is SENDER_TYPES.VISITOR.

Kind: global class Extends: ChatMessage

visitorMessage.attachment

Kind: instance property of VisitorMessage Properties

Name

Type

Description

attachment

object

Conditional attachment block for message. Should be provided only when visitor selects one of the pre-defined options.

visitorMessage.TYPES : Object

Kind: instance property of VisitorMessage Properties

Name

Type

Description

TYPES.USER

string

Chat messages from the visitor.

TYPES.EVENT

string

Event records generated by the visitor.

visitorMessage.type

Kind: instance property of VisitorMessage Properties

Name

Type

Description

type

string

Chat message type, see TYPES.

visitorMessage.metadata

Kind: instance property of VisitorMessage Properties

Name

Type

Description

metadata

object

Any additional data that can be parsed by the applet. For more information see Chat Message Metadata.

visitorMessage.id

Kind: instance property of VisitorMessage Overrides: id Properties

Name

Type

Description

id

string

Identifier of the message. This identifier can be used to track a single message's status updates through time and to avoid re-rendering the entire list of messages when the status of only a single message has changed.

visitorMessage.content

Kind: instance property of VisitorMessage Overrides: content Properties

Name

Type

Description

content

string

Content of the message.

visitorMessage.SENDER_TYPES

Kind: instance property of VisitorMessage Overrides: SENDER_TYPES Properties

Name

Type

Description

SENDER_TYPES

object

Possible message sender types.

SENDER_TYPES.OPERATOR

string

Refers to the human operator as the sender, used as sender type in [OperatorMessage](#OperatorMessage).

SENDER_TYPES.VISITOR

string

Refers to the visitor as the sender, used as sender type in [VisitorMessage](#VisitorMessage).

SENDER_TYPES.SYSTEM

string

Refers to the Glia system as the sender, used as sender type in [SystemMessage](#SystemMessage).

SENDER_TYPES.OPERATOR_ASSISTANT

string

Referes to the operator assistant as the sender, used as sender type in [OperatorAssistantMessage](#OperatorAssistantMessage).

visitorMessage.sender

Kind: instance property of VisitorMessage Overrides: sender Properties

Name

Type

Description

sender

object

The sender of the message.

sender.type

string

The type refers to the originator of the message. See SENDER_TYPES. If the sender is an operator assistant, then the type would be SENDER.TYPE.OPERATOR_ASSISTANT.

Engagement

Encapsulates the engagement information.

Kind: global class

engagement.engagementId

Kind: instance property of Engagement Properties

Name

Type

Description

engagementId

string

Current engagement ID.

engagement.engagementLegId

Kind: instance property of Engagement Properties

Name

Type

Description

engagementLegId

string

Current engagement leg ID.

engagement.engagementQueues

Kind: instance property of Engagement Properties

Name

Type

Description

engagementQueues

object

data about engagement source.

[engagementQueues.enqueuedAt]

string

UTC time when the visitor enqueued for engagement in the ISO-8601 format.

[engagementQueues.queues]

array

{Queue} instances through which the visitor enqueued. Queues of current engagement.

Glia

Allows adding listeners to events that happen in Glia Hub as well as perform other global operations.

Kind: global class

glia.STORAGE_TYPES : Object

Kind: instance property of Glia Properties

Name

Type

Description

IN_MEMORY

string

Data is stored in the current JavaScript runtime memory of the Glia Hub. This means the data will persist until the browser is refreshed or until the user logs out from Glia Hub. This option should be used when storing sensitive user-specific data such as authentication tokens that you do not wish to persist for other users of the same browser.

SESSION_STORAGE

string

Data is stored in the sessionStorage property of the browser window. The data stored will persist until the Glia Hub browser tab or window is closed. Other websites besides app.glia.com are not able to access the data.

LOCAL_STORAGE

string

Data is stored in the localStorage property of the browser window. The data stored will persist even after the Glia Hub browser tab or window has been closed. Other websites besides app.glia.com are not able to access the data.

glia.addBufferedEventListener ⇒ void

Registers buffered event listener on {Glia}.

This listener has a buffer for events that occurred before the listener was added. It will buffer the last event that was fired before any listeners were added. In another word, if a listener is added during or after an event has occurred, the listener will trigger immediately. This can be useful, for example, if a listener should fire for events that occurred during page loading and all the scripts were not yet initialized.

If multiple identical listeners are registered on the same event type, the duplicate instances are discarded. They do not cause the listener to be called twice and do not need to be removed with the removeBufferedEventListener method.

Kind: instance property of Glia

Param

Type

Description

type

string

The event type for which the user is registering. Must be one of {Glia.EVENTS}.

listener

function

The listener function that will be called when the event occurs.

glia.removeBufferedEventListener ⇒ void

Removes a buffered event listener from {Glia}.

If an event listener is removed while {Glia} is processing an event, it will not be triggered with the current event.

An event listener is never invoked after being removed.

Calling removeBufferedEventListener with arguments which do not identify any currently registered listener has no effect.

Kind: instance property of Glia

Param

Type

Description

type

string

The event type for the listener being removed.

listener

function

The event listener to be removed.

glia.storeAxonData(key, data, storageType) ⇒ void

Stores arbitrary data for a specific type of applet. In case two or more instances of the same applet are being displayed (e.g. in multi-engage), both applet instances have access to the same data. Examples of data to store include authentication tokens to external services that only periodically need to be fetched and thus can be reused by the same applet when they are displayed.

Specifying a key that already has data stored will overwrite the existing data.

How the data persists throughout browser sessions depends on the storageType option.

Kind: instance method of Glia Throws:

  • Error an error is thrown in the case of invalid parameters.

Param

Type

Description

key

string

The key under which the data will be stored.

data

string

The data to be stored. Only data of type String is supported.

storageType

string

The type of storage to write to. Defaults to {Glia.STORAGE_TYPES.IN_MEMORY} when not specified. Value must be one of {Glia.STORAGE_TYPES}. See documentation for {Glia.STORAGE_TYPES} for more information.

glia.getAxonData(key, storageType) ⇒ Promise

Fetches the data previously stored using saveToAxonStorage.

Kind: instance method of Glia Returns: Promise - Fulfilled with the data of type String stored under the key or null if no data was stored. Rejected with {Error} in the case of invalid parameters.

Param

Type

Description

key

string

The key under which the data will be fetched.

storageType

string

The storage type to get data from. Defaults to {Glia.STORAGE_TYPES.IN_MEMORY} when not specified. Value must be one of {Glia.STORAGE_TYPES}. See documentation for {Glia.STORAGE_TYPES} for more information.

glia.sendChatMessage(message) ⇒ void

Sends a chat message to the visitor.

Kind: instance method of Glia

Param

Type

Description

message

object

Message object

message.content

string

Text content

message.attachment

object

Attachments (See attachments section for more information)

message.metadata

object

Any additional data that will be parsed by the receiver (See chat message metadata section for more information)

"VISITOR_STATE"

An event that is triggered when the visitor's state changes. For instance, the event is triggered when visitor's custom attributes are updated. The event listener will be called with a [Visitor](#Visitor) instance.

Kind: event emitted by Glia Example (Show visitor name on the page)

function visitorNameListener(visitor) {
var nameElementId = 'visitor-name';
var name = document.getElementById(nameElementId);
if (!name) {
var name = document.createElement('span');
name.id = nameElementId;
document.body.appendChild(name);
}
name.innerText = visitor.name;
}
glia.addBufferedEventListener(
glia.EVENTS.VISITOR_STATE,
visitorNameListener
);

"ENGAGEMENT_STATE"

An event that is used for getting visitor's current engagement attributes. Triggered when any of the attributes change and on first subscription if an engagement exists. The event listener will be called with an [Engagement](#Engagement) instance.

Kind: event emitted by Glia Example (Show visitor's engagement ID on the page)

function visitorEngagementIdListener(engagement) {
var engagementIdElementId = 'visitor-engagement-id';
var engagementIdElement = document.getElementById(engagementIdElementId);
if (!engagementIdElement) {
var engagementIdElement = document.createElement('span');
engagementIdElement.id = engagementIdElementId;
document.body.appendChild(engagementIdElement);
}
engagementIdElement.innerText = engagement.engagementId;
}
glia.addBufferedEventListener(
glia.EVENTS.ENGAGEMENT_STATE,
visitorEngagementIdListener
);

"CHAT_MESSAGES"

An event that is triggered when a chat message is received from an operator assistant, system or visitor or sent by the operator.

The event listener will be called with an array of {VisitorMessage}, {OperatorMessage}, {OperatorAssistantMessage} and {SystemMessage} instances that have been exchanged with the visitor. The amount of messages shown to the visitor will be the same amount as what the operator sees. The newest message appears as the first message in the array.

Kind: event emitted by Glia Example (Display a list of chat messages)

function getChatMessages(messages) {
var messagesDiv = document.getElementById('chat-messages');
if (messagesDiv) {
document.body.removeChild(messagesDiv);
}
messagesDiv = document.createElement('div');
messagesDiv.setAttribute('id', 'chat-messages');
document.body.appendChild(messagesDiv);
if (messages) {
messages.forEach(element => {
var div = document.createElement('div');
div.innerHTML = element.content;
messagesDiv.appendChild(div);
});
}
}
glia.addBufferedEventListener(glia.EVENTS.CHAT_MESSAGES, getChatMessages);

Queue

Encapsulates the queue information.

Kind: global class

queue.id

Kind: instance property of Queue Properties

Name

Type

Description

id

string

Queue's identifier.

queue.name

Kind: instance property of Queue Properties

Name

Type

Description

name

string

Queue's human-readable name.

Visitor

Encapsulates the visitor information.

Kind: global class

visitor.id

Kind: instance property of Visitor Properties

Name

Type

Description

id

string

Visitor's ID.

visitor.siteId

Kind: instance property of Visitor Properties

Name

Type

Description

siteId

string

ID of the site that the visitor is currently engaged on or during observation, the site that visitor is active on. Visitor can simultaneously be on multiple sites. Site visitor's data is only accessible within this site.

visitor.name

Kind: instance property of Visitor Properties

Name

Type

Description

name

string

Visitor's name.

visitor.email

Kind: instance property of Visitor Properties

Name

Type

Description

email

string

Visitor's email.

visitor.phone

Kind: instance property of Visitor Properties

Name

Type

Description

phone

string

Visitor's phone number.

visitor.customAttributes

Kind: instance property of Visitor Properties

Name

Type

Description

customAttributes

object

Visitor's custom attributes.

visitor.authenticatedAttributes

Kind: instance property of Visitor Properties

Name

Type

Description

authenticatedAttributes

object

Visitor's authenticated attributes.

authenticatedAttributes.visitorName

string

Visitor's authenticated name.

authenticatedAttributes.visitorPreferredName

string

Visitor's authenticated preferred name.

authenticatedAttributes.visitorEmail

string

Visitor's authenticated email.

authenticatedAttributes.authenticationProviderId

string

The ID of the authentication provider used to authenticate visitor.

authenticatedAttributes.issuer

string

Issuer as returned by the authentication provider during visitor authentication.

authenticatedAttributes.subject

string

Subject as returned by the authentication provider during visitor authentication.

authenticatedAttributes.accessToken

string

Token to retrieve additional visitor context or perform operations on behalf of a visitor.

authenticatedAttributes.authenticatedAt

Date

Timestamp of the visitor's authentication.