Accessing Session ID

Original Discord Post by yxmx3472 | 2024-11-01 20:00:54

Hello! So I’m trying to access the session id’s on the dashboard so that my character can remember past details from the game. I’ve been fiddling with the SessionManager script from this page: Managing sessionID Locally | Documentation My issue is that I don’t know the npc client is null when I’m trying to get it; public ConvaiService.ConvaiServiceClient grpcClient;
, it is null when I run the script. It is not visible/accessible through the inspector so I’m going through a ConvaiNPC to use GetClient(). I would like to be to get session ID from the dashboard. What is the best way to do that, to get the client correctly.

Embedded Content:
Managing sessionID Locally | Documentation
Session ID Management - Manage unique session IDs for Convai Unity integration.
Link: Managing sessionID Locally | Documentation

Reply by yxmx3472 | 2024-11-01 20:01:16

Here is my script: using System.Threading.Tasks;
using Convai.Scripts.Runtime.Core;
using Service;
using UnityEngine;

public class SessionManager : MonoBehaviour
{
public string characterName;
public string characterID;
public ConvaiNPC convaiNPC;

private ConvaiService.ConvaiServiceClient grpcClient;

private void Start()
{
   
    if (convaiNPC != null)
    {
        grpcClient = convaiNPC.GetClient(); 
        InitializeSession(characterName, grpcClient, characterID);
    }
    else
    {
        Debug.LogError("No ConvaiNPC found in the scene.");
    }
}

private async void InitializeSession(string characterName, ConvaiService.ConvaiServiceClient client, string characterID)
{
    if (client == null)
    {
        Debug.LogError("gRPC client is not initialized.");
        return;
    }

    string sessionID = await InitializeSessionIDAsync(characterName, client, characterID);

    if (!string.IsNullOrEmpty(sessionID))
    {
        Debug.Log("Session ID initialized and stored: " + sessionID);
    }
    else
    {
        Debug.LogError("Failed to initialize session ID.");
    }
}

public static async Task<string> InitializeSessionIDAsync(string characterName, ConvaiService.ConvaiServiceClient client, string characterID)
{
    string sessionID = PlayerPrefs.GetString(characterID, string.Empty);

    if (string.IsNullOrEmpty(sessionID))
    {
        sessionID = await ConvaiGRPCAPI.InitializeSessionIDAsync(characterName, client, characterID, sessionID);

        if (!string.IsNullOrEmpty(sessionID))
        {
            PlayerPrefs.SetString(characterID, sessionID);
            PlayerPrefs.Save();
        }
    }

    return sessionID;
}

}

Reply by k3kalinix | 2024-11-01 20:06:57

You have to use the Long Term Memory feature.

Reply by k3kalinix | 2024-11-01 20:10:39

Embedded Content:
Long Term Memory | Documentation
Learn how to enable character retain conversation history across multiple sessions
Link: Long Term Memory | Documentation

Reply by yxmx3472 | 2024-11-01 20:23:10

Thank you, yes I did use the long-term memory component on the npc and enabled it as well as on the dashboard. The npc also has a narrative design. I’m unsure if it affects it, but the npc doesn’t remember a specific thing from a previous session.

Replying to yxmx3472’s Message

Reply by yxmx3472 | 2024-11-01 20:23:10
Thank you, yes I did use the long-term memory component on the npc and enabled it as well as on the dashboard. The npc also has a narrative design. I’m unsure if it affects it, but the npc doesn’t remember a specific thing from a previous session.

Reply by k3kalinix | 2024-11-01 20:25:23

Could you please check Speaker IDs from the Toolbar?

Reply by k3kalinix | 2024-11-01 20:25:50

Images:

Reply by yxmx3472 | 2024-11-01 20:29:33

Mine looks different, is it because I’m suppose to have access to it in a higher tier?

Images:


Reply by yxmx3472 | 2024-11-01 20:36:22

Sorry wrong png earlier, but I don’t see it

Images:

Reply by k3kalinix | 2024-11-01 21:12:13

Please update it to 3.2.0

Reply by yxmx3472 | 2024-11-01 21:16:05

Ok no problem, but where do I download different versions I just picked up the one I currently have from the UnityStore

Reply by k3kalinix | 2024-11-01 21:16:29

Reply by k3kalinix | 2024-11-01 21:17:18

It was released yesterday. You can update from Package Manager.

Reply by yxmx3472 | 2024-11-01 21:17:52

Ok thank you I’ll try it out

Reply by yxmx3472 | 2024-11-01 21:36:36

My speaker Id is not there, it’s empty. Am I suppose to get one for it to work?

Reply by k3kalinix | 2024-11-01 23:45:36

Convai/Resources/PlayerDataSO

Reply by k3kalinix | 2024-11-01 23:45:49

There should be a bool

Reply by k3kalinix | 2024-11-01 23:46:08

Called Create a speaker id

This conversation happened on the Convai Discord Server, so this post will be closed.