| com.glia.androidsdk.chat.Chat |
Interface for managing chat activity.
To get instance of this class use getChat()
| Nested Classes | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| interface | Chat.ChatEvent<T> | ||||||||||
| class | Chat.Events | Defines Chat event types. | |||||||||
| enum | Chat.Participant | Defines possible chat participant types. | |||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| abstract <T> void |
off(ChatEvent<T> event, Consumer<T> listener)
Removes event listeners from the Chat.
| ||||||||||
| abstract <T> void |
off(ChatEvent<T> event)
Removes all event listeners from Chat.
| ||||||||||
| abstract <T> void |
on(ChatEvent<T> event, Consumer<T> listener)
Registers event listeners for Chat.
| ||||||||||
| abstract void | sendMessage(MessageAttachment attachment, RequestCallback<VisitorMessage> callback) | ||||||||||
| abstract void |
sendMessage(String message, MessageAttachment attachment, RequestCallback<VisitorMessage> callback)
Sends a chat message with an attachment to the Operator.
| ||||||||||
| abstract void | sendMessage(String message, RequestCallback<VisitorMessage> callback) | ||||||||||
| abstract void |
sendMessagePreview(String message)
Sends a message preview to the Operator.
| ||||||||||
Removes event listeners from the Chat.
If an event listener is removed while the Chat is processing an event, it is not triggered with the current event.
Calling off with arguments which do not identify any currently registered
listener has no effect.
| event | One of Chat.Events |
|---|---|
| listener | Event listener to remove |
Removes all event listeners from Chat.
Behaves the same way as off(ChatEvent, Consumer) but removes all listeners of specified type
| event | One of Chat.Events
|
|---|
Registers event listeners for Chat.
If a listener is added while the Chat is processing an event, it is not triggered with the current event.
If multiple identical listeners are registered on the same event type
the duplicate instances are discarded. They do not cause the listener
to be called twice and do not need to be removed with the off(ChatEvent) or
off(ChatEvent, Consumer) method.
| event | One of Chat.Events |
|---|---|
| listener | Event listener to register |
Sends a chat message with an attachment to the Operator.
Usage example:
engagement.getChat().sendMessage(messageContent, attachment, (visitorMessage, exception) -> {
if (exception != null) {
// failed to send message
return;
}
// message sent
});
Note, MESSAGE event triggers once request succeeds.
See on(ChatEvent, Consumer) for managing Chat events.
| message | The content of the message that should be sent to the Operator |
|---|---|
| attachment | The attachment that will be added to the message |
| callback | The callback called with VisitorMessage instance when request succeeds
or with GliaException. Exception may have one of following causes:
NETWORK_TIMEOUT - when request times out due to connection issues
INTERNAL_ERROR - when internal error occurs
INVALID_INPUT - if this Engagement has already ended |
Sends a message preview to the Operator.
The latest preview message is always visible to the Operator. This means that Operators can use the preview messages as an indication of Visitor activity. The Operator could also use the preview messages to start preparing a response before the Visitor finishes typing, ensuring a fast and seamless communication experience.
Usage example:
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable message) {
engagement.getChat().sendMessagePreview(message.toString());
}
}
| message | message that currently is being typed by Visitor |
|---|