Sending text string to convai NPC via unity event system

Original Discord Post by etinesaego | 2024-08-02 10:53:47

Hello!

Here’s what I would like to do:
-I want to create a scenario where the player has multiple canvases that have different themes on them (cats, dogs, etc).

  • when the player presses a button on one of the scenes (eg cat or dog), a string of text is sent to the Convai UI akin to “tell me about cats”
  • the NPC then proceeds to talk about the subject without having the player speak or type the question.

notes-

  • this is in MR on Quest 3
  • Unity 2022.3.12f1
  • VR template installed
  • XR Rig adapted

THank you!

Reply by etinesaego | 2024-08-02 11:35:19

Im noticing that maybe the VR chat and the text-based input chat might be different. If the VR chat is only looking for audio input, then I dont have access (I think, please correct me) to the text input feature. Please advise

Reply by k3kalinix | 2024-08-03 14:17:23

Hello <@1101428836916264993>,

Reply by k3kalinix | 2024-08-03 14:19:09

In the Convai NPC component, you can use the SendTextDataAsync method.

Since it is a Core SDK component, it doesn’t matter if you are using VR or a different platform.

Reply by etinesaego | 2024-08-04 16:48:20

ok will try this tomorrow and see. thanks for the help

Reply by etinesaego | 2024-08-04 17:41:13

so you’re saying the message goes right to the server and not to the tmp input field?

Reply by k3kalinix | 2024-08-04 18:49:40

Yes

Reply by etinesaego | 2024-08-05 08:55:55

ok I’ll give it a go and see what i can come up with. will be back

Reply by etinesaego | 2024-08-05 10:12:49

do I need to have all the awaits from the try catch included?

Reply by k3kalinix | 2024-08-05 10:25:06

add await

Reply by etinesaego | 2024-08-05 10:35:07

await on its or await particular features?

Reply by k3kalinix | 2024-08-05 10:35:44

what do you mean

Reply by etinesaego | 2024-08-05 10:37:30

await ConvaiGRPCAPI.Instance.SendTextData(_client, text, characterID,
_isActionActive, _isLipSyncActive, ActionConfig, FaceModel);

Reply by k3kalinix | 2024-08-05 10:38:37

Why do you use grpcapi?

Reply by etinesaego | 2024-08-05 10:43:23

tbh i have no idea just that it breaks the script if i take it out

Reply by k3kalinix | 2024-08-05 10:43:54

Just use ConvaiNPC

Reply by etinesaego | 2024-08-05 10:49:50

ok here’s the script I was trying

Reply by etinesaego | 2024-08-05 10:50:48

using UnityEngine;
using System;
using System.Threading.Tasks;

public class npcText : MonoBehaviour
{

private ConvaiService.ConvaiServiceClient _client;

private void Start()
{
    SendTextDataAsync("Tell me about the hub");
}

public async void SendTextDataAsync(string text)
{
    try
    {
        var response = await _client.SendTextAsync(new TextRequest { Text = text });
        Debug.Log("Message sent: " + response.ResponseMessage);
    }
    catch (Exception ex)
    {
        Debug.LogError("Failed to send message: " + ex.Message);
    }
}

}

Reply by k3kalinix | 2024-08-05 10:51:26

Why did you create a new method?

Reply by k3kalinix | 2024-08-05 10:52:02

Just use ConvaiNPC’s SendTextDataAsync method.