realcoloride/node_characterai

Which method should I use?

Closed this issue · 2 comments

I can't really figure out which method from which class should I use to talk to a bot without creating a new "chat" every single time I execute a script. What I mean by this is that I want to be able to speak to a character in the same "chat history" across every script execution.

Thanks in advance.

Hello there, you can keep using the same chat object, and if you want to resume the same one, you can store the chat's external id.

  const chat = await characterAI.createOrContinueChat(characterId);
  const response1 = await chat.sendAndAwaitResponse("Hello discord mod!", true);
  const response2 = await chat.sendAndAwaitResponse("How are you?", true);
  const response3 = await chat.sendAndAwaitResponse("I agree!", true);

  const externalId = chat.externalId;

  const sameChatDifferentObject = await characterAI.createOrContinueChat(characterId, externalId);
  const response4 = await sameChatDifferentObject.sendAndAwaitResponse("Hello again!", true);

Cheers

Thank you very much, I'll mark this as completed.