Package 

Class Glia


  • 
    public class Glia
    
                        

    This class is a starting point for integration with Glia SDK and for most interactions with Glia platform.

    • Method Detail

      • 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 Events
        listener - 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 Events
        listener - 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.
      • 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() 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 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
      • 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.