Package 

Object EmilyChat


  • 
    public class EmilyChat
    
                        

    SDK 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.

    • Method Detail

      • configure

         final static EmilyChat configure(EmilyChatOptions options)

        Stores (or replaces) the configuration used by the next open. Returns this so 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 adds FLAG_ACTIVITY_NEW_TASK.
      • close

         final static Unit close()

        Closes the chat activity (if any). Sends a CLOSE bridge 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.