public class ZopimChat extends Object implements Chat, ChatSession
Firstly, to initialize the chat call init(String)
with the correct account key obtained at your Zopim account configuration page.
A default 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 start(android.support.v4.app.FragmentActivity)
.
Starting a chat will provide an instance of Chat
used for chat communication. That chat is the bound to the lifecycle of the activity that was used to start the chat.
Chat
Modifier and Type | Class and Description |
---|---|
static class |
ZopimChat.ChatServiceBinder
Takes care of the chat service bind/unbind from the host activity that started the chat.
|
class |
ZopimChat.DefaultConfig
Configuration class for default chat configuration
|
static class |
ZopimChat.SessionConfig
Configuration class for session chat configuration
|
ACTION_CHAT_INITIALIZATION_TIMEOUT, ACTION_CHAT_SESSION_TIMEOUT, DEFAULT_CHAT_INITIALIZATION_TIMEOUT, DEFAULT_CHAT_SESSION_TIMEOUT, DEFAULT_RECONNECT_TIMEOUT
Modifier and Type | Method and Description |
---|---|
boolean |
emailTranscript(String email)
Emails the current chat transcript
|
void |
endChat()
Ends the current chat.
|
ChatConfig |
getConfig()
Gets chat config for the current chat session as configured via
ZopimChat |
static DataSource |
getDataSource()
Gets chat data source defined in
DataSource and PathDataSource |
static Long |
getInitializationTimeout()
Gets initialization timeout that was configured via
ZopimChat.DefaultConfig.initializationTimeout
If timeout was not configured it will return the ChatSession.DEFAULT_CHAT_INITIALIZATION_TIMEOUT |
static Long |
getReconnectTimeout()
Gets reconnect timeout that was configured via
ZopimChat.DefaultConfig.reconnectTimeout
If timeout was not configured it will return the ChatSession.DEFAULT_RECONNECT_TIMEOUT |
boolean |
hasEnded()
Tells if this chat session has ended and can not be continued.
|
static ZopimChat.DefaultConfig |
init(String accountKey)
Initiates chat and provides
ZopimChat.DefaultConfig configuration builder to allow setting the default chat configuration. |
void |
resetTimeout()
Resets chat timeout.
|
static Chat |
resume(FragmentActivity activity)
Attempts to resume the existing chat if possible.
|
void |
send(String message)
Sends the message to the agents.
|
boolean |
sendOfflineMessage(String name,
String email,
String message)
Sends email to agents defined in the dashboard for this account.
|
void |
setDepartment(String department)
Sets department to the current chat session
|
void |
setEmail(String email)
Sets visitor email to the current chat session
Chat session must be connected in order to change session configuration.
|
void |
setName(String name)
Sets visitor name to the current chat session
Chat session must be connected in order to change session configuration.
|
void |
setPhoneNumber(String phoneNumber)
Sets visitor phone number to the current chat session
Chat session must be connected in order to change session configuration.
|
static void |
setVisitorInfo(VisitorInfo visitorInfo)
Configures the default
VisitorInfo |
static Chat |
start(FragmentActivity activity)
Starts the chat with default configuration.
|
public static DataSource getDataSource()
DataSource
and PathDataSource
Data source provides subscription to data update broadcasts. It also enables to get current state of a data path.
public static void setVisitorInfo(VisitorInfo visitorInfo)
VisitorInfo
Visitor info can be set at any point, but the changes will take effect at next chat session start
visitorInfo
- visitor data from VisitorInfo
public ChatConfig getConfig()
Chat
ZopimChat
It will reflect ZopimChat.DefaultConfig
configuration values unless overridden via ZopimChat.SessionConfig
at chat start.
public static Long getReconnectTimeout()
ZopimChat.DefaultConfig.reconnectTimeout
If timeout was not configured it will return the ChatSession.DEFAULT_RECONNECT_TIMEOUT
public static Long getInitializationTimeout()
ZopimChat.DefaultConfig.initializationTimeout
If timeout was not configured it will return the ChatSession.DEFAULT_CHAT_INITIALIZATION_TIMEOUT
public void setDepartment(String department)
Chat session must be connected in order to change session configuration.
setDepartment
in interface ChatApi
department
- visitor is chatting withpublic void setPhoneNumber(String phoneNumber)
setPhoneNumber
in interface ChatApi
phoneNumber
- of the visitorpublic void setName(String name)
setName
in interface ChatApi
name
- of the visitorpublic void setEmail(String email)
setEmail
in interface ChatApi
email
- of the visitorpublic void send(String message)
If chat is unavailable at the moment it will cache this message until the communication recovers and re-send it again.
send
in interface ChatApi
message
- to be sentpublic void endChat()
In order to end it, the chat instance need to be able to communicate via 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 via ZopimChat.ChatServiceBinder
.
public boolean hasEnded()
Chat
public boolean emailTranscript(String email)
ChatApi
It will send an email to the provided address with the current chat log
emailTranscript
in interface ChatApi
email
- address to send the transcript topublic boolean sendOfflineMessage(String name, String email, String message)
ChatApi
Email must be provided in order for the agent to be able to respond.
sendOfflineMessage
in interface ChatApi
name
- of the visitoremail
- of the visitormessage
- inquirypublic void resetTimeout()
Chat
ZopimChat.DefaultConfig.sessionTimeout(long)
.resetTimeout
in interface Chat
public static ZopimChat.DefaultConfig init(String accountKey)
ZopimChat.DefaultConfig
configuration builder to allow setting the default chat configuration.
This configuration will apply to all new instances of chat session unless session configuration is provided at start time.accountKey
- Your account key obtained from the Zopim widget config page. Will configure chat to use your Zopim instance.public static Chat start(FragmentActivity activity)
activity
- that holds the chat sessionpublic static Chat resume(FragmentActivity activity)
Resuming a chat will be possible if the previous chat was not ended via endChat()
or expired.
Chat timeout time, defined here ChatSession.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 ended hasEnded()
.
Resumed chat might not be immediately ready to communicate, check canCommunicate()
.
activity
- that holds the chat session