Chat

public interface Chat implements AutoCloseable

Current chat instance. Client is not limited to a single instance of any given chat. They can create (or rather build) as many instances as they like. They are though advised that creating CONFLICTING (or identical) instances with the same configuration may lead to unexpected consequences.

After creating an instance via build, the customer is automatically authorized if the authorization is enabled and the customer was not previously authorized, otherwise reconnects the customer. The created chat instance also starts listening for the authorization and updates customer details after customer authorization. The time it takes to reach the device is undefined.

Moreover, it starts listening to events that modify welcome messages. Therefore, a welcome message is only available after we receive the given event and requires no actions from the client side. The time it takes to reach the device is undefined.

Functions

Link copied to clipboard
public abstract ChatActionHandler actions()

Returns new instance of an action handler for this Chat.

Link copied to clipboard
public abstract Unit close()

Closes the connection to the chat backend and removes all listeners, even those the client forgot to unregister.

Link copied to clipboard
public abstract Cancellable connect()

Attempts to connect the chat session using existing configuration, the attempt will be made on background thread. Successful connection will be announced to the ChatStateListener.onConnected which was supplied in ChatBuilder. If there is an issue during/after reconnection the ChatStateListener.onUnexpectedDisconnect will be called, it is responsibility of application to perform a repeated reconnection attempt, if it is desirable. Reconnect attempts should be performed only if the device is connected to the internet. If the repeated reconnection attempts are made, they should be called with exponential backoff, in order to prevent backend overload.

Link copied to clipboard
public abstract ChatFieldHandler customFields()

Creates new instance to modify global custom fields.

Link copied to clipboard
public abstract ChatEventHandler events()

Creates new instance to interact with this instance.

Link copied to clipboard
public abstract Cancellable getChannelAvailability(Function1<Boolean, Unit> callback)

Determine if a chat is available.

Link copied to clipboard
Link copied to clipboard
public abstract Configuration getConfiguration()

Current options of the channel as received from the backend. It will remain unchanged while this Chat instance exists.

Link copied to clipboard
public abstract Environment getEnvironment()

Current environment provided by the SocketFactoryConfiguration. It will remain unchanged for the duration while this object exists.

Link copied to clipboard
public abstract Collection<CustomField> getFields()

Current collection of global customer CustomFields set in SDK. Instance provided by the method won't be updated if the CustomFields collection is updated in the Chat, it should be considered as a snapshot of current state. Values can be updated from backend, after ChatThreadsHandler.refresh call.

Link copied to clipboard
public abstract Boolean isChatAvailable()

Last known channel availability.

Link copied to clipboard
@Deprecated(message = "Deprecated, use connect() instead.", replaceWith = @ReplaceWith(imports = {}, expression = "connect()"))
public abstract Cancellable reconnect()

Attempts to restart the chat session using existing configuration, the attempt will be made on background thread. Successful connection will be announced to the ChatStateListener.onConnected which was supplied in ChatBuilder. If there is an issue during/after reconnection the ChatStateListener.onUnexpectedDisconnect will be called, it is responsibility of application to perform a repeated reconnection attempt, if it is desirable. Reconnect attempts should be performed only if the device is connected to the internet. If the repeated reconnection attempts are made, they should be called with exponential backoff, in order to prevent backend overload.

Link copied to clipboard
public abstract Unit setDeviceToken(String token)

Sets device token (notification push token) to this instance and transmits it to the server. It's not guaranteed that the token is delivered to the server though. Therefore, clients are strongly advised to call this method every time they receive new tokens and reconnect to this instance.

Link copied to clipboard
public abstract Unit setUserName(String firstName, String lastName)

Attempts to change username if the channel configuration allows setting of the username. All subsequent events sent from chat will have new value filled out.

Link copied to clipboard
public abstract Unit signOut()

Signs out the user, clears all stored values and closes the connection. Client doesn't need to call close explicitly.

Link copied to clipboard
public abstract ChatThreadsHandler threads()

Creates new instance to observe and interact with Threads.