HatangChat

object HatangChat

Entry point of the Hatang chat SDK. Call configure once (in Application.onCreate), then open the chat, identify the user and observe state / unreadCount / events.

HatangChat.configure(this, HatangConfig(siteId = "site_…", appKey = "hak_…"))
HatangChat.open(context)

Properties

Link copied to clipboard

The configuration given to configure; throws when it has not run.

Link copied to clipboard

The production gateway.

Link copied to clipboard

The state machine (advanced hosts); throws when configure has not run.

Link copied to clipboard
val events: Flow<HatangEvent>

Host-facing events: ready, opened, closed, messages, status, conversions, session changes, outdated.

Link copied to clipboard
Link copied to clipboard

A chat screen is on screen.

Link copied to clipboard

The current session (visitor, conversation, locale).

Link copied to clipboard
val state: StateFlow<ChatState>

Every snapshot the chat UI renders (an idle state before configure). Follows re-configuration.

Link copied to clipboard
val unreadCount: StateFlow<Int>

Messages received while the chat was not on screen (for badges).

Functions

Link copied to clipboard
suspend fun clearPushToken()

Unregisters the push token (sign-out).

Link copied to clipboard
fun close()

Closes every chat screen opened by open, openInbox or handleNotification.

Link copied to clipboard
fun configure(context: Context, config: HatangConfig)

Configures the SDK. Calling it again replaces the previous instance (the old engine is disposed). With HatangConfig.autoConnect the SDK bootstraps and connects in the background right away.

Link copied to clipboard
suspend fun connect()

Bootstraps and connects (after autoConnect = false or disconnect).

Link copied to clipboard

The conversation a Hatang notification points at, if any.

Link copied to clipboard
suspend fun disconnect()

Closes the socket; the SDK stays configured.

Link copied to clipboard
fun dispose()

Releases the engine and every resource; configure again to use the SDK afterwards.

Link copied to clipboard

Opens the conversation a Hatang notification points at (from the notification's tap, e.g. the launcher activity's intent extras). Returns false for foreign payloads. Starts the engine when it is not running yet (cold start).

Link copied to clipboard
suspend fun identify(user: HatangUser)

Attaches the host user's identity. Pass a hash (HMAC-SHA256 of the user id with the site's identity secret, computed on your server) for verified identities. Throws HatangException on failure.

Link copied to clipboard

true when an FCM data payload came from Hatang (hatang: "1").

Link copied to clipboard

The restore token inside a magic link: /c/<token> paths or a hatang_restore query parameter; null otherwise.

Link copied to clipboard
fun open(context: Context, conversationId: String? = null)

Opens the chat screen in its own activity (the active conversation, or conversationId).

Link copied to clipboard
fun openInbox(context: Context)

Opens the visitor's conversation list.

Link copied to clipboard
fun openIntent(context: Context, conversationId: String? = null): Intent

An intent that opens the chat (for a notification's PendingIntent).

Link copied to clipboard

The account id for one of your users: pass it as setObfuscatedAccountId when launching the Play billing flow so Google Play's notifications reach this customer in Hatang.

Link copied to clipboard
fun pushEvent(name: String, data: Map<String, Any?>? = null)

Records a custom event on the active conversation.

Link copied to clipboard
suspend fun reportPurchase(storeProductId: String, purchaseToken: String? = null, amount: Double? = null, currency: String? = null, productType: String = "subs", consumable: Boolean? = null): Boolean

After a successful in-app purchase. With the Play purchaseToken Hatang verifies it with Google, records it for this person and acknowledges it (Play refunds unacknowledged purchases after three days). productType is "subs" or "inapp"; consumable marks one-time products used up in the app. The team also gets an internal note.

Link copied to clipboard
suspend fun reset()

Forgets this visitor (sign-out): fresh visitor, old token revoked.

Link copied to clipboard
suspend fun restoreSession(linkToken: String)

Restores the session behind a "we replied" magic-link token (see linkTokenFromUri).

Link copied to clipboard
suspend fun setData(data: Map<String, Any?>)

Attaches custom attributes shown to agents.

Link copied to clipboard
suspend fun setLocale(locale: HatangLocale)

Switches the language.

Link copied to clipboard
suspend fun setPushToken(token: String)

Registers the FCM token for this visitor. Safe before the SDK is ready: registration is deferred and repeated when the visitor or app version changes. Call it from FirebaseMessagingService.onNewToken and once at start-up with FirebaseMessaging.getInstance().token.

Link copied to clipboard
fun setScreen(name: String, params: Map<String, String>? = null)

Reports the screen the app shows (Live board and page views).

Link copied to clipboard
fun showMessage(text: String, senderName: String? = null)

Shows a local-only assistant bubble (never sent to the gateway).