Class ZopimChatApi
- java.lang.Object
-
- com.zopim.android.sdk.api.ZopimChatApi
-
- All Implemented Interfaces:
- ChatApi, ChatApiCommands, ChatSession
public class ZopimChatApi extends java.lang.Object implements ChatApi, ChatSession
Definition for initialization and configuration of the chat.Firstly, to initialize the chat call
ZopimChatApi.init(String)
with the correct account key obtained at your Zopim account configuration page.A global chat configuration can be provided at initialization which will apply to all chat sessions that get started. Additionally, each chat session can be configured separately during chat start
ZopimChatApi#start(android.support.v4.app.FragmentActivity)
. Starting a chat will provide an instance ofChatApi
used for chat communication. That chat is the bound to the lifecycle of the activity that was used to start the chat.- See Also:
- Getting Started,
ChatApi
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static class
ZopimChatApi.DefaultConfig<T extends ZopimChatApi.DefaultConfig>
Configuration class for global chat configurationstatic class
ZopimChatApi.SessionConfig
Configuration class for session chat configuration
-
Field Summary
-
Fields inherited from interface com.zopim.android.sdk.api.ChatSession
ACTION_CHAT_APP_BACKGROUND, ACTION_CHAT_APP_FOREGROUND, ACTION_CHAT_BACKGROUND, ACTION_CHAT_FOREGROUND, ACTION_CHAT_INITIALIZATION_TIMEOUT, ACTION_CHAT_SESSION_TIMEOUT, DEFAULT_CHAT_INITIALIZATION_TIMEOUT, DEFAULT_CHAT_SESSION_TIMEOUT, DEFAULT_RECONNECT_TIMEOUT
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description void
addNote(java.lang.String note)
Appends a note to the current visitor notestatic void
clearPushToken()
Clear the token so that push notifications are no longer sent for agent chat messages.void
disconnect()
Disconnect the current chat, used when switching to push mode.boolean
emailTranscript(java.lang.String email)
Emails the current chat transcriptvoid
endChat()
Ends the current chat.ChatApiConfig
getConfig()
Gets chat config for the current chat session as configured viaZopimChatApi
static DataSource
getDataSource()
Gets chat data source defined inDataSource
andPathDataSource
static java.lang.Long
getInitializationTimeout()
Gets initialization timeout that was configured viaZopimChatApi.DefaultConfig.initializationTimeout
If timeout was not configured it will return theChatSession.DEFAULT_CHAT_INITIALIZATION_TIMEOUT
static java.lang.Long
getReconnectTimeout()
Gets reconnect timeout that was configured viaZopimChatApi.DefaultConfig.reconnectTimeout
If timeout was not configured it will return theChatSession.DEFAULT_RECONNECT_TIMEOUT
boolean
hasEnded()
Tells if this chat session has ended and can not be continued.static ZopimChatApi.DefaultConfig
init(java.lang.String accountKey)
Initiates chat and returnsZopimChatApi.DefaultConfig
configuration builder to be used for configuring the global chat settings.static void
onMessageReceived(PushData pushData)
Notify the SDK of FCM message receipt.void
resend(java.lang.String messageId)
Re-sends the visitor message.void
resetTimeout()
Resets chat timeout.static ChatApi
resume(FragmentActivity activity)
Attempts to resume the existing chat if possible.void
send(java.io.File file)
Sends the file to the current chat log.void
send(java.lang.String message)
Sends the message to the agents.void
sendChatComment(java.lang.String comment)
Sets a comment to the current chat session.void
sendChatRating(ChatLog.Rating rating)
Sets rating for the current chat session.boolean
sendOfflineMessage(java.lang.String name, java.lang.String email, java.lang.String message)
Sends email to agents defined in the dashboard for this account.void
setDepartment(java.lang.String department)
Sets department to the current chat sessionvoid
setEmail(java.lang.String email)
Sets visitor email to the current chat session Chat session must be connected in order to change session configuration.void
setName(java.lang.String name)
Sets visitor name to the current chat session Chat session must be connected in order to change session configuration.void
setNote(java.lang.String note)
Sets a note to the visitor profilevoid
setPhoneNumber(java.lang.String phoneNumber)
Sets visitor phone number to the current chat session Chat session must be connected in order to change session configuration.static void
setPushToken(java.lang.String token)
Set the push token to allow agent message to be sent to the app via push notifications.static void
setVisitorInfo(VisitorInfo visitorInfo)
Configures the globalVisitorInfo
static ChatApi
start(FragmentActivity activity)
Starts the chat withZopimChatApi.DefaultConfig
global configuration.static void
trackEvent(java.lang.String description)
Leaves an event trace.
-
-
-
Method Detail
-
getDataSource
public static DataSource getDataSource()
Gets chat data source defined inDataSource
andPathDataSource
Data source provides subscription to data update broadcasts. It also enables to get current state of a data path.
- Returns:
- data source
-
setVisitorInfo
public static void setVisitorInfo(VisitorInfo visitorInfo)
Configures the globalVisitorInfo
Visitor info can be set at any point, but the changes will take effect at next chat session start
- Parameters:
visitorInfo
- visitor data fromVisitorInfo
-
trackEvent
public static void trackEvent(java.lang.String description)
Leaves an event trace.It is possible to track event prior chat session being started. Tracked events will be sent as soon as chat session is connected and any further event after that point will be sent immediately.
- Parameters:
description
- of the event
-
getConfig
public ChatApiConfig getConfig()
Description copied from interface:ChatApi
Gets chat config for the current chat session as configured viaZopimChatApi
It will reflect
ZopimChatApi.DefaultConfig
configuration values unless overridden viaZopimChatApi.SessionConfig
at chat start.
-
setPushToken
public static void setPushToken(java.lang.String token)
Set the push token to allow agent message to be sent to the app via push notifications.- Parameters:
token
- the token received from FCM
-
clearPushToken
public static void clearPushToken()
Clear the token so that push notifications are no longer sent for agent chat messages.
-
onMessageReceived
public static void onMessageReceived(PushData pushData)
Notify the SDK of FCM message receipt.- Parameters:
pushData
- the push notification data
-
getReconnectTimeout
public static java.lang.Long getReconnectTimeout()
Gets reconnect timeout that was configured viaZopimChatApi.DefaultConfig.reconnectTimeout
If timeout was not configured it will return theChatSession.DEFAULT_RECONNECT_TIMEOUT
- Returns:
- reconnect timeout
-
getInitializationTimeout
public static java.lang.Long getInitializationTimeout()
Gets initialization timeout that was configured viaZopimChatApi.DefaultConfig.initializationTimeout
If timeout was not configured it will return theChatSession.DEFAULT_CHAT_INITIALIZATION_TIMEOUT
- Returns:
- initialization timeout
-
setDepartment
public void setDepartment(java.lang.String department)
Sets department to the current chat sessionChat session must be connected in order to change session configuration.
- Specified by:
setDepartment
in interfaceChatApiCommands
- Parameters:
department
- visitor is chatting with- See Also:
- Departments Dashboard
-
setPhoneNumber
public void setPhoneNumber(java.lang.String phoneNumber)
Sets visitor phone number to the current chat session Chat session must be connected in order to change session configuration.- Specified by:
setPhoneNumber
in interfaceChatApiCommands
- Parameters:
phoneNumber
- of the visitor- See Also:
- Agent Dashboard
-
setName
public void setName(java.lang.String name)
Sets visitor name to the current chat session Chat session must be connected in order to change session configuration.- Specified by:
setName
in interfaceChatApiCommands
- Parameters:
name
- of the visitor- See Also:
- Agent Dashboard
-
setEmail
public void setEmail(java.lang.String email)
Sets visitor email to the current chat session Chat session must be connected in order to change session configuration.- Specified by:
setEmail
in interfaceChatApiCommands
- Parameters:
email
- of the visitor- See Also:
- Agent Dashboard
-
setNote
public void setNote(java.lang.String note)
Description copied from interface:ChatApiCommands
Sets a note to the visitor profile- Specified by:
setNote
in interfaceChatApiCommands
- Parameters:
note
- about the visitor
-
addNote
public void addNote(java.lang.String note)
Description copied from interface:ChatApiCommands
Appends a note to the current visitor note- Specified by:
addNote
in interfaceChatApiCommands
- Parameters:
note
- about the visitor to append
-
send
public void send(java.lang.String message)
Sends the message to the agents.If chat is unavailable at the moment it will cache this message until the communication recovers and re-send it again.
- Specified by:
send
in interfaceChatApiCommands
- Parameters:
message
- to be sent- See Also:
- Agent Visitor List
-
send
public void send(java.io.File file)
Description copied from interface:ChatApiCommands
Sends the file to the current chat log. Successful file send will trigger a chat log update with information about the file being uploaded.File must pass validation check and upload requirements defined in Zopim attachments page
A successful file upload will be visible in the agent dashboard.
- Specified by:
send
in interfaceChatApiCommands
- Parameters:
file
- to send- See Also:
ChatLogObserver
, Agent Dashboard
-
resend
public void resend(java.lang.String messageId)
Description copied from interface:ChatApiCommands
Re-sends the visitor message.This message will appear in the agent dashboard.
- Specified by:
resend
in interfaceChatApiCommands
- Parameters:
messageId
- id of the message to resend- See Also:
- Agent Visitor List
-
sendChatRating
public void sendChatRating(ChatLog.Rating rating)
Description copied from interface:ChatApiCommands
Sets rating for the current chat session.This will appear as a response to the chat rating questionnaire sent by an agent to the visitor.
- Specified by:
sendChatRating
in interfaceChatApiCommands
- Parameters:
rating
- to set
-
sendChatComment
public void sendChatComment(java.lang.String comment)
Description copied from interface:ChatApiCommands
Sets a comment to the current chat session.- Specified by:
sendChatComment
in interfaceChatApiCommands
- Parameters:
comment
- to set
-
endChat
public void endChat()
Ends the current chat. This will update the connection status to closed.In order to end it the chat instance need to be able to communicate via
ZopimChatApi.canCommunicate()
. After the chat has ended the service will attempt to stop itself but will remain running until it's unbound from the host activity. Unbinding is done on host activity destruction and is handled viaChatServiceBinder
.- Specified by:
endChat
in interfaceChatApiCommands
- See Also:
ConnectionObserver
-
disconnect
public void disconnect()
Description copied from interface:ChatApiCommands
Disconnect the current chat, used when switching to push mode.- Specified by:
disconnect
in interfaceChatApiCommands
-
hasEnded
public boolean hasEnded()
Description copied from interface:ChatApi
Tells if this chat session has ended and can not be continued.
-
emailTranscript
public boolean emailTranscript(java.lang.String email)
Description copied from interface:ChatApiCommands
Emails the current chat transcriptIt will send an email to the provided address with the current chat log
- Specified by:
emailTranscript
in interfaceChatApiCommands
- Parameters:
email
- address to send the transcript to- Returns:
- true if email was sent, false otherwise
-
sendOfflineMessage
public boolean sendOfflineMessage(java.lang.String name, java.lang.String email, java.lang.String message)
Description copied from interface:ChatApiCommands
Sends email to agents defined in the dashboard for this account.Email must be provided in order for the agent to be able to respond.
- Specified by:
sendOfflineMessage
in interfaceChatApiCommands
- Parameters:
name
- of the visitoremail
- of the visitormessage
- inquiry- Returns:
- true if was able to send, false otherwise
-
resetTimeout
public void resetTimeout()
Description copied from interface:ChatApi
Resets chat timeout. This will offset the timeout by the value configured viaZopimChatApi.DefaultConfig.sessionTimeout(long)
.- Specified by:
resetTimeout
in interfaceChatApi
-
init
public static ZopimChatApi.DefaultConfig init(java.lang.String accountKey)
Initiates chat and returnsZopimChatApi.DefaultConfig
configuration builder to be used for configuring the global chat settings. This configuration will apply to all new instances of a chat session unless a new session configuration is provided when starting the new chat.- Parameters:
accountKey
- Your account key obtained from the Zopim widget config page. Will configure chat to use your Zopim instance.- Returns:
- configuration builder for setting the global chat configuration
-
start
public static ChatApi start(FragmentActivity activity)
Starts the chat withZopimChatApi.DefaultConfig
global configuration. Chat needs to be previously initialized.- Parameters:
activity
- that holds the chat session- Returns:
- chat session instance
-
resume
public static ChatApi resume(FragmentActivity activity)
Attempts to resume the existing chat if possible. Chat needs to be previously initialized.Resuming a chat will be possible if the previous chat was not ended via
ZopimChatApi.endChat()
or expired. Chat timeout time, defined hereChatSession.DEFAULT_CHAT_SESSION_TIMEOUT
is the time that expired after the last message exchange. If resuming was successful it will restore chat configuration from the server. If chat can not be resumed this will still return the chat instance but it won't be able to chat because it has endedZopimChatApi.hasEnded()
.Resumed chat might not be immediately ready to communicate, check
ZopimChatApi.canCommunicate()
.- Parameters:
activity
- that holds the chat session- Returns:
- chat session instance
-
-