Hey There!, I’m curious to know if its possible and how to change the Core Description of a Character and update it in realtime within a script. This will save me time rather than having to create multiple characters with different Descriptions. Hoping to hear from someone! Thanks
Hello @Dylan_Suaris,
To update a character’s Core Description in real-time, you need to use Convai’s Character Crafting API.
Documentation: Character API - Update Character
Please note that this feature is available on specific plans. You can find more details under Character Crafting API on our Pricing page.
Let us know if you have any other questions!
Hey, I just got a plan which has the Convai’s Character Crafting API …The documentation isnt too clear on how to implement in my C# Script…What i have is 5 different buttons…each button has its own topic, when i click either of these buttons i want to change my backstory and update it in realtime. Any help would be appreciated.
Welcome to the Convai Developer Forum!
The documentation provides general guidance using Python, but implementing it in Unity with C# depends on your coding knowledge, particularly on how to make Web Requests in Unity.
Here’s a sample script to help you get started:
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
using System.Text;
public class ConvaiCharacterUpdater : MonoBehaviour
{
private string apiUrl = "https://api.convai.com/character/update";
[System.Serializable]
public class CharacterData
{
public string charID;
public string backstory;
}
void Start()
{
// Start the API request
StartCoroutine(UpdateCharacter());
}
IEnumerator UpdateCharacter()
{
if (!ConvaiAPIKeySetup.GetAPIKey(out string apiKey)) return;
// Create JSON data
CharacterData characterData = new CharacterData
{
charID = "<Character ID>", // Add your Character ID here
backstory = "Raymond Reddington is a highly intelligent, highly driven individual with developed sociopathic tendencies..."
};
string jsonData = JsonUtility.ToJson(characterData);
byte[] postData = Encoding.UTF8.GetBytes(jsonData);
Debug.Log("Sending JSON: " + jsonData);
// Create HTTP request
UnityWebRequest request = new UnityWebRequest(apiUrl, "POST");
request.uploadHandler = new UploadHandlerRaw(postData);
request.downloadHandler = new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
request.SetRequestHeader("CONVAI-API-KEY", apiKey);
// Send the request
yield return request.SendWebRequest();
// Check the response
if (request.result == UnityWebRequest.Result.Success)
{
Debug.Log("Character updated successfully: " + request.downloadHandler.text);
}
else
{
Debug.LogError("Error updating character: " + request.error);
Debug.LogError("Server Response: " + request.downloadHandler.text);
}
}
}
This script demonstrates how to make a POST request to the Character Crafting API in Unity using UnityWebRequest.
If you have multiple buttons, you can modify this to call UpdateCharacter() when each button is clicked.
Let me know if you need further assistance!