-
public class GliaThis class is a starting point for integration with Glia SDK and for most interactions with Glia platform.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceGlia.OmnicoreEventpublic final classGlia.EventsGlia global event types.
-
Field Summary
Fields Modifier and Type Field Description public static Omnibrowseomnibrowse
-
Method Summary
Modifier and Type Method Description static voidsetOmnibrowse(Omnibrowse omnibrowse)static synchronized voidinit(@NotNull() GliaConfig config)Initializes Glia SDK using GliaConfig. static synchronized voidonAppCreate(Application application)Configures Glia SDK application lifecycle related settings. static voidgetVisitorInfo(RequestCallback<VisitorInfo> visitorCallback)Fetches the visitor's informationIf visitor is authenticated, the response will include the attributes and tokens fetched from the authentication provider. static voidupdateVisitorInfo(VisitorInfoUpdateRequest visitorInfoUpdateRequest, Consumer<GliaException> visitorCallback)Updates the visitor's informationUpdates the visitor's information stored on the server. static <T> voidon(@NotNull() Glia.OmnicoreEvent<T> event, Consumer<T> listener)Registers event listeners for Omnicore. static <T> voidoff(@NotNull() Glia.OmnicoreEvent<T> event, Consumer<T> listener)Removes event listeners from OmniCore. static <T> voidoff(@NotNull() Glia.OmnicoreEvent<T> event)Removes all event listeners from OmniCore. static voidfetchFile(AttachmentFile attachmentFile, RequestCallback<InputStream> callback)Retrieves file content stream. static voidgetChatHistory(RequestCallback<Array<ChatMessage>> callback)Returns Visitor's chat historyIncludes all Operator and Visitor chat messages from previous and/or ongoing Engagements that were sentprior to calling this method. static voidgetQueues(RequestCallback<Array<Queue>> requestCallback)Gets a list of all Queues. static voidgetOperators(RequestCallback<Array<Operator>> requestCallback)Deprecated since SDK version 0.22. static voidrequestEngagement(@NotNull() String operatorId, @NotNull() VisitorContext visitorContext, @NotNull() RequestCallback<OutgoingEngagementRequest> requestCallback)Sends Engagement request to specific Operator. static voidrequestEngagement(@NotNull() String operatorId, @NotNull() VisitorContext visitorContext, @NotNull() Engagement.MediaType mediaType, int mediaPermissionRequestCode, @NotNull() RequestCallback<OutgoingEngagementRequest> requestCallback)static voidrequestEngagement(@NotNull() String operatorId, @NotNull() VisitorContext visitorContext, @NotNull() Engagement.MediaType mediaType, @Nullable() EngagementOptions engagementOptions, int mediaPermissionRequestCode, @NotNull() RequestCallback<OutgoingEngagementRequest> requestCallback)Sends Engagement request to specific Operator with possibility to choose engagement media type (text/audio/video). static voidcancelEngagementRequest(@NotNull() String engagementRequestId, Consumer<GliaException> callback)Cancels Visitor's Engagement Request. static voidqueueForEngagement(@NotNull() String queueId, @NotNull() VisitorContext visitorContext, Consumer<GliaException> callback)Enqueues the Visitor for TEXT type Engagement. static voidqueueForEngagement(@NotNull() String queueId, Engagement.MediaType mediaType, @NotNull() VisitorContext visitorContext, Consumer<GliaException> callback)static voidqueueForEngagement(@NotNull() String queueId, @NotNull() Engagement.MediaType mediaType, @NotNull() VisitorContext visitorContext, int mediaPermissionRequestCode, @NotNull() Consumer<GliaException> callback)static voidqueueForEngagement(@NotNull() String queueId, @NotNull() Engagement.MediaType mediaType, @NotNull() VisitorContext visitorContext, @Nullable() EngagementOptions engagementOptions, int mediaPermissionRequestCode, @NotNull() Consumer<GliaException> callback)Enqueues the Visitor for text Engagement. static voidcancelQueueTicket(@NotNull() String queueTicketId, Consumer<GliaException> callback)Cancels Visitor's spot in the queue. static voidsubscribeToQueueStateUpdates(@NotNull() Array<String> queueIds, Consumer<GliaException> onError, Consumer<Queue> callback)Subscribes to state updates of one or multiple Queues. static voidsubscribeToQueueStateUpdates(@NotNull() String queueId, Consumer<GliaException> onError, Consumer<Queue> callback)Subscribes to state updates of one or multiple Queues. static voidunsubscribeFromQueueUpdates(Consumer<GliaException> onError, Consumer<Queue> callback)Unsubscribes from Queue state updates currently subscribed with subscribeToQueueStateUpdates or subscribeToQueueStateUpdates static voidsubmitSurveyAnswers(@NonNull() List<Survey.Answer> answers, @NonNull() String surveyId, @NonNull() String engagementId, @NonNull() Consumer<GliaException> callback)Send the survey answers. static voidonRequestPermissionsResult(int requestCode, Array<String> permissions, @NonNull() Array<int> grantResults)Accepts permissions request results. static booleanisInitialized()Checks result of Glia initialization static voidclearVisitorSession()Clears current Glia SDK session and also resetting the Visitor ID and his local data. static voidgetSiteInfo(@NonNull() RequestCallback<SiteInfo> callback)Fetches the site configurations -
-
Method Detail
-
setOmnibrowse
static void setOmnibrowse(Omnibrowse omnibrowse)
-
init
static synchronized void init(@NotNull() GliaConfig config)
Initializes Glia SDK using GliaConfig.
Use it one time when the app starts to initialize Glia SDKwith necessary configuration.
Example:
{@code * Glia.init(new GliaConfig.Builder() * .setAppToken("APP_TOKEN") * .setSiteId("SITE_ID") * .setRegion(Region.US) * .build() * ); * }- Parameters:
config- Glia configuration
-
onAppCreate
static synchronized void onAppCreate(Application application)
Configures Glia SDK application lifecycle related settings.
Should be called from onCreate
- Parameters:
application- may have one of following causes:INVALID_INPUT - in case passed argumentis this method was called not from onCreate,or when called more then one time.
-
getVisitorInfo
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.
- Parameters:
visitorCallback- called with VisitorInfo when request succeeds or with GliaException if error happened.
-
updateVisitorInfo
static void updateVisitorInfo(VisitorInfoUpdateRequest visitorInfoUpdateRequest, Consumer<GliaException> visitorCallback)
Updates the visitor's information
Updates the visitor's information stored on the server. This information will also be displayed to the operator.
- Parameters:
visitorCallback- Called with{@code null}if request succeeds or with GliaException if error happened.
-
on
static <T> void on(@NotNull() Glia.OmnicoreEvent<T> event, Consumer<T> listener)
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 typethe duplicate instances are discarded. They do not cause the listenerto be called twice and do not need to be removed with the off or off method.
Calling before SDK is initialized results in runtime exception GliaException with INVALID_INPUT cause.
- Parameters:
event- One of Eventslistener- Event listener to register
-
off
static <T> void off(@NotNull() Glia.OmnicoreEvent<T> event, Consumer<T> listener)
Removes 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
{@code off}with arguments which do not identify any currently registeredlistener has no effect.Calling before SDK is initialized results in runtime exception GliaException with INVALID_INPUT cause.
- Parameters:
event- One of Eventslistener- Event listener to remove
-
off
static <T> void off(@NotNull() Glia.OmnicoreEvent<T> event)
Removes all event listeners from OmniCore.
Behaves the same way as off but removes all listeners of specified type
- Parameters:
event- One of Events
-
fetchFile
static void fetchFile(AttachmentFile attachmentFile, RequestCallback<InputStream> callback)
Retrieves file content stream.
To close network connection ensure to call close even if you have notperformed 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(); } }); });- Parameters:
callback- called with InputStream that can be used to download file contentor with GliaException.
-
getChatHistory
static void getChatHistory(RequestCallback<Array<ChatMessage>> callback)
Returns Visitor's chat history
Includes all Operator and Visitor chat messages from previous and/or ongoing Engagements that were sentprior to calling this method.
- Parameters:
callback- called with ChatMessage when request succeeds or with GliaException if error happened.
-
getQueues
static void getQueues(RequestCallback<Array<Queue>> requestCallback)
Gets a list of all Queues.
This information can be used to enqueue by Queue ID by queueForEngagement.
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 youcan check state of Queues by fetching their information and assigning your Engagementdynamically 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(); } }); });- Parameters:
requestCallback- called with Queue array set when request succeedsor with GliaException.
-
getOperators
@Deprecated() static void getOperators(RequestCallback<Array<Operator>> requestCallback)
Deprecated since SDK version 0.22.0
-
requestEngagement
static void requestEngagement(@NotNull() String operatorId, @NotNull() VisitorContext visitorContext, @NotNull() RequestCallback<OutgoingEngagementRequest> requestCallback)
Sends Engagement request to specific Operator. Once request is successfully sent and Operatorapproved it an Engagement is started and ENGAGEMENT trigger is fired.
Behaves same way as calling the < > with the TEXT media type.
-
requestEngagement
@Deprecated() static void requestEngagement(@NotNull() String operatorId, @NotNull() VisitorContext visitorContext, @NotNull() Engagement.MediaType mediaType, int mediaPermissionRequestCode, @NotNull() RequestCallback<OutgoingEngagementRequest> requestCallback)
-
requestEngagement
static void requestEngagement(@NotNull() String operatorId, @NotNull() VisitorContext visitorContext, @NotNull() Engagement.MediaType mediaType, @Nullable() EngagementOptions engagementOptions, int mediaPermissionRequestCode, @NotNull() RequestCallback<OutgoingEngagementRequest> 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 with the same int passedto the first argument as passed to this function (@param mediaPermissionRequestCode)within a calling screen.
Once request is successfully sent and Operator andapproved 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. });- Parameters:
operatorId- The Operator with whom you want to start engagement with.mediaType- The engagement media type.engagementOptions- The options that the engagement should have.mediaPermissionRequestCode- The code to handle system permission request.requestCallback- called with OutgoingEngagementRequest set when request succeedsor with GliaException.
-
cancelEngagementRequest
static void cancelEngagementRequest(@NotNull() String engagementRequestId, Consumer<GliaException> callback)
Cancels Visitor's Engagement Request.
Behaves same way as cancel only you have to manually specify Engagement Request ID.
- Parameters:
engagementRequestId- String that represents Engagement Request ID.callback- Called with{@code null}if request succeeds or with GliaException if failed.
-
queueForEngagement
static void queueForEngagement(@NotNull() String queueId, @NotNull() VisitorContext visitorContext, Consumer<GliaException> callback)
Enqueues the Visitor for TEXT type Engagement.
Behaves same way as calling the queueForEngagement with the TEXT media type.
-
queueForEngagement
@Deprecated() static void queueForEngagement(@NotNull() String queueId, Engagement.MediaType mediaType, @NotNull() VisitorContext visitorContext, Consumer<GliaException> callback)
-
queueForEngagement
@Deprecated() static void queueForEngagement(@NotNull() String queueId, @NotNull() Engagement.MediaType mediaType, @NotNull() VisitorContext visitorContext, int mediaPermissionRequestCode, @NotNull() Consumer<GliaException> callback)
-
queueForEngagement
static void queueForEngagement(@NotNull() String queueId, @NotNull() Engagement.MediaType mediaType, @NotNull() VisitorContext visitorContext, @Nullable() EngagementOptions engagementOptions, int mediaPermissionRequestCode, @NotNull() Consumer<GliaException> callback)
Enqueues the Visitor for text Engagement.While audio or video media engagement intended, client must call onRequestPermissionsResult 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 theavailable Operators. To be able to still provide best possible user experience under thesecircumstances, Glia provides a way for Visitors to queue for Engagements.
When the Visitor was successfully put into to Queue QUEUE_TICKET event istriggered with an instance of QueueTicket. QueueTicket can be used to cancel queueingusing cancel or cancelQueueTicket.
Visitors who have entered the Queue is, in turn, Engaged with an appropriate Operatoras soon as one becomes available and accepts the Engagement Request. Once that happens ENGAGEMENT event is triggered. See on 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"); });- Parameters:
queueId- ID of the Queue to which Visitor will be enqueued.mediaType- The engagement media type.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 contextabout the Visitor or any other content that might be helpful.engagementOptions- The options that the engagement should have.mediaPermissionRequestCode- The code to handle system permission request.callback- Called with{@code null}if request succeeds or with GliaException if failed.
-
cancelQueueTicket
static void cancelQueueTicket(@NotNull() String queueTicketId, Consumer<GliaException> callback)
Cancels Visitor's spot in the queue.
Behaves same way as cancel only you have to manually specify Queue ticket ID.
- Parameters:
queueTicketId- String that represents Queued Ticket ID.callback- Called with{@code null}if request succeeds or with GliaException if failed.
-
subscribeToQueueStateUpdates
static void subscribeToQueueStateUpdates(@NotNull() Array<String> queueIds, Consumer<GliaException> onError, Consumer<Queue> callback)
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.
- Parameters:
queueIds- array of Queue IDs for which you want to receive state updatesonError- is called with instance of GliaException when error happened.callback- is called when a Queue state update occurs with the updated Queue instance
-
subscribeToQueueStateUpdates
static void subscribeToQueueStateUpdates(@NotNull() String queueId, Consumer<GliaException> onError, Consumer<Queue> callback)
Subscribes to state updates of one or multiple Queues.
Behaves same way as subscribeToQueueStateUpdates
- Parameters:
queueId-{@code String}that represent Queue ID for which you want to receive updates.onError- is called with instance of GliaException when error happened.callback- is called when a Queue state update occurs with the updated Queue instance
-
unsubscribeFromQueueUpdates
static void unsubscribeFromQueueUpdates(Consumer<GliaException> onError, Consumer<Queue> callback)
Unsubscribes from Queue state updates currently subscribed with subscribeToQueueStateUpdates or subscribeToQueueStateUpdates
- Parameters:
onError- is called with instance of GliaException when error happened.callback- callback to release
-
submitSurveyAnswers
static void submitSurveyAnswers(@NonNull() List<Survey.Answer> answers, @NonNull() String surveyId, @NonNull() String engagementId, @NonNull() Consumer<GliaException> callback)
Send the survey answers.
- Parameters:
answers- Collection of Survey.Answer given by the visitor.surveyId- ID of the survey which the visitor answered.engagementId- ID of the engagement after which the visitor filled the survey.callback- Called with{@code null}if request succeeds or with GliaException if error happened.
-
onRequestPermissionsResult
static void onRequestPermissionsResult(int requestCode, Array<String> permissions, @NonNull() Array<int> grantResults)
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.
-
isInitialized
static boolean isInitialized()
Checks result of Glia initialization
-
clearVisitorSession
static void clearVisitorSession()
Clears current Glia SDK session and also resetting the Visitor ID and his local data.
-
getSiteInfo
static void getSiteInfo(@NonNull() RequestCallback<SiteInfo> callback)
Fetches the site configurations
- Parameters:
callback- called with SiteInfo when request succeeds or with GliaException if error happened.
-
-
-
-