How to Reset Chat and Restart Conversation After Inactivity in Unity WebGL

Hi Convai team,

I’m working on a Unity WebGL project using Convai, and I’ve implemented an intro poster screen with a “Start” button. Once the user clicks “Start,” the Convai avatar begins interacting with the user, If there is no user response for 3 minutes the intro poster with the Start button reappear.

Currently, I can return to the intro screen, but I’m not sure how to fully reset the Convai conversation and clear the previous chat messages.

My questions is How can I reset or restart the conversation and the chat box after inactivity or after pressing the start button on the intro screen?

Thank you!!

Hello,

To fully reset the session, you should re-initialize the Convai client when you return from the intro screen. Use the example in ConvaiGRPCWebAPI.cs under SetInteractionTarget as a reference and call the WebGL initializer again.

Example

// Initialize the JS client for the new target NPC
#if UNITY_WEBGL && !UNITY_EDITOR
// Prepare configurations
string templateKeyJSON = GetJsonString(_currentInteractingNPC.NarrativeDesignKeyController?.narrativeDesignKeyController, "NarrativeDesign Keys");
string actionConfigJSON = GetJsonString(_currentInteractingNPC.ActionsHandler?.ActionConfig, "Action Config");

// Call the internal wrapper for JS client initialization
InitializeConvaiClientWrapper(
    _currentInteractingNPC.characterID,
    enableAudioRecorder: true,
    actionConfigJson: actionConfigJSON,
    templateKeysJson: templateKeyJSON
);
#else
InitializeConvaiClientWrapper(_currentInteractingNPC.characterID, true, "", "");
#endif

Suggested flow:

On inactivity timeout or when pressing Start on the intro screen:

  • Stop listening/talking if active.
  • Clear your chat UI/history. (ChatBoxUI.cs → ClearUI)
  • Call the initialization wrapper again (as above) to start a fresh session.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.