realcoloride/node_characterai

Open a new conversation.

Closed this issue · 1 comments

Logging as Guest has a limit on the number of times and I want it to open a new conversation at the 6th dialogue. What should i do?

async function startChat() {
  const characterId = "Dyy_jfTJ3ZKddwqvo3EFURxtAXSfoij7pY8w97TlC84"; // Discord moderator
  console.log("Creating a chat...");

  characterAI = new CharacterAI(); 

  await characterAI.authenticateAsGuest();
  console.log("Created!");

  io.on('connection', (socket) => {
    console.log('Client connected');

    const chatPromise = characterAI.createOrContinueChat(characterId);

    socket.on('message', async (message) => {
      console.log('Received message:', message);

      const chat = await chatPromise;
      const response = await chat.sendAndAwaitResponse(message, true);

      console.log('Bot response:', response.text);
      count++;
      socket.emit('message', response.text);

      if (count === 2) {
      
        count = 0;
        characterAI = null;
        startChat(); 
      }
    });

    socket.on('disconnect', () => {
      console.log('Client disconnected');
    });
  });
}

startChat();

I've tried this,but it seems to be continuing an old conversation.

This is something with CharacterAI itself. Try opening an incognito tab and see that it will limit the amount of messages you can send before logging in.