realcoloride / node_characterai

Unofficial Character AI wrapper for node.
https://beta.character.ai/
341 stars 72 forks source link

Which method should I use? #161

Closed gonz4DAG closed 5 months ago

gonz4DAG commented 5 months ago

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.

realcoloride commented 5 months ago

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

gonz4DAG commented 5 months ago

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