Skip to main content
Version: 5.21.0

Message methods

info

If the user types in the chat themselves, you do not need to call send(): the SDK handles sending from the built-in UI automatically. send() is for cases when your app initiates the message (for example, sending order context when opening the chat).

logout() / deauthorizeUser()

User sign-out methods are described in Authorization → Logout.

Sending and prefill

send(message: ChatMessage): Boolean

Sends a message on behalf of the currently authorized user.

Returns / throwsWhen
trueFor TextMessage / FileMessage: the user is authorized — the message is saved to the local DB and queued for sending (if the socket is active) or sent through a freshly opened socket. For LocationMessage: the user is authorized, or deviceAddress has not been received yet (in which case the coordinates are cached and sent after the device is registered).
falseFor TextMessage / FileMessage: the user is not authorized (authorize() was not called or was reset via logout() / deauthorizeUser()). For LocationMessage: deviceAddress has already been received but ChatUser / ChatAuth are missing, or the transport did not accept the send.
IllegalStateExceptionThe SDK is not initialized — call send() only after init() / initAsync().

ChatMessage subtypes:

  • ChatMessage.TextMessage(text: String) — text message
  • ChatMessage.FileMessage(file: File) — file
  • ChatMessage.LocationMessage(point: Point) — geolocation (edna.chatcenter.core.models.Point)
import edna.chatcenter.core.models.ChatMessage
import edna.chatcenter.core.models.Point

chatCenterUI.send(ChatMessage.TextMessage("Hello"))
chatCenterUI.send(ChatMessage.FileMessage(file))
chatCenterUI.send(ChatMessage.LocationMessage(Point(latitude = 55.7558, longitude = 37.6173)))

Message statuses — MessageStatus

edna.chatcenter.core.models.MessageStatus is the enum of message delivery states. The SDK updates the status automatically: SENDING → SENT → DELIVERED → READ for the success path; FAILED on a transport error; ENQUEUED for deferred sending.

ValueWhen it is set
SENDINGThe message is saved locally and being sent to the server
SENTThe server accepted the message
DELIVEREDThe message was delivered to the operator
READThe operator read the message
FAILEDSend error — the standard UI lets the user retry
ENQUEUEDDeferred sending (e.g., until the connection is restored)

The status is available in the sentState field of history items. In a custom UI, subscribe to changes via outgoingMessageStatusChangedFlow — it emits List<Status> with status updates for different messages.

prefill(message: String)

fun prefill(message: String)

Prefills the input field with the given text. The text is shown the next time the chat screen is opened. Pass an empty string ("") to clear a previously set prefill.

chatCenterUI.prefill("Hello, I have a question about order №12345")

// Clear the prefill
chatCenterUI.prefill("")

Unread message counter

updateUnreadCountMessagesIfNeed()

fun updateUnreadCountMessagesIfNeed()

Forcibly updates the unread message counter with a server request. The SDK also calls it automatically on authorize(...) — an explicit call is needed only if the app wants to trigger the update outside that scenario. If the user is not authorized, the update is skipped silently (no error).

UnreadMessagesController

For programmatic counter control, use UnreadMessagesController (an enum singleton):

Method / PropertyTypeDescription
pushesCountUIntCurrent count of unread push notifications; reading is thread-safe from any thread.
unreadMessagesPublishProcessorMutableSharedFlow<UInt>Reactive flow of counter changes — consumers can only read via collect; writes are reserved for the SDK. The flow does not deliver the current value on subscription (only new emissions); for the current value, use the pushesCount field.
refreshUnreadMessagesCount(getCountRemotely, block?)Refresh the counter. getCountRemotely = false by default. When true, fetches data from the server.
clearPushesCount()Locally resets pushesCount to 0. Does not emit an event to unreadMessagesPublishProcessor — if your UI updates only via the flow subscription, synchronize the badge manually.
// Get the current count of unread push notifications
val count = UnreadMessagesController.INSTANCE.pushesCount

// Subscribe to counter changes via Flow
lifecycleScope.launch {
UnreadMessagesController.INSTANCE.unreadMessagesPublishProcessor.collect { count ->
updateBadge(count)
}
}

// Forcibly refresh the counter (with a server request)
UnreadMessagesController.INSTANCE.refreshUnreadMessagesCount(getCountRemotely = true) { count ->
updateBadge(count)
}

// Clear the push notification counter
UnreadMessagesController.INSTANCE.clearPushesCount()

Message history storage

Message history lives in SQLite in process memory (in-memory): it is available for pagination, status updates, and search during the current run, but is not persisted to disk and is lost on process termination — on the next authorize(...) it is loaded from the server again.

A full overview of all SDK storages (prefs, push tokens, what survives logout()) is in Authorization → User data storage.

Thread safety and threads

Public SDK methods do not require a specific call dispatcher, except for methods that return or work with Android UI components.

MethodCall fromNote
init() / initAsync()Application.onCreate()init() performs initialization synchronously and blocks the calling thread; initAsync() does the same work asynchronously.
authorize()Any threadRequires the SDK to be initialized and a non-empty identifier. Network operations run asynchronously.
send()Any threadWriting to the local DB and sending via the SDK transport happen inside the method.
logout() / deauthorizeUser()Any threadSee Authorization → Logout.
getChatFragment()Main threadReturns an Android Fragment — work with UI components only from the main thread.
setChatCenterUIListener()Any threadThe call itself is thread-independent; where callbacks run — see below.
ChatFragment.onBackPressed()Main threadA Fragment method, call from the UI.
networkErrorReceived is not delivered on the main thread

Of the four ChatCenterUIListener callbacks, only networkErrorReceived is called from a background thread (OkHttp/Retrofit network). Before UI operations, switch to main explicitly. The full thread table and the recommended idiom are in Delegates → Callback threads.

  • Authorization (auth) — a required precondition for send().
  • DelegatesChatCenterUIListener and ChatUpdateProcessor.
  • Errors — what is delivered to networkErrorReceived and exceptionReceived.