Package cloud.genesys.webmessaging.sdk
Class WebMessagingClient
java.lang.Object
cloud.genesys.webmessaging.sdk.WebMessagingClient
A client used to connect to a Web Messaging session
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceImplement this listener to receive messages from the Web Messaging session -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new Web Messaging clientWebMessagingClient(String address) Creates a new Web Messaging client -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSessionListener(WebMessagingClient.SessionListener sessionListener) Registers aSessionListenerto receive eventsvoidattachment(String fileName, int fileSize, String fileType) send a request to generate an upload url for an attachmentvoidconfigureAuthenticatedSession(String deploymentId, String origin, OAuthParams data) Configures a new authenticated session with a randomly generated session tokenvoidconfigureAuthenticatedSession(String deploymentId, String token, String origin, OAuthParams data) Configures an authenticated session using the provided session token.voidconfigureSession(String deploymentId, String origin) Configures a new session with a randomly generated session tokenvoidConfigures a session using the provided session token.voidvoidconnect(String deploymentId, String origin, Optional<Integer> connectionTimeout, Optional<String> userAgent) Establishes a connection to Genesys Cloud via a WebSocketvoiddeleteAttachment(String attachmentId) delete an attachment.voidCloses the WebSocket connectionvoidgetAttachment(String attachmentId) send a request to generate a download url for an attachmentRetrieves the the messages for a web messaging session.voidgetJwt()static booleanhasEvents(StructuredMessage message, EventType type) Inspect a StructuredMessage, looking for a type of event (EventType)static booleanhasPresenceEvents(StructuredMessage message) Inspect a StructuredMessage, looking for Presence events (EventType.PRESENCE)static booleanhasTypingEvents(StructuredMessage message) Inspect a StructuredMessage, looking for Typing events (EventType.TYPING)booleanCheck whether the underlying websocket's input is closedbooleanCheck whether the underlying websocket's output is closedvoidjoinConversation(String deploymentId, String initialMessage, String origin) Full service operation to connect the WebSocket and configure the sessionvoidjoinConversation(String deploymentId, String token, String initialMessage, String origin) Full service operation to connect the WebSocket and configure the sessionvoidping()Sends a message that will cause a response to ensure the connection is activevoidremoveSessionListener(WebMessagingClient.SessionListener sessionListener) Unregisters aSessionListenerobjectvoidsendMessage(String message, String... attachmentIds) Sends a message to the conversationvoidSends a message to the conversation with customAttributesvoidsend an event of type Presence join for backward compatibilityvoidsend a Presence event by specifying the subtypevoidsend an event of type Presence clearvoidsend an event of type Presence joinvoidsend an event of type Typing onvoidsetApiClient(ApiClient apiClient) Adds a custom ApiClient used for API requests
-
Constructor Details
-
WebMessagingClient
Creates a new Web Messaging client- Parameters:
address- The WebSocket server's address, including the wss:// protocol
-
WebMessagingClient
Creates a new Web Messaging client- Parameters:
region- The WebSocket server's Genesys Cloud region
-
-
Method Details
-
hasPresenceEvents
Inspect a StructuredMessage, looking for Presence events (EventType.PRESENCE)- Parameters:
message- message to introspect for Presence events- Returns:
- true if a Presence event exists in this message, false otherwise
- See Also:
-
hasTypingEvents
Inspect a StructuredMessage, looking for Typing events (EventType.TYPING)- Parameters:
message- message to introspect for Typing events- Returns:
- true if a Typing event exists in this message, false otherwise
- See Also:
-
hasEvents
Inspect a StructuredMessage, looking for a type of event (EventType)- Parameters:
message- message to introspect for eventstype- type of event to look for- Returns:
- true if this type of event exists in this message, false otherwise
- See Also:
-
joinConversation
Full service operation to connect the WebSocket and configure the session- Parameters:
deploymentId- The ID of the Web Messaging deploymentinitialMessage- 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 deploymenttoken- The session tokeninitialMessage- The initial message to send once the session is ready
-
connect
-
connect
public void connect(String deploymentId, String origin, Optional<Integer> connectionTimeout, Optional<String> userAgent) Establishes a connection to Genesys Cloud via a WebSocket- Parameters:
deploymentId- deploymentId to connect toorigin- origin header to addconnectionTimeout- connection timeout, in second, to useuserAgent- user-agent string to be set in header connecting to the websocket. Optional, default of WebMessagingSdk-"version" will be used
-
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
Configures a new session with a randomly generated session token- Parameters:
deploymentId- The ID of the Web Messaging deploymentorigin- Represents the origin of the request. You can restrict access in Messenger Deployments
-
configureSession
public void configureSession(String deploymentId, String token, String origin, Optional<Boolean> startNew) 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 deploymenttoken- The session tokenorigin- Represents the origin of the request. You can restrict access in Messenger DeploymentsstartNew- true if you want to start a new session for your currently read-only session (after a Presence event of typeEventPresenceType.DISCONNECT)
-
configureAuthenticatedSession
Configures a new authenticated session with a randomly generated session token- Parameters:
deploymentId- The ID of the Web Messaging deploymentorigin- Represents the origin of the request. You can restrict access in Messenger Deploymentsdata- 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 deploymenttoken- The session tokenorigin- Represents the origin of the request. You can restrict access in Messenger Deploymentsdata- 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
Sends a message to the conversation- Parameters:
message- The text to sendattachmentIds- 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 sendcustomAttributes- Key Value Pair that allows custom data to be sent with a messageattachmentIds- The Id of the attachments being sent with the message
-
sendPresenceEvent
send a Presence event by specifying the subtype- See Also:
-
sendPresenceEvent
public void sendPresenceEvent()send an event of type Presence join for backward compatibility- See Also:
-
sendPresenceEventJoin
public void sendPresenceEventJoin()send an event of type Presence join- See Also:
-
sendPresenceEventEndUserClear
public void sendPresenceEventEndUserClear()send an event of type Presence clear- See Also:
-
sendTypingEvent
public void sendTypingEvent()send an event of type Typing on- See Also:
-
attachment
send a request to generate an upload url for an attachment -
getAttachment
send a request to generate a download url for an attachment -
deleteAttachment
delete an attachment. Must not have been sent -
getJwt
public void getJwt() -
addSessionListener
Registers aSessionListenerto receive events- Parameters:
sessionListener- An implementation ofSessionListener
-
removeSessionListener
Unregisters aSessionListenerobject- Parameters:
sessionListener- TheSessionListenerto remove
-
getHistory
Retrieves the the messages for a web messaging session.- Returns:
- WebMessagingMessageEntityList
- Throws:
WebMessagingException- if the request fails on the serverIOException- if the request fails to be processed
-
setApiClient
Adds a custom ApiClient used for API requests- Parameters:
apiClient- An instance ofApiClient
-