| java.lang.Object | |
| ↳ | com.glia.androidsdk.Glia |
This class is a starting point for integration with Glia SDK and for most interactions with Glia platform.
| Nested Classes | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| class | Glia.Events | Glia global event types. | |||||||||
| interface | Glia.OmnicoreEvent<T> | ||||||||||
| Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| public static Omnibrowse | omnibrowse | Omnibrowse instance, can be used to perform OmniBrowse specific actions. |
|||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| static void |
cancelEngagementRequest(String engagementRequestId, Consumer<GliaException> callback)
Cancels Visitor's Engagement Request.
| ||||||||||
| static void |
cancelQueueTicket(String queueTicketId, Consumer<GliaException> callback)
Cancels Visitor's spot in the queue.
| ||||||||||
| static void |
fetchFile(AttachmentFile attachmentFile, RequestCallback<InputStream> callback)
Retrieves file content stream.
| ||||||||||
| static void |
getChatHistory(RequestCallback<ChatMessage[]> callback)
Returns Visitor's chat history
Includes all Operator and Visitor chat messages from previous and/or ongoing Engagements that were sent prior to calling this method. | ||||||||||
| static Optional<Engagement> |
getCurrentEngagement()
Returns current Engagement if exists.
| ||||||||||
| static void |
getOperators(RequestCallback<Operator[]> requestCallback)
Deprecated since SDK version 0.22.0
| ||||||||||
| static PushNotifications | getPushNotificationHandler() | ||||||||||
| static void |
getQueues(RequestCallback<Queue[]> requestCallback)
Gets a list of all Queues.
| ||||||||||
| static void |
getVisitorInfo(RequestCallback<VisitorInfo> visitorCallback)
Fetches the visitor's information
If visitor is authenticated, the response will include the attributes and tokens fetched from the authentication provider. | ||||||||||
| synchronized static void |
init(GliaConfig config)
Initializes Glia SDK using
GliaConfig. | ||||||||||
| static boolean |
isInitialized()
Checks result of Glia initialization
| ||||||||||
| static <T> void |
off(OmnicoreEvent<T> event, Consumer<T> listener)
Removes event listeners from OmniCore.
| ||||||||||
| static <T> void |
off(OmnicoreEvent<T> event)
Removes all event listeners from OmniCore.
| ||||||||||
| static <T> void |
on(OmnicoreEvent<T> event, Consumer<T> listener)
Registers event listeners for Omnicore.
| ||||||||||
| synchronized static void |
onAppCreate(Application application)
Configures Glia SDK application lifecycle related settings.
| ||||||||||
| static void |
onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
Accepts permissions request results.
| ||||||||||
| static void |
queueForEngagement(String queueId, Engagement.MediaType mediaType, VisitorContext visitorContext, Consumer<GliaException> callback)
This method is deprecated.
use
queueForEngagement(String, Engagement.MediaType, VisitorContext, int, Consumer)
to have permission-aware implementation
Deprecated since SDK version 0.20.0
| ||||||||||
| static void |
queueForEngagement(String queueId, Engagement.MediaType mediaType, VisitorContext visitorContext, int mediaPermissionRequestCode, Consumer<GliaException> callback)
This method is deprecated.
use
queueForEngagement(String, Engagement.MediaType, VisitorContext, EngagementOptions, int, Consumer)
Deprecated since SDK version 0.21.0
| ||||||||||
| static void |
queueForEngagement(String queueId, Engagement.MediaType mediaType, VisitorContext visitorContext, EngagementOptions engagementOptions, int mediaPermissionRequestCode, Consumer<GliaException> callback)
Enqueues the Visitor for text Engagement.
| ||||||||||
| static void |
queueForEngagement(String queueId, VisitorContext visitorContext, Consumer<GliaException> callback)
Enqueues the Visitor for
TEXT type Engagement. | ||||||||||
| static void |
requestEngagement(String operatorId, VisitorContext visitorContext, Engagement.MediaType mediaType, int mediaPermissionRequestCode, RequestCallback<OutgoingEngagementRequest> requestCallback)
This method is deprecated.
use #requestEngagement(String, VisitorContext, Engagement.MediaType, EngagementOptions, int, RequestCallback
| ||||||||||
| static void |
requestEngagement(String operatorId, VisitorContext visitorContext, Engagement.MediaType mediaType, EngagementOptions engagementOptions, int mediaPermissionRequestCode, RequestCallback<OutgoingEngagementRequest> requestCallback)
Sends Engagement request to specific Operator with possibility to choose
engagement media type (text/audio/video). | ||||||||||
| static void |
requestEngagement(String operatorId, VisitorContext visitorContext, RequestCallback<OutgoingEngagementRequest> requestCallback)
Sends Engagement request to specific Operator.
| ||||||||||
| static void |
subscribeToQueueStateUpdates(String[] queueIds, Consumer<GliaException> onError, Consumer<Queue> callback)
Subscribes to state updates of one or multiple Queues.
| ||||||||||
| static void |
subscribeToQueueStateUpdates(String queueId, Consumer<GliaException> onError, Consumer<Queue> callback)
Subscribes to state updates of one or multiple Queues.
| ||||||||||
| static void |
unsubscribeFromQueueUpdates(Consumer<GliaException> onError, Consumer<Queue> callback)
Unsubscribes from Queue state updates currently subscribed with
subscribeToQueueStateUpdates(String, Consumer, Consumer)
or subscribeToQueueStateUpdates(String[], Consumer, Consumer) | ||||||||||
| static void |
updateVisitorInfo(VisitorInfoUpdateRequest visitorInfoUpdateRequest, Consumer<GliaException> visitorCallback)
Updates the visitor's information
Updates the visitor's information stored on the server. | ||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
Omnibrowse instance, can be used to perform OmniBrowse specific actions.
Cancels Visitor's Engagement Request.
Behaves same way as cancel(Consumer) only you have to manually specify Engagement Request ID.
| engagementRequestId | String that represents Engagement Request ID. |
|---|---|
| callback | Called with null if request succeeds or with GliaException if failed.
Exception may have one of following causes:
NETWORK_TIMEOUT - when request times out due to connection issues
INTERNAL_ERROR - when internal error occurs
INVALID_INPUT - if invalid Engagement Request ID is provided |
Cancels Visitor's spot in the queue.
Behaves same way as cancel(Consumer) only you have to manually specify Queue ticket ID.
| queueTicketId | String that represents Queued Ticket ID. |
|---|---|
| callback | Called with null if request succeeds or with GliaException if failed.
Exception may have one of following causes:
NETWORK_TIMEOUT - when request times out due to connection issues
INTERNAL_ERROR - when internal error occurs
INVALID_INPUT - if invalid Ticket Queue ID is provided |
Retrieves file content stream.
To close network connection ensure to call close() even if you have not
performed any actions with the stream.
fileDownloadIcon.setOnClickListener(view -> {
Glia.fetchFile(attachmentFile, (fileInputStream, exception) -> {
if (exception != null) {
// Something went wrong when trying to retrieve file content
// Show some error message
return;
}
try (FileOutputStream newFileStream = new FileOutputStream(YOUR_FILE_PATH)) {
int length;
byte[] buffer = new byte[1024];
while ((length = fileInputStream.read(buffer)) != -1) {
newFileStream.write(buffer, 0, length);
}
newFileStream.flush();
} finally {
fileInputStream.close();
}
});
});
| callback | called with InputStream that can be used to download file content
or with GliaException. Exception may have one of following causes:
NETWORK_TIMEOUT - when request times out due to connection issues
INTERNAL_ERROR - when internal error occurs
INVALID_INPUT - when invalid AttachmentFile
FILE_UNAVAILABLE - when file is unavailable (most common scenario - expiration option in Operator's Admin Panel (Advanced):
Check admin setting “Store File Attachments”. If it is set to “Off”, the file attachments will be deleted 24 hours after the engagement ends) |
|---|
Returns Visitor's chat history
Includes all Operator and Visitor chat messages from previous and/or ongoing Engagements that were sent prior to calling this method.
| callback | called with ChatMessage[] when request succeeds or with GliaException if error happened.
Exception may have one of following causes:
INTERNAL_ERROR - when internal error occurs
NETWORK_TIMEOUT - when request times out due to connection issues |
|---|
Returns current Engagement if exists.
This method is useful when you need to access current Engagement instance in an activity
that is different from the activity that received ENGAGEMENT event.
Engagement if there is an ongoing Engagement
when the method is called. Otherwise returns an empty Optional instance.
Deprecated since SDK version 0.22.0
Gets a list of all Queues.
This information can be used to enqueue by Queue ID by queueForEngagement(String, VisitorContext, Consumer).
Usage example:
You might have multiple Operator Queues for different purposes. Let's say one is named 'regular' and is for normal Visitors while another is 'premium' for VIP Visitors. In this case you can check state of Queues by fetching their information and assigning your Engagement dynamically to more fitting Queue.
Glia.getQueues((queues, exception) -> {
runOnUiThread(() -> {
if (queues != null) {
makeEnqueue(queues);
}
if (exception != null && exception.cause.equals(GliaException.Cause.NETWORK_TIMEOUT)) {
showNetworkError();
}
});
});
| requestCallback | called with Queue array set when request succeeds
or with GliaException. Exception may have one of following causes:
NETWORK_TIMEOUT - when request times out due to connection issues
INTERNAL_ERROR - when internal error occurs
INVALID_INPUT - if SDK has not initialized |
|---|
Fetches the visitor's information
If visitor is authenticated, the response will include the attributes and tokens fetched from the authentication provider.
| visitorCallback | called with VisitorInfo when request succeeds or with GliaException if error happened.
Exception may have one of following causes:
INTERNAL_ERROR - when internal error occurs
NETWORK_TIMEOUT - when request times out due to connection issues
|
|---|
Initializes Glia SDK using GliaConfig.
Use it one time when the app starts to initialize Glia SDK with necessary configuration.
Example:
Glia.init(new GliaConfig.Builder()
.setAppToken("APP_TOKEN")
.setSiteId("SITE_ID")
.setRegion(Region.US)
.build()
);
| config | Glia configuration |
|---|
| GliaException | may have one of following causes:
INVALID_INPUT - in case provided configuration is
invalid or information is missing, onAppCreate(Application) was not called
or when called more then one time. |
|---|
Checks result of Glia initialization
true if Glia SDK have been successfully initializedRemoves event listeners from OmniCore.
If an event listener is removed while the OmniCore is processing an event, it is not triggered with the current event.
Calling off with arguments which do not identify any currently registered
listener has no effect.
Calling before SDK is initialized results in runtime exception GliaException with
INVALID_INPUT cause.
| event | One of Glia.Events |
|---|---|
| listener | Event listener to remove |
Removes all event listeners from OmniCore.
Behaves the same way as off(OmnicoreEvent, Consumer) but removes all listeners of specified type
| event | One of Glia.Events
|
|---|
Registers event listeners for Omnicore.
If a listener is added while the Omnicore is processing an event, it is not triggered with the current event.
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 off(OmnicoreEvent) or
off(OmnicoreEvent, Consumer) method.
Calling before SDK is initialized results in runtime exception GliaException with
INVALID_INPUT cause.
| event | One of Glia.Events |
|---|---|
| listener | Event listener to register |
Configures Glia SDK application lifecycle related settings.
Should be called from onCreate()
| application | may have one of following causes:
INVALID_INPUT - in case passed argument
is null this method was called not from onCreate(),
or when called more then one time. |
|---|
| GliaException |
|---|
Accepts permissions request results.
Some functionalities, for example Video or Audio calls, require to request runtime permissions via Activity#requestPermissions(String[], int). The results of such request is passed to your activity's Activity#onRequestPermissionsResult(int, String[], int[])
Your activity in turn must call this method to pass the results of the request to Glia SDK.
This method is no-op for other non-Glia triggered results.
This method is deprecated.
use queueForEngagement(String, Engagement.MediaType, VisitorContext, int, Consumer)
to have permission-aware implementation
Deprecated since SDK version 0.20.0
This method is deprecated.
use queueForEngagement(String, Engagement.MediaType, VisitorContext, EngagementOptions, int, Consumer)
Deprecated since SDK version 0.21.0
Enqueues the Visitor for text Engagement.
While audio or video media engagement intended, client must call
onRequestPermissionsResult(int, String[], int[]) within a calling screen.
In case of audio\video media type specified (@param mediaType), first argument there must be equal to
(@param mediaPermissionRequestCode)
On high-traffic Sites, Visitors looking for Engagements can greatly outnumber the available Operators. To be able to still provide best possible user experience under these circumstances, Glia provides a way for Visitors to queue for Engagements.
When the Visitor was successfully put into to Queue QUEUE_TICKET event is
triggered with an instance of QueueTicket. QueueTicket can be used to cancel queueing
using cancel(Consumer) or cancelQueueTicket(String, Consumer).
Visitors who have entered the Queue is, in turn, Engaged with an appropriate Operator
as soon as one becomes available and accepts the Engagement Request. Once that happens
ENGAGEMENT event is triggered. See on(OmnicoreEvent, Consumer)
for more info regarding OmniCore events.
Usage example:
Glia.queueForEngagement(yourQueueId, mediaType, visitorContext, MEDIA_PERMISSION_CODE, response -> {
if (response != null) {
Log.e("Glia", "Failed to queue for Engagement: " + response.toString());
return;
}
Log.i("Glia", "Visitor successfully enqueued, waiting for Operator to accept Engagement");
});
| queueId | ID of the Queue to which Visitor will be enqueued.
NB: The Queue must have text media available |
|---|---|
| mediaType | The engagement media type. Might not be `null` or `UNKNOWN`. `PHONE` media type is not currently supported. |
| visitorContext | Content that is displayed to the Operator during the Engagement. You may use it to display information that would give the Operator an additional context about the Visitor or any other content that might be helpful. |
| engagementOptions | The options that the engagement should have. Set it as `null` for the default options. |
| mediaPermissionRequestCode | The code to handle system permission request. Must
be equal to one passed to onRequestPermissionsResult(int, String[], int[])
as first argument. Mandatory only in case of
Audio\Video media type specified, otherwise might
be any value.
See more about runtime permissions request codes |
| callback | Called with null if request succeeds or with GliaException if failed.
Exception may have one of following causes:
NETWORK_TIMEOUT - when request times out due to connection issues
INTERNAL_ERROR - when internal error occurs
INVALID_INPUT - when SDK is not initialized, invalid Queue ID, invalid media type,
or Queue is unavailable for required media
ALREADY_QUEUED - when Visitor is already queued
FORBIDDEN - when Visitor is banned by an Operator
PERMISSIONS_DENIED - when Visitor declined the required permissions |
Enqueues the Visitor for TEXT type Engagement.
Behaves same way as calling the queueForEngagement(String, Engagement.MediaType, VisitorContext, Consumer)
with the TEXT media type.
This method is deprecated.
use #requestEngagement(String, VisitorContext, Engagement.MediaType, EngagementOptions, int, RequestCallback
Sends Engagement request to specific Operator with possibility to choose
engagement media type (text/audio/video).
While audio or video media engagement intended, client must call
onRequestPermissionsResult(int, String[], int[]) with the same int passed
to the first argument as passed to this function (@param mediaPermissionRequestCode)
within a calling screen.
Once request is successfully sent and Operator and
approved then an Engagement is started and ENGAGEMENT trigger is fired.
Code example:
VisitorContext visitorContext = new VisitorContext(VisitorContext.Type.PAGE, "https://example.com/");
Glia.requestEngagement(operatorId, visitorContext, Engagement.MediaType.VIDEO, MEDIA_PERMISSION_CODE, (engagementRequest, error) -> {
if (error != null) {
// Failed to send Engagement Request
return;
}
// Engagement request was sent successfully, waiting for Operator to approve.
});
| operatorId | The Operator with whom you want to start engagement with. |
|---|---|
| mediaType | The engagement media type. Might not be `null` or `UNKNOWN`. `PHONE` media type is not currently supported. |
| engagementOptions | The options that the engagement should have. Set it as `null` for the default options. |
| mediaPermissionRequestCode | The code to handle system permission request. Must
be equal to one passed to onRequestPermissionsResult(int, String[], int[])
as first argument. Mandatory only in case of
Audio\Video media type specified.
See more about runtime permissions request codes |
| requestCallback | called with OutgoingEngagementRequest set when request succeeds
or with GliaException. Exception may have one of following causes:
NETWORK_TIMEOUT - when request times out due to connection issues
INTERNAL_ERROR - when internal error occurs
INVALID_INPUT - when SDK is not initialized, invalid Operator ID,
Queue is unavailable for required media or VisitorContext is null
ALREADY_QUEUED - when Visitor is already queued
FORBIDDEN - when Visitor is banned by an Operator
PERMISSIONS_DENIED - when Visitor declined the required permissions |
Sends Engagement request to specific Operator. Once request is successfully sent and Operator
approved it an Engagement is started and ENGAGEMENT trigger is fired.
Behaves same way as calling the
#requestEngagement(String, VisitorContext, Engagement.MediaType, EngagementOptions, int, RequestCallbackTEXT media type.
Subscribes to state updates of one or multiple Queues.
Allows to subscribe to Queue state updates of a specific Queue. This can be useful when there is a need to have multiple integration points, for example buttons, corresponding to different Queues.
| queueIds | array of Queue IDs for which you want to receive state updates |
|---|---|
| onError | is called with instance of GliaException when error happened.
Exception may have one of following causes:
INTERNAL_ERROR - when internal error occurs
INVALID_INPUT - if invalid Queue ID is provided |
| callback | is called when a Queue state update occurs with the updated Queue instance |
Subscribes to state updates of one or multiple Queues.
Behaves same way as subscribeToQueueStateUpdates(String[], Consumer, Consumer)
| queueId | String that represent Queue ID for which you want to receive updates. |
|---|---|
| onError | is called with instance of GliaException when error happened.
Exception may have one of following causes:
INTERNAL_ERROR - when internal error occurs
INVALID_INPUT - if invalid Queue ID is provided |
| callback | is called when a Queue state update occurs with the updated Queue instance |
Unsubscribes from Queue state updates currently subscribed with subscribeToQueueStateUpdates(String, Consumer, Consumer)
or subscribeToQueueStateUpdates(String[], Consumer, Consumer)
| onError | is called with instance of GliaException when error happened.
Exception may have one of following causes:
INTERNAL_ERROR - when internal error occurs
|
|---|---|
| callback | callback to release |
Updates the visitor's information
Updates the visitor's information stored on the server. This information will also be displayed to the operator.
| visitorCallback | Called with null if request succeeds or with GliaException if error happened.
Exception may have one of following causes: INVALID_INPUT - when request
contains:
• getName(),
getEmail() fields' length more
than 250 symbols long,
• getPhone() more than 20 symbols
long,
• getNote() more than 5000
symbols long
INTERNAL_ERROR - when internal error occurs
NETWORK_TIMEOUT - when request times out due to connection issues
Example:
|
|---|