Package cloud.genesys.webmessaging.sdk
Class WebMessagingClient
- java.lang.Object
-
- cloud.genesys.webmessaging.sdk.WebMessagingClient
-
public class WebMessagingClient extends Object
A client used to connect to a Web Messaging session
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceWebMessagingClient.SessionListenerImplement this listener to receive messages from the Web Messaging session
-
Constructor Summary
Constructors Constructor Description WebMessagingClient(GenesysCloudRegionWebSocketHosts region)Creates a new Web Messaging clientWebMessagingClient(String address)Creates a new Web Messaging client
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSessionListener(WebMessagingClient.SessionListener sessionListener)Registers aSessionListenerto receive eventsvoidattachment(String fileName, int fileSize, String fileType)voidconfigureAuthenticatedSession(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 tokenvoidconfigureSession(String deploymentId, String token, String origin)Configures a session using the provided session token.voidconnect(String deploymentId, String origin)Establishes a connection to Genesys Cloud via a WebSocketvoiddeleteAttachment(String attachmentId)voiddisconnect()Closes the WebSocket connectionvoidgetAttachment(String attachmentId)WebMessagingMessageEntityListgetHistory()Retrieves the the messages for a web messaging session.voidgetJwt()voidjoinConversation(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 conversationvoidsendMessage(String message, Map<String,String> customAttributes, String... attachmentIds)Sends a message to the conversation with customAttributesvoidsetApiClient(ApiClient apiClient)Adds a custom ApiClient used for API requests
-
-
-
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 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
public void connect(String deploymentId, String origin)
Establishes a connection to Genesys Cloud via a WebSocket
-
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 deploymentorigin- 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 deploymenttoken- The session tokenorigin- 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 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
public void sendMessage(String message, String... attachmentIds)
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
-
getAttachment
public void getAttachment(String attachmentId)
-
deleteAttachment
public void deleteAttachment(String attachmentId)
-
getJwt
public void getJwt()
-
addSessionListener
public void addSessionListener(WebMessagingClient.SessionListener sessionListener)
Registers aSessionListenerto receive events- Parameters:
sessionListener- An implementation ofSessionListener
-
removeSessionListener
public void removeSessionListener(WebMessagingClient.SessionListener sessionListener)
Unregisters aSessionListenerobject- Parameters:
sessionListener- TheSessionListenerto remove
-
getHistory
public WebMessagingMessageEntityList getHistory() throws IOException, WebMessagingException
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
public void setApiClient(ApiClient apiClient)
Adds a custom ApiClient used for API requests- Parameters:
apiClient- An instance ofApiClient
-
-