-
public class EmilyChatSDK entry point. Owns the singleton state (configured options, a weak reference to the live EmilyChatActivity, the event callback) and exposes the imperative API host apps interact with.
Typical flow:
// 1. Configure once (e.g. in Application.onCreate or before first open). EmilyChat.configure( EmilyChatOptions( serviceSid = "LV3-...", userToken = session.token, ) ) // 2. Observe events (Ready / CloseRequest / BridgeError / LoadFailed). EmilyChat.onEvent = { event -> Log.d("Emily", event.toString()) } // 3. Open from any Context (Activity recommended for the slide-up animation). EmilyChat.open(activity)Or chained:
EmilyChat.configure(EmilyChatOptions(serviceSid = "LV3-...")).open(activity)Threading: call every method from the main thread (the default for UI code). onEvent is always invoked on the main thread.
-
-
Field Summary
Fields Modifier and Type Field Description private volatile EmilyChatOptionsoptionsprivate static Function1<EmilyChatEvent, Unit>onEventpublic final static EmilyChatINSTANCE
-
Method Summary
Modifier and Type Method Description final static EmilyChatconfigure(EmilyChatOptions options)Stores (or replaces) the configuration used by the next open. final static Unitopen(Context context)Launches the full-screen chat activity. final static Unitclose()Closes the chat activity (if any). final static UnitsetAttributes(Map<String, Object> attributes)Merges new attributes into the running conversation (forwarded as SET_ATTRIBUTES) and persists them into the stored options so a later open picks them up too.final static Unitlogout()Clears the user identity in the live chat (forwarded as LOGOUT) and from the stored options so subsequent opens start anonymous.final EmilyChatOptionsgetOptions()Active configuration. final UnitsetOptions(EmilyChatOptions options)final static Function1<EmilyChatEvent, Unit>getOnEvent()Receives every EmilyChatEvent. final static UnitsetOnEvent(Function1<EmilyChatEvent, Unit> onEvent)Receives every EmilyChatEvent. -
-
Method Detail
-
configure
final static EmilyChat configure(EmilyChatOptions options)
Stores (or replaces) the configuration used by the next open. Returns
thisso the call can be chained:EmilyChat.configure(opts).open(ctx).Reconfiguring while the chat is already open does NOT re-init the live WebView — close and re-open to apply structural changes (new
serviceSid/userToken). For in-flight tweaks use setAttributes.
-
open
final static Unit open(Context context)
Launches the full-screen chat activity. Requires configure to have been called first; otherwise no-ops and emits a EmilyChatEvent.BridgeError with stage
"open".- Parameters:
context- an Activity context is preferred (gives the default slide-up transition); an application context also works but addsFLAG_ACTIVITY_NEW_TASK.
-
close
final static Unit close()
Closes the chat activity (if any). Sends a
CLOSEbridge message first so the web side can run its own teardown. Safe to call when nothing is open — becomes a no-op.
-
setAttributes
final static Unit setAttributes(Map<String, Object> attributes)
Merges new attributes into the running conversation (forwarded as
SET_ATTRIBUTES) and persists them into the stored options so a later open picks them up too. No-op on the live chat if it isn't open.The map is forwarded flat, matching the web SDK's
Emily.setAttributes({ userId, contact_id })— call it after login and after each token refresh.
-
logout
final static Unit logout()
Clears the user identity in the live chat (forwarded as
LOGOUT) and from the stored options so subsequent opens start anonymous. Backend session invalidation is the host app's responsibility.
-
getOptions
final EmilyChatOptions getOptions()
Active configuration.
nulluntil configure is called.
-
setOptions
final Unit setOptions(EmilyChatOptions options)
-
getOnEvent
final static Function1<EmilyChatEvent, Unit> getOnEvent()
Receives every EmilyChatEvent. Always invoked on the main thread.
-
setOnEvent
final static Unit setOnEvent(Function1<EmilyChatEvent, Unit> onEvent)
Receives every EmilyChatEvent. Always invoked on the main thread.
-
-
-
-