Lifecycle callbacks

To create a robust virtual assistant, you must understand in which state a dialog with the user can be and know how and when the dialog transitions between the states.

Virtual assistant lifecycle

Every project you create with Alan AI goes through the following workflow:

  1. Project is created: The project lifecycle begins when you create and save scripts for your assistant in Alan AI Studio. At this step, Alan AI loads the scripts in the Alan AI Cloud and builds the project model for the assistant.

    Alan AI reloads scripts and rebuilds the project model every time you update and save scripts in Alan AI Studio.

  2. User is connected: When a new user opens an app with the AI assistant and starts a conversation, Alan AI connects to the project in the Alan AI Cloud, creates a new dialog for this user and assigns a unique ID to this dialog. For every user interacting with Alan AI, a separate dialog is created. All the communication with Alan AI is performed within this dialog, even if the user stops interaction for a while by clicking or tapping the AI assistant button.

  3. User is disconnected: When the user stops communicating with the app, he or she gets disconnected, and Alan AI closes the dialog created for the user. The dialog can also be closed in the following cases:

    • The user is inactive for a 30-minute period.

    • The dialog scripts for the project are reloaded.

Callbacks

As the dialog transitions from state to state, you may need to adjust the assistant behavior. To let you do it, Alan AI offers a set of predefined callbacks. You can use these callbacks to perform necessary tasks and handle significant events in your dialog script.

Here is a list of callbacks that can be used in Alan AI:

  • onCreateProject: This callback is invoked when the project is created and the project model is built. You can perform any initialization activities that may be required for your assistant.

  • onCreateUser: This callback is invoked when a new user connects to Alan AI and starts the dialog session. Here, for example, you can set user-specific data.

  • onCleanupUser: This callback is invoked when the user disconnects from Alan AI or the dialog is closed. Here you can perform any cleanup activities or save the user data.

  • onVisualState: This callback is invoked when the visual state is sent from the client app.

  • onEnter: This callback is invoked when a context added to the script is activated.

  • onUserEvent: This callback invoked when Alan AI emits events driven by users’ interactions with the AI assistant.