public class ZopimChatApi extends java.lang.Object implements ChatApi, ChatSession
Firstly, to initialize the chat call 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
start(android.support.v4.app.FragmentActivity)
.
Starting a chat will provide an instance of ChatApi
used for chat communication. That chat is the bound to
the lifecycle of the activity that was used to start the chat.
ChatApi
Modifier and Type | Class and Description |
---|---|
static class |
ZopimChatApi.DefaultConfig<T extends ZopimChatApi.DefaultConfig>
Configuration class for global chat configuration
|
static class |
ZopimChatApi.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 |
---|---|
void |
addNote(java.lang.String note)
Appends a note to the current visitor note
|
boolean |
emailTranscript(java.lang.String email)
Emails the current chat transcript
|
void |
endChat()
Ends the current chat.
|
ChatApiConfig |
getConfig()
Gets chat config for the current chat session as configured via
ZopimChatApi |
static DataSource |
getDataSource()
Gets chat data source defined in
DataSource and PathDataSource |
static java.lang.Long |
getInitializationTimeout()
Gets initialization timeout that was configured via
ZopimChatApi.DefaultConfig.initializationTimeout
If timeout was not configured it will return the ChatSession.DEFAULT_CHAT_INITIALIZATION_TIMEOUT |
static java.lang.Long |
getReconnectTimeout()
Gets reconnect timeout that was configured via
ZopimChatApi.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 ZopimChatApi.DefaultConfig |
init(java.lang.String accountKey)
Initiates chat and returns
ZopimChatApi.DefaultConfig configuration builder to be used for configuring
the global chat settings. |
void |
resend(java.lang.String messageId)
Re-sends the visitor message.
|
void |
resetTimeout()
Resets chat timeout.
|
static ChatApi |
resume(android.support.v4.app.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 session
|
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.
|
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 profile
|
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.
|
static void |
setVisitorInfo(VisitorInfo visitorInfo)
Configures the global
VisitorInfo |
static ChatApi |
start(android.support.v4.app.FragmentActivity activity)
Starts the chat with
ZopimChatApi.DefaultConfig global configuration. |
static void |
trackEvent(java.lang.String description)
Leaves an event trace.
|
@NonNull 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 static void trackEvent(java.lang.String description)
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.
description
- of the event@NonNull public ChatApiConfig getConfig()
ChatApi
ZopimChatApi
It will reflect ZopimChatApi.DefaultConfig
configuration values unless overridden via ZopimChatApi.SessionConfig
at chat start.
@NonNull public static java.lang.Long getReconnectTimeout()
ZopimChatApi.DefaultConfig.reconnectTimeout
If timeout was not configured it will return the ChatSession.DEFAULT_RECONNECT_TIMEOUT
@NonNull public static java.lang.Long getInitializationTimeout()
ZopimChatApi.DefaultConfig.initializationTimeout
If timeout was not configured it will return the ChatSession.DEFAULT_CHAT_INITIALIZATION_TIMEOUT
public void setDepartment(java.lang.String department)
Chat session must be connected in order to change session configuration.
setDepartment
in interface ChatApiCommands
department
- visitor is chatting withpublic void setPhoneNumber(java.lang.String phoneNumber)
setPhoneNumber
in interface ChatApiCommands
phoneNumber
- of the visitorpublic void setName(java.lang.String name)
setName
in interface ChatApiCommands
name
- of the visitorpublic void setEmail(java.lang.String email)
setEmail
in interface ChatApiCommands
email
- of the visitorpublic void setNote(java.lang.String note)
ChatApiCommands
setNote
in interface ChatApiCommands
note
- about the visitorpublic void addNote(java.lang.String note)
ChatApiCommands
addNote
in interface ChatApiCommands
note
- about the visitor to appendpublic void send(java.lang.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 ChatApiCommands
message
- to be sentpublic void send(java.io.File file)
ChatApiCommands
File must pass validation check and upload requirements defined in Zopim attachments page
A successful file upload will be visible in the agent dashboard.
send
in interface ChatApiCommands
file
- to sendChatLogObserver
,
Agent Dashboardpublic void resend(java.lang.String messageId)
ChatApiCommands
This message will appear in the agent dashboard.
resend
in interface ChatApiCommands
messageId
- id of the message to resendpublic void sendChatRating(@NonNull ChatLog.Rating rating)
ChatApiCommands
This will appear as a response to the chat rating questionnaire sent by an agent to the visitor.
sendChatRating
in interface ChatApiCommands
rating
- to setpublic void sendChatComment(@NonNull java.lang.String comment)
ChatApiCommands
sendChatComment
in interface ChatApiCommands
comment
- to setpublic 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 ChatServiceBinder
.
endChat
in interface ChatApiCommands
ConnectionObserver
public boolean hasEnded()
ChatApi
public boolean emailTranscript(java.lang.String email)
ChatApiCommands
It will send an email to the provided address with the current chat log
emailTranscript
in interface ChatApiCommands
email
- address to send the transcript topublic boolean sendOfflineMessage(java.lang.String name, java.lang.String email, java.lang.String message)
ChatApiCommands
Email must be provided in order for the agent to be able to respond.
sendOfflineMessage
in interface ChatApiCommands
name
- of the visitoremail
- of the visitormessage
- inquirypublic void resetTimeout()
ChatApi
ZopimChatApi.DefaultConfig.sessionTimeout(long)
.resetTimeout
in interface ChatApi
public static ZopimChatApi.DefaultConfig init(java.lang.String accountKey)
ZopimChatApi.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.accountKey
- Your account key obtained from the Zopim widget config page. Will configure chat to use your
Zopim instance.public static ChatApi start(android.support.v4.app.FragmentActivity activity)
ZopimChatApi.DefaultConfig
global configuration. Chat
needs to be previously initialized.activity
- that holds the chat sessionpublic static ChatApi resume(android.support.v4.app.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