1.1.2-alpha.0 • Published 1 year ago

bot-chatgpt v1.1.2-alpha.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

A simple Node.js module for interacting with the ChatGPT without using any Browser.

import chatGPT from "bot-chatgpt";

let bot = new chatGPT("<SESSION_TOKEN>");
let response = await bot.ask("Hello?");
console.log(response);

How the new method working without a browser?

The new method operates without a browser by utilizing a server that has implemented bypass methods to function as a proxy. The library sends requests to the server, which then redirects the request to ChatGPT while bypassing Cloudflare and other bot detection measures. The server then returns the ChatGPT response, ensuring that the method remains effective even if ChatGPT implements changes to prevent bot usage. Our servers are continuously updated to maintain their bypass capabilities.

Installation

To install the package, run the following command:

npm install bot-chatgpt

Usage

To use the package, require it in your code and create a new instance of the chatGPT class, passing in your ChatGPT API session token as an argument.

import chatGPT from "bot-chatgpt";

let bot = new chatGPT("<SESSION_TOKEN>");

// or if your accounts is pro
let bot = new chatGPT("<SESSION_TOKEN>", {
  proAccount: true,
});

Before making any requests to the API, you should wait for the bot instance to be ready by calling the waitForReady method. This ensures that the connection to the API has been established and any necessary setup has been completed.

await bot.waitForReady();

Once the bot instance is ready, you can send a message to the API using the ask method. This method takes a message string as its first argument and an optional conversation ID as its second argument. If a conversation ID is not provided, the default conversation will be used.

let response = await bot.ask("Hello?");
console.log(response);

let response2 = await bot.ask("Hello?", "any-unique-string");
console.log(response2);

The ask method returns a promise that resolves with the API's response to the message.

ES6 Update

This library is now using ES6 syntax and is intended to be used with the "module" type in your package.json file. This means that you will need to update your package.json file to include the following:

{
  "type": "module"
}

In addition, you will need to change any instances of "require" to "import" in your code. For example, instead of:

const chatGPT = require("bot-chatgpt");

You will now use:

import chatGPT from "bot-chatgpt";

API Reference

ChatGPT class

constructor(sessionToken: string, options: object)

Creates a new instance of the ChatGPT class.

Parameters
  • sessionToken (string): Your ChatGPT API session token.
  • options (object):
options = {
  name: string; // default = "default"
  reconnection: boolean; // default = true
  forceNew: boolean; // default = false
  logLevel: LogLevel; // default = Info
  bypassNode: string; // default = "https://gpt.pawan.krd"
  proAccount: boolean; // default = false
}
LogLevel = {
  Trace = 0,
  Debug = 1,
  Info = 2,
  Warning = 3,
  Error = 4
}

waitForReady(): Promise<void>

Waits for the chatGPT instance to be ready to make requests to the API. Returns a promise that resolves when the instance is ready.

ask(message: string, conversationId?: string): Promise<string>

Sends a message to the API and returns a promise that resolves with the API's response.

Parameters
  • message (string): The message to send to the API.
  • conversationId (string, optional): The ID of the conversation to send the message to. If not provided, the default conversation will be used.

Example

Here is an example of how to use the chatgpt module to send a message to the API and log the response:

import chatGPT from "bot-chatgpt";

(async function () {
  let bot = new chatGPT("<SESSION_TOKEN>");
  await bot.waitForReady();

  // default conversation
  let response = await bot.ask("Hello?");
  console.log(response);

  // specific conversation
  let response2 = await bot.ask("Hello?", "any-unique-string");
  console.log(response2);
})();

Event example(Alpha)

import chatGPT from "bot-chatgpt";

(async function () {
  let bot = new chatGPT("<SESSION_TOKEN>");

  bot.onConnected = async () => {
    await bot.waitForReady();
    // default conversation
    let response = await bot.ask("Hello?");
    console.log(response);
  };
})();

Server Example

In examples/server.js you can find an example of how to use the chatgpt module to create a simple Fastify server that can be used to send messages to ChatGPT.

Run the server by setting the CHATGPT_SESSION_TOKEN environment variable to your ChatGPT API session token and running the following command:

node examples/server.js

You can also set the port with the CHATGPT_PORT environment variable. The default port is 3000.

To send a message to the server, make a POST request to http://localhost:<port>/ask with the following JSON body:

{
  "message": "Hello?",
  "conversation_id": "any-unique-string"
}