Assistant Lifecycle Events

This page describes how developers can register for some interesting life-cycle events from the Assistant

The Slang Assistant handles most of the heavy lifting of interacting with the end-users and notifies the app when there is some action to be performed by the app. But in some cases, apps may want to be notified of low-level events that the Assistant is aware of. For example, whenever a user clicks on the trigger (the microphone button) or when the user cancels the Slang surface.

Access to low-level Assistant events is available through the Assistant's Lifecycle Events API.

Registering for events

The app can register with the Assistant to be notified of all interesting life-cycle events via the setLifeCycleObserver method

Java
React Native
Flutter
Web
Java
SlangRetailAssistant.setLifecycleObserver(observer);
React Native
SlangRetailAssistant.setLifecycleObserver(observer);
Flutter
SlangRetailAssistant.setLifecycleObserver(observer);
Web
‚Äč

As part of the Lifecycle Events API, an observer will be notified of the following events:

  • onAssistantInitSuccess

    • Called as soon as the Assistant has initialized successfully and is ready to serve the app

  • onAssistantInitFailure

    • Called when the Assistant failed to initialize successfully. The reason is passed as a parameter to this callback

  • onAssistantInvoked

    • Called whenever the Assistant has been launched (this can be either as a result of the user clicking on the trigger or the app invoking the Assistant via the startConversation API)

  • onAssistantClosed

    • Called whenever the Assistant has been dismissed. A boolean parameter isCanceled is passed to indicate whether this happened because the user canceled the session or if the Assistant was done with its job

  • onAssistantLocaleChanged

    • Called whenever the user changes the locale of the Assistant

  • onUnrecognisedUtterance

    • Called whenever the Assistant is not able to understand what the user spoke. The utterance that the user spoke is passed as a parameter.