Chat
Class Chat
- java.lang.Object
-
- com.boldchat.visitor.api.Chat
-
public class Chat extends java.lang.Object
This class is the main class that will be used to interact with an active chat session. You can register callback listeners which will receive updates and events related to the chat. An instance of this class can only be created by calling
Account.createChat(CreateChatListener)
orAccount.createChat(CreateChatListener, boolean)
. Once an instance of this class has been obtained you should then register any listeners you want to receive events, then callstartChat(ChatStartListener)
. If you register for an event after callingstartChat(ChatStartListener)
please be aware some messages may be lost.After the chat has been connected (as notified by events from
ChatStartListener
) then you can begin calling the api methods such assendMessage(String)
.After a chat has ended you should always make a call to
finishChat(ChatFinishedListener)
. This ensures that the server understands that the chat has ended, and allows you to retrieve any post-chat survey information.
-
-
Method Summary
Methods Modifier and Type Method and Description void
acceptActiveAssist(ActiveAssistSession activeAssistSession)
Notifies the server that the active assist session has been accepted by the visitor.void
addActiveAssistListener(ActiveAssistListener listener)
Add a listener that will receive messages about active assist sessions being started or updated.void
addChatListener(ChatListener listener)
Adds a listener that will receive updates when the status of this chat updates.void
addMessageListener(ChatMessageListener listener)
Add a listener that will receive new messages that are added to the chat.void
addQueueListener(ChatQueueListener listener)
Adds a listener that will receive queue update events.void
addTyperListener(ChatTyperListener listener)
Add a listener that will receive updates on the operator and visitor typing status.void
cancelActiveAssist(ActiveAssistSession activeAssistSession)
Notifies the server that the visitor has cancelled the active assist session.void
changeLanguage(java.lang.String language, LanguageChangeListener languageChangeListener)
Method used to change the language of the chat and retrieve a new set of branding values for the chosen language.void
emailChatHistory(java.lang.String email)
Sets the email address that will be sent a transcript of the chat when it completes.void
finishChat(ChatFinishedListener listener)
Ends the chat, this should always be called even if the chat has already been ended by the operator.Account
getAccount()
Retrieves the account object that created this object.java.util.Date
getAnswered()
Gets the answered date for this chat.int
getAnswerTimeout()
When AnswerTimeout is present, after that number of seconds has elapsed without the chat being answered, the client should callgetUnavailableForm(ChatUnavailableListener)
to end the chat and go to the unavailable form.java.util.Map<java.lang.String,java.lang.String>
getBrandings()
The Brandings are a set of key value pairs returned by the server that most commonly include text strings localized in the correct language.java.util.List<Message>
getChatHistory()
Returns a list of all messages that have been received by the server, this will not include messages that have been sent to the server, but not yet acknowledged.int
getClientTimeout()
Returns the maximum amount of time the server will wait before considering a chat abandoned.java.util.Date
getEnded()
Gets the date that either the operator or the visitor ended the chat.EndedReason
getEndedReason()
Gets the cause for the chat to end, or null if the chat has not yet ended.java.lang.String
getLanguage()
java.util.Date
getStarted()
java.util.Map<java.lang.Long,Typer>
getTypers()
Gets the set of known typers involved in this chat session.void
getUnavailableForm(ChatUnavailableListener chatUnavailableListener)
long
getVisitorID()
Gets the visitor id for this chat.boolean
isConnected()
Determines the connection status of the connection to the BoldChat server.boolean
isEnded()
Convenience method to test if the chat has been ended either by the visitor or the operator.boolean
isTimedOut()
void
pingChat(boolean chatClosed, ChatRecaptureListener recaptureListener)
Tells the server that the chat window is still open.void
removeActiveAssistListener(ActiveAssistListener listener)
Removes a listenervoid
removeChatListener(ChatListener listener)
Removes a listenervoid
removeMessageListener(ChatMessageListener listener)
Removes a listenervoid
removeQueueListener(ChatQueueListener listener)
Removes a listenervoid
removeTyperListener(ChatTyperListener listener)
Removes a listenerlong
sendMessage(java.lang.String message)
Send the message to the operator, this will immediately call theChatMessageListener.onPreliminaryMessageAdded(Message)
method, then later call theChatMessageListener.onMessageAdded(Message)
method after it has been fully received and processed by the server.void
sendMessage(java.lang.String message, long messageID)
Send the message to the operator, this will immediately call theChatMessageListener.onPreliminaryMessageAdded(Message)
method, then later call theChatMessageListener.onMessageAdded(Message)
method after it has been fully received and processed by the server.void
setVisitorName(java.lang.String visitorName)
Sets the name of the visitor.void
setVisitorTyping(boolean visitorTyping)
Sets the status indicating the visitor is typing in the message input field.void
startChat(ChatStartListener listener)
This method starts the created chat, and establishes all networking for communication while the chat is active.void
submitPostChat(Form postChat, PostChatSubmitListener submitListener)
Submits the post-chat data.void
submitPreChat(Form formData, ChatStartListener listener)
This call submits the information gathered on the Pre-Chat form.void
submitUnavailableEmail(Form formData)
Submits the unavailable form data to the server.
-
-
-
Method Detail
-
getVisitorID
public long getVisitorID()
Gets the visitor id for this chat. If this is the first time this app install has chatted then this value should be saved and all subsequent uses of theAccount
object should setAccount.setVisitorID(long)
with the saved value before callingAccount.createChat(CreateChatListener)
.- Returns:
- the visitor ID for this chat.
-
getAccount
public Account getAccount()
Retrieves the account object that created this object.- Returns:
- The account that created this chat.
-
getStarted
public java.util.Date getStarted()
- Returns:
- Gets the time that the chat was started, or null if the chat has not yet been started.
-
getAnswered
public java.util.Date getAnswered()
Gets the answered date for this chat. This may return null if the chat has not yet been answered.- Returns:
- The answered date, or null if the chat is not answered.
-
getEnded
public java.util.Date getEnded()
Gets the date that either the operator or the visitor ended the chat. This value may be null if the chat is still active.- Returns:
- The ended date, or null if the chat is still active.
-
isEnded
public boolean isEnded()
Convenience method to test if the chat has been ended either by the visitor or the operator.- Returns:
- true if the chat is ended, false otherwise.
-
getEndedReason
public EndedReason getEndedReason()
Gets the cause for the chat to end, or null if the chat has not yet ended.- Returns:
- The ended reason for the chat, or null if the chat is still active.
-
addChatListener
public void addChatListener(ChatListener listener)
Adds a listener that will receive updates when the status of this chat updates.- Parameters:
listener
- The listener for the chat status events.
-
removeChatListener
public void removeChatListener(ChatListener listener)
Removes a listener- Parameters:
listener
- The listener to remove
-
addQueueListener
public void addQueueListener(ChatQueueListener listener)
Adds a listener that will receive queue update events. If the chat is currently in a queue this listener will periodically be called to update the visitor on their position in the queue.- Parameters:
listener
- The listener to receive queue updates
-
removeQueueListener
public void removeQueueListener(ChatQueueListener listener)
Removes a listener- Parameters:
listener
- The listener to remove
-
addMessageListener
public void addMessageListener(ChatMessageListener listener)
Add a listener that will receive new messages that are added to the chat.- Parameters:
listener
- The listener for new messages.
-
removeMessageListener
public void removeMessageListener(ChatMessageListener listener)
Removes a listener- Parameters:
listener
- The listener to remove
-
addTyperListener
public void addTyperListener(ChatTyperListener listener)
Add a listener that will receive updates on the operator and visitor typing status.- Parameters:
listener
- The listener for typing status updates.
-
removeTyperListener
public void removeTyperListener(ChatTyperListener listener)
Removes a listener- Parameters:
listener
- The listener to remove
-
addActiveAssistListener
public void addActiveAssistListener(ActiveAssistListener listener)
Add a listener that will receive messages about active assist sessions being started or updated.- Parameters:
listener
- The listener to receive active assist messages.
-
removeActiveAssistListener
public void removeActiveAssistListener(ActiveAssistListener listener)
Removes a listener- Parameters:
listener
- The listener to remove
-
submitPreChat
public void submitPreChat(Form formData, ChatStartListener listener)
This call submits the information gathered on the Pre-Chat form. This method will NOT start the chat. This method behaves the same as if you calledstartChat(ChatStartListener)
.- Parameters:
formData
-listener
- The listener that should be called when the chat is started since this submit method behaves the same as a call tostartChat(ChatStartListener)
-
startChat
public void startChat(ChatStartListener listener)
This method starts the created chat, and establishes all networking for communication while the chat is active. This call should be made after the call toAccount.createChat(CreateChatListener)
. If there is pre-chat forms this method call should not be made until after the method call tosubmitPreChat(Form, ChatStartListener)
.- Parameters:
listener
- The callback listener that will be notified on the success (or failure) of starting the chat.
-
submitUnavailableEmail
public void submitUnavailableEmail(Form formData)
Submits the unavailable form data to the server.- Parameters:
formData
- The keys and values for the unavailable form.
-
setVisitorTyping
public void setVisitorTyping(boolean visitorTyping)
Sets the status indicating the visitor is typing in the message input field.- Parameters:
visitorTyping
- True if the visitor is typing, or false if the visitor has stopped typing.
-
setVisitorName
public void setVisitorName(java.lang.String visitorName)
Sets the name of the visitor. This affects the visitor name label the operator sees, as well as the label the visitor sees for their own messages.- Parameters:
visitorName
-
-
sendMessage
public long sendMessage(java.lang.String message)
Send the message to the operator, this will immediately call theChatMessageListener.onPreliminaryMessageAdded(Message)
method, then later call theChatMessageListener.onMessageAdded(Message)
method after it has been fully received and processed by the server.- Parameters:
message
- The message to send.- Returns:
- The identifier for the message, this is used to match the preliminary message added, with the real one processed by the server.
-
sendMessage
public void sendMessage(java.lang.String message, long messageID)
Send the message to the operator, this will immediately call theChatMessageListener.onPreliminaryMessageAdded(Message)
method, then later call theChatMessageListener.onMessageAdded(Message)
method after it has been fully received and processed by the server.- Parameters:
message
- The message to send.messageID
- The identifier for the message, this is used to match the preliminary message added, with the real one processed by the server.
-
getUnavailableForm
public void getUnavailableForm(ChatUnavailableListener chatUnavailableListener)
-
getClientTimeout
public int getClientTimeout()
Returns the maximum amount of time the server will wait before considering a chat abandoned.- Returns:
- The amount of time in seconds
-
finishChat
public void finishChat(ChatFinishedListener listener)
Ends the chat, this should always be called even if the chat has already been ended by the operator. This method call is the only way to retrieve the Post-Chat form data.- Parameters:
listener
- The listener that will be notified on the completion of the finishChat call.
-
submitPostChat
public void submitPostChat(Form postChat, PostChatSubmitListener submitListener)
Submits the post-chat data. If "email" is passed in the Data, a visitor chat transcript will be emailed in addition to storing the post-chat data on the chat record.- Parameters:
postChat
- The form data to be submitted.
-
pingChat
public void pingChat(boolean chatClosed, ChatRecaptureListener recaptureListener)
Tells the server that the chat window is still open. From the createChat call until the chat is completely done and closed this should be called every 30 seconds.- Parameters:
chatClosed
- When the window is closed, you can call pingChat with Closed set to true to update the server immediately with this informationrecaptureListener
- The listener that will be notified if an operator attempts to re-capture a chat that was denied to to operator availability.
-
acceptActiveAssist
public void acceptActiveAssist(ActiveAssistSession activeAssistSession)
Notifies the server that the active assist session has been accepted by the visitor.- Parameters:
activeAssistSession
- The active assist session that is being accepted.
-
cancelActiveAssist
public void cancelActiveAssist(ActiveAssistSession activeAssistSession)
Notifies the server that the visitor has cancelled the active assist session.- Parameters:
activeAssistSession
- The active assist session to cancel.
-
isConnected
public boolean isConnected()
Determines the connection status of the connection to the BoldChat server.- Returns:
- true if the socket is still connected, false if the socket is disconnected, or the chat has ended.
-
isTimedOut
public boolean isTimedOut()
- Returns:
- Determines if the connection has timed out by measuring the last time a heartbeat was received against the current time.
-
emailChatHistory
public void emailChatHistory(java.lang.String email)
Sets the email address that will be sent a transcript of the chat when it completes.- Parameters:
email
- The email address
-
changeLanguage
public void changeLanguage(java.lang.String language, LanguageChangeListener languageChangeListener)
Method used to change the language of the chat and retrieve a new set of branding values for the chosen language.- Parameters:
language
- The language to change.languageChangeListener
- The callback listener that will be notified with the new values.
-
getTypers
public java.util.Map<java.lang.Long,Typer> getTypers()
Gets the set of known typers involved in this chat session.- Returns:
- The list of typers.
-
getBrandings
public java.util.Map<java.lang.String,java.lang.String> getBrandings()
The Brandings are a set of key value pairs returned by the server that most commonly include text strings localized in the correct language. This method returns the most recent set of branding values that have been returned by the server either fromAccount.createChat(CreateChatListener)
, orchangeLanguage(String, LanguageChangeListener)
.- Returns:
- The most recent set of brandings available, or null if no branding values have been received.
-
getLanguage
public java.lang.String getLanguage()
- Returns:
- Returns the language for the current set of brandings.
-
getChatHistory
public java.util.List<Message> getChatHistory()
Returns a list of all messages that have been received by the server, this will not include messages that have been sent to the server, but not yet acknowledged.- Returns:
- The list of messages received by the server.
-
getAnswerTimeout
public int getAnswerTimeout()
When AnswerTimeout is present, after that number of seconds has elapsed without the chat being answered, the client should callgetUnavailableForm(ChatUnavailableListener)
to end the chat and go to the unavailable form.- Returns:
- The number of seconds to wait for an operator to answer the chat.
-
-