Class WebMessagingClient


  • public class WebMessagingClient
    extends Object
    A client used to connect to a Web Messaging session
    • Constructor Detail

      • WebMessagingClient

        public WebMessagingClient​(String address)
        Creates a new Web Messaging client
        Parameters:
        address - The WebSocket server's address, including the wss:// protocol
      • WebMessagingClient

        public WebMessagingClient​(GenesysCloudRegionWebSocketHosts region)
        Creates a new Web Messaging client
        Parameters:
        region - The WebSocket server's Genesys Cloud region
    • Method Detail

      • joinConversation

        public void joinConversation​(String deploymentId,
                                     String initialMessage,
                                     String origin)
        Full service operation to connect the WebSocket and configure the session
        Parameters:
        deploymentId - The ID of the Web Messaging deployment
        initialMessage - The initial message to send once the session is ready
      • joinConversation

        public void joinConversation​(String deploymentId,
                                     String token,
                                     String initialMessage,
                                     String origin)
        Full service operation to connect the WebSocket and configure the session
        Parameters:
        deploymentId - The ID of the Web Messaging deployment
        token - The session token
        initialMessage - The initial message to send once the session is ready
      • connect

        public void connect​(String deploymentId,
                            String origin)
      • connect

        public void connect​(String deploymentId,
                            String origin,
                            Optional<Integer> connectionTimeout)
        Establishes a connection to Genesys Cloud via a WebSocket
        Parameters:
        deploymentId - deploymentId to connect to
        origin - origin header to add
        connectionTimeout - connection timeout, in second, to use
      • isInputClosed

        public boolean isInputClosed()
        Check whether the underlying websocket's input is closed
        Returns:
        true if closed, false otherwise
      • isOutputClosed

        public boolean isOutputClosed()
        Check whether the underlying websocket's output is closed
        Returns:
        true if closed, false otherwise
      • configureSession

        public void configureSession​(String deploymentId,
                                     String origin)
        Configures a new session with a randomly generated session token
        Parameters:
        deploymentId - The ID of the Web Messaging deployment
        origin - Represents the origin of the request. You can restrict access in Messenger Deployments
      • configureSession

        public void configureSession​(String deploymentId,
                                     String token,
                                     String origin)
        Configures a session using the provided session token. This can be used to reconnect to active sessions.
        Parameters:
        deploymentId - The ID of the Web Messaging deployment
        token - The session token
        origin - Represents the origin of the request. You can restrict access in Messenger Deployments
      • configureAuthenticatedSession

        public void configureAuthenticatedSession​(String deploymentId,
                                                  String origin,
                                                  OAuthParams data)
        Configures a new authenticated session with a randomly generated session token
        Parameters:
        deploymentId - The ID of the Web Messaging deployment
        origin - Represents the origin of the request. You can restrict access in Messenger Deployments
        data - The session OAuthParams for configuring Authenticated Session
      • configureAuthenticatedSession

        public void configureAuthenticatedSession​(String deploymentId,
                                                  String token,
                                                  String origin,
                                                  OAuthParams data)
        Configures an authenticated session using the provided session token. This can be used to reconnect to active sessions.
        Parameters:
        deploymentId - The ID of the Web Messaging deployment
        token - The session token
        origin - Represents the origin of the request. You can restrict access in Messenger Deployments
        data - The session OAuthParams for configuring Authenticated Session
      • disconnect

        public void disconnect()
        Closes the WebSocket connection
      • ping

        public void ping()
        Sends a message that will cause a response to ensure the connection is active
      • sendMessage

        public void sendMessage​(String message,
                                String... attachmentIds)
        Sends a message to the conversation
        Parameters:
        message - The text to send
        attachmentIds - The Id of the attachments being sent with the message
      • sendMessage

        public void sendMessage​(String message,
                                Map<String,​String> customAttributes,
                                String... attachmentIds)
        Sends a message to the conversation with customAttributes
        Parameters:
        message - The text to send
        customAttributes - Key Value Pair that allows custom data to be sent with a message
        attachmentIds - The Id of the attachments being sent with the message
      • sendPresenceEvent

        public void sendPresenceEvent()
        send an event of type Presence join
        See Also:
        EventPresence
      • sendTypingEvent

        public void sendTypingEvent()
        send an event of type Typing on
        See Also:
        EventTyping
      • attachment

        public void attachment​(String fileName,
                               int fileSize,
                               String fileType)
        send a request to generate an upload url for an attachment
      • getAttachment

        public void getAttachment​(String attachmentId)
        send a request to generate a download url for an attachment
      • deleteAttachment

        public void deleteAttachment​(String attachmentId)
        delete an attachment. Must not have been sent
      • getJwt

        public void getJwt()
      • addSessionListener

        public void addSessionListener​(WebMessagingClient.SessionListener sessionListener)
        Registers a SessionListener to receive events
        Parameters:
        sessionListener - An implementation of SessionListener
      • removeSessionListener

        public void removeSessionListener​(WebMessagingClient.SessionListener sessionListener)
        Unregisters a SessionListener object
        Parameters:
        sessionListener - The SessionListener to remove
      • setApiClient

        public void setApiClient​(ApiClient apiClient)
        Adds a custom ApiClient used for API requests
        Parameters:
        apiClient - An instance of ApiClient