Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tokens don't work #13

Closed
Piipperi opened this issue Mar 8, 2023 · 30 comments
Closed

Tokens don't work #13

Piipperi opened this issue Mar 8, 2023 · 30 comments

Comments

@Piipperi
Copy link

Piipperi commented Mar 8, 2023

I've tried using the authenticateAsGuest() method, which gives me Error: Failed to fetch a lazy token.
authenticateWithToken() throws an Error: Token is invalid.

I copied the access_token without the access_token:, and I tried it twice to make sure I hadn't copied the wrong line or hadn't copied the entire token as it is very long.

Console doesn't seem to give any more specific information. Using Node v19.7.0 on macOS 12.6.3.

@realcoloride
Copy link
Owner

Could you show me the code? Have you sure you put the correct token? I have tried it on my environment and it works perfectly.
image

@Piipperi
Copy link
Author

Piipperi commented Mar 8, 2023

Here's the code which, aside from the Discord stuff and the character, I basically copied from the example. It might be a bit messy as I'm still kinda a noob with js.

Do you have the testing environment or some basic code which I could use to test if it works? Looking at an older issue #1 has the same error I get, but it wasn't very clear to me what they did to fix it.

const { SlashCommandBuilder } = require('discord.js');

const node_characterai = require('node_characterai');
const characterAI = new node_characterai();



module.exports = {
    data: new SlashCommandBuilder()
        .setName('cai')
        .setDescription("Talk to Braixen from Character.AI! Remember, don't take anything an AI says seriously.")
        .addStringOption(option =>
            option
            .setName('message')
            .setDescription('What is your message to them?')
            .setRequired(true)
        ),

    async execute(interaction, responseMessage, dateTime) {

        const message = interaction.options.getString('message')
        
        await characterAI.authenticateAsGuest();

        const characterId = "FdOuMH3rMG39zYwTvu5qIYcHda9_oMMpU14BolueOcI";

        const chat = await characterAI.createOrContinueChat(characterId);
        const response = await chat.sendAndAwaitResponse(message, true);

        responseMessage = "";
        await interaction.reply(responseMessage);
        console.log(`${dateTime}    Responded to commands with ${responseMessage}`);
    },
};

@realcoloride
Copy link
Owner

see the main page, you'll have an example.

const CharacterAI = require('node_characterai');
const characterAI = new CharacterAI();

(async() => {
    await characterAI.authenticateAsGuest();

    const characterId = "8_1NyR8w1dOXmI1uWaieQcd147hecbdIK7CeEAIrdJw" // Discord moderator

    const chat = await characterAI.createOrContinueChat(characterId);
    const response = await chat.sendAndAwaitResponse('Hello discord mod!', true)

    console.log(response);
    // use response.text to use it in a string.
})();

@realcoloride
Copy link
Owner

You're kinda doing things wrong too. you should store an instance of the chat or characterai and use it per request instead of keep logging and creating new character ai instances when a message is sent

@Piipperi
Copy link
Author

Piipperi commented Mar 8, 2023

Well there isn't much documentation about how to keep the conversation going without starting a new one + the command is still very barebones and I'm just trying to see if I can get it to return anything. I'll just try the code provided in an empty js file and see if it works tomorrow

@realcoloride
Copy link
Owner

realcoloride commented Mar 9, 2023 via email

@realcoloride
Copy link
Owner

realcoloride commented Mar 9, 2023 via email

@Piipperi
Copy link
Author

Piipperi commented Mar 9, 2023

I used your example code in a blank file, and it still just fails on the lazy token. I could probably still test it in a completely new node project folder to rule out if there's any npm package conflicting with it, but I don't think that would be the case. I tried using just Chrome to go to https://beta.character.ai/chat/auth/lazy/ which does work, but it says {"detail":"Method "GET" not allowed."}. That might be normal though

node test.js
/Volumes/Stuff 8 TB/Shared/BraixenBot/node_modules/node_characterai/client.js:211
        } else throw Error('Failed to fetch a lazy token')
                     ^

Error: Failed to fetch a lazy token
    at Client.authenticateAsGuest (/Volumes/Stuff 8 TB/Shared/BraixenBot/node_modules/node_characterai/client.js:211:22)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /Volumes/Stuff 8 TB/Shared/BraixenBot/test.js:5:5

Node.js v19.7.0

@1Hibiki1
Copy link

1Hibiki1 commented Mar 9, 2023

I'm having the same issue with the example code. Just to check, I added a console.log(request) inside authenticateAsGuest, and sure enough, it returns a 403. Not sure why that's happening though.

Edit: It works when I send the same request through Postman:
Screenshot 2023-03-09 at 12 38 40

@gwigz
Copy link

gwigz commented Mar 9, 2023

403 is likely Cloudflare blocking the request, which is what I'm seeing myself when I call using this and Node.

@realcoloride
Copy link
Owner

