npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

betach

v1.0.4

Published

Node.js Character.AI Unofficial API

Downloads

1

Readme

characterai.js Tests codecov

characterai.js

Node.js Character.AI Unofficial API

Index

Installation

Installation is done using the npm install command:

npm install characterai.js

Use

import CharacterAI from "characterai.js";

const message = "YOUR MESSAGE";

const characterAI = new CharacterAI(AI_KEY, CHARACTER_ID);
const chat = await characterAI.continueOrCreateChat();
const response = await chat.sendAndAwaitResponse({ message, singleReply: true });

console.log(response);

Get AI_KEY and CHARACTER_ID

AI_KEY

  1. Open your browser and press F12.
  2. Go to https://beta.character.ai/.
  3. Click on the Network tab.
  4. Click on Fetch/XHR filter.
  5. Find and click on auth0/.
  6. Go to the Response tab.
  7. Copy the key.

AI_KEY

CHARACTER_ID

  1. Open your character link in your browser.
  2. Copy the last part of the URL after char= that's your character ID.

CHARACTER_ID

Examples

List of examples of ways to use this package.

Text a character via the command-line

Text a character using a command prompt using the native readline node package.

  1. Install the necessary packages.

    npm install dotenv characterai.js
  2. Create a .env file in your project's root folder and paste your credentials.

    CHARACTER_ID = ""
    AI_KEY = ""

Code: cmd-chat.js

import CharacterAI from "characterai.js";
import { createInterface } from "readline";
import * as dotenv from "dotenv";
dotenv.config();

const getCharResponse = async (message) => {
  const characterAI = new CharacterAI(process.env.AI_KEY, process.env.CHARACTER_ID);
  const chat = await characterAI.continueOrCreateChat();
  const response = await chat.sendAndAwaitResponse({ message, singleReply: true });
  return response;
};

const readline = createInterface({
  input: process.stdin,
  output: process.stdout,
});

const chat = () => readline.question("Message: ", async (msg) => {
  if (msg == "exit") {
    return readline.close();
  }
  console.log("Response: ", await getCharResponse(msg), "\n");
  chat();
});

chat();

Discord bot integration

Text a character via Discord bot using the discord.js package. The bot looks for a message with an !ai prefix.

  1. Install the necessary packages.

    npm install discord.js dotenv characterai.js
  2. Create a .env file in your project's root folder and paste your credentials.

    DISCORD_TOKEN = " "
    CHARACTER_ID = ""
    AI_KEY = ""

Code: discord-bot.js

import { Client, GatewayIntentBits } from "discord.js";
import CharacterAI from "characterai.js";
import * as dotenv from "dotenv";
dotenv.config();

const getCharResponse = async (message) => {
  const characterAI = new CharacterAI(process.env.AI_KEY, process.env.CHARACTER_ID);
  const chat = await characterAI.continueOrCreateChat();
  const response = await chat.sendAndAwaitResponse({ message, singleReply: true });
  return response;
};

const client = new Client({ intents: [
  GatewayIntentBits.Guilds,
  GatewayIntentBits.MessageContent,
  GatewayIntentBits.GuildMessages,
  GatewayIntentBits.GuildIntegrations
] });

client.on("ready", () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on("messageCreate", async message => {
  if (message.content.startsWith("!ai")) {
    await message.channel.sendTyping();
    const mensaje = message.content.split("!ai ")[1];
    const { username } = message.author;
    try {
      const response = await getCharResponse(`${username} says:\n${mensaje}`);
      await message.reply(`${response}`);
    }
    catch (error) {
      console.log(error);
    }
  }
});

client.login(process.env.DISCORD_TOKEN);