Hello!
Try using a proxy or a VPN. Doing it worked correctly for me. Which version of the package are you using? Which version of node?
image

@1Hibiki1
Copy link

1Hibiki1 commented Mar 9, 2023

I got it to work. I just had to update node. Didn't work with v19.5.0, but works with v19.7.0. Thanks everyone!

@realcoloride
Copy link
Owner

all good then, waiting for op to confirm if the issue was caused by the same problem

@Piipperi
Copy link
Author

all good then, waiting for op to confirm if the issue was caused by the same problem

Using Node.js v19.7.0 as seen on the other comments. What VPN do I need to use/which country do I need to connect to?

@realcoloride
Copy link
Owner

realcoloride commented Mar 10, 2023 via email

@Piipperi
Copy link
Author

Piipperi commented Mar 10, 2023

From Finland, not sure what the question about a code means.
If you're asking for my application's code, it's mentioned in the comment #13 (comment)

@1Hibiki1
Copy link

Using Node.js v19.7.0 as seen on the other comments. What VPN do I need to use/which country do I need to connect to?

If u don't have a VPN already, how about try Cloudflare WARP? It doesn't let you select specific country, but it's free. btw I'm in the USA and it works without a VPN.

@realcoloride
Copy link
Owner

I mean source code of the application

From Finland, not sure what the question about a code means. If you're asking for my application's code, it's mentioned in the comment #13 (comment)

@Piipperi
Copy link
Author

If u don't have a VPN already, how about try Cloudflare WARP? It doesn't let you select specific country, but it's free. btw I'm in the USA and it works without a VPN.

Tried with Cloudflare WARP, made no difference, unfortunately. This was expected though as Cloudflare has a server in my country, so WARP just connected to that.

I mean source code of the application

test.js
Or do you need the entire project folder?

@realcoloride
Copy link
Owner

This might be a region issue (use a vpn or proxy)/nodejs version/dependencies

@Piipperi
Copy link
Author

I tried out Windscribe to connect to US Central, still the same exact error. What version of node.js do I need and what dependencies? Shouldn't all of them be installed by npm?

@realcoloride
Copy link
Owner

realcoloride commented Mar 13, 2023

I tried out Windscribe to connect to US Central, still the same exact error. What version of node.js do I need and what dependencies? Shouldn't all of them be installed by npm?

"node-fetch": "^3.3.0",
"uuid": "^9.0.0",
"json-bigint": "^1.0.0"

@Piipperi
Copy link
Author

"node-fetch": "^3.3.0",
"uuid": "^9.0.0",
"json-bigint": "^1.0.0"

Checked and I seem to have all of them

piipperi@Piipperis-MacBook-Pro-13-2012 BraixenBot % npm info node-fetch version
3.3.1
piipperi@Piipperis-MacBook-Pro-13-2012 BraixenBot % npm info uuid version      
9.0.0
piipperi@Piipperis-MacBook-Pro-13-2012 BraixenBot % npm info json-bigint version
1.0.0

@realcoloride
Copy link
Owner

whats your current node version and package version?

@Piipperi
Copy link
Author

whats your current node version and package version?

I'm sorry but I've now replied with the node version 2 or 3 times. It's v19.7.0. And the package versions are listed on my earlier reply...
If you need the node_characterai version, it's the latest 1.1.0.......

@realcoloride
Copy link
Owner

realcoloride commented Mar 14, 2023

Hello! Your code did not fetch a lazy token for some reason, I will investigate the issue.
image

@realcoloride
Copy link
Owner

image
Turns out its because cloudflare seems to be blocking stuff...

@realcoloride
Copy link
Owner

realcoloride commented Mar 14, 2023

Hello again, I will try to find a way to go around cloudflare and update you today. Thank you for the patience!
If you have any idea in how I can go around it in the meantime, please let me know!
Roadmap issue - #14

@Naozumi520
Copy link

Naozumi520 commented Mar 14, 2023

@realcoloride After contacting w/ user K3YOMI in #1, it turns out that he fixed with adding the user agent. He sent me a copy with the patched package and it was working, but today I checked for it and it returns nothing. Here's his modified version and I have granted his permission. I hope this helps you to confirm what's going on in here.

node_characterai.zip

According to his instructions, there are two step to make it work:

  1. fill in the the token (not access token) in chat.js, by replacing (TOKEN HERE) to the token (Keep the TOKEN word)
    The token can be found in the network tab of dev tool, by searching recent:

Screenshot 2023-03-14 at 9 38 38 PM

Screenshot 2023-03-14 at 9 38 55 PM

  1. Only authenticateWithToken will work (with access token), cannot login as guest

I have confirmed that it was working yesterday night, but somehow it stopped working in today. See if it works for you.

@realcoloride
Copy link
Owner

Merging all updates for 1.1.1 in a new issue: #17.
Thank you for your understanding and patience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants