Giter Site home page Giter Site logo

poe-node-api's Introduction

poe-api-node

A reverse engineered Node.js client for Quora's Poe.

Support: Fetch needed info and write to .env file | send messages to different bot | set up proxies | clear/delete/purge messages | get history messages | get bot info | get next data

I'm still working on this, so it's might not stable. If your meet any problems, please create an issue.

Install

npm install poe-node-api

requirement:

  • node >= 18
  • .env: To store needed params like poe-formkey / cookie / buildId / botId.....

Usage

  1. Get cookie from poe.com: F12 / inspect, Application > Cookies > https://poe.com > p-b

  2. Create .env file in your project root path, and add cookie to .env file

cookie=p-b=xxxxxxxxxxxxxxxxxxxxxxxxxxx
  1. Fetch all needed info
const client = new PoeClient({logLevel: 'debug'});
await client.init()
// If no poe-formkey and buildId in .env file, client will download needed params, next time will not need to fetch these params again until cookie is changed/logout(For now).

How to create a client:

import {PoeClient} from "poe-node-api";

const client = new PoeClient({logLevel: 'debug'});
  • cookie?: string
  • env?: ProcessEnv(Default: process.env). for multi-account use, user can pass envMap to constructor, client will read needed info from that envMap
  • logLevel?: string(Default: 'info'). enable debug console output
  • fetch?: FetchFunction
    • type FetchFunction = typeof fetch
  • retry?: number(Default: 5).
  • retryMsInterval?: number(Default: 2000).
  • proxy?: ProxyInfo

How to init client

await client.init()
  • rewriteToLocalEnvFile: boolean = true. This means that the client will retrieve necessary parameters like buildId / poe-formkey and overwrite them in the local '.env' file.

To prevent conflicts, when using multi-account, you should set rewriteToLocalEnvFile to false

Bot nicknames

botNickName <==> botDisplayName

  • a2 <==> Claude-instant
  • a2_2 <==> Claude+
  • beaver <==> GPT-4
  • capybara <==> Sage
  • nutria <==> Dragonfly
  • chinchilla <==> ChatGPT
  • hutia <==> NeevaAI
  • Your own bot

SendMessage

/**
  * send message to bot
  * @param text user input
  * @param botNickName bot nick name, like capybara(Sage) / a2(Claude-instant) / a2_2(Claude+) etc.
  * @param withChatBreak Add a chat break or not. (Empty context)
  * @param callback When ws on message, will invoke this callback function.
 */
await client.sendMessage(text, botNickName, withChatBreak, (result: string) => {console.log(`${result}`)})

text: string

botNickName: string

withChatBreak: boolean

callback: (result: string) => void

Warning: Too many requests within one minute will result in (free)account being blocked !!!!!

I had sent about 20 messages in one minute, and now it's blocked. Login failed with error message: Something went wrong. Please wait a moment and try again.

So make sure you know what you're doing~

AddChatBreak

const res = await client.addChatBreak(botNickName);
  • botNickName: string

DeleteMessage

const res = await client.deleteMessage(messageIds);
  • messageIds: number[], messageIds to delete

PurgeAllMessage

const res = await client.purgeAllMessage();

Delete all bot messages, equals to click poe.com > Settings > Delete all messages

GetHistory

const history = await client.getHistory(botNickName, count);
  • botNickName: string
  • count?: number, Messages's count to get. (default: 25)

GetBotInfo

const history = await client.getBotByNickName(botNickName, retryCount, retryIntervalMs);
  • botNickName: string
  • retryCount?: number, If fetch bot info failed, will retry.
  • retryIntervalMs?: number, ms time to wait before next fetch. (default: 2000)

GetNextData

const history = await client.getNextData();

Can get poe-formkey / buildId / latest messages(like latest 5 messages) and startCursor(use startCursor to fetch history messages) / availableBots / x-forwarded-for / ......

UpdateAllBotInfo

await client.updateAllBotInfo()

This function will fetch poe-formkey, buildId, latest messages, startCursor and all bots info(chatId / id, this two params will be used to ).

This function will set poe-formkey / cookie / buildId / ${botDisplayName}_chatId and ${botDisplayName}_id to .env file(These parameters are the same as cookies and do not need to be requested every time).

Next time you send a msg to any bot, will not need to fetch bot info again, client will get needed params like buildId from local .env file.

Example

SendMessage

example - sendMessage.ts

Multi-account support

example - sendMessage.ts

SetProxy

example - proxy.ts

History

example - history.ts

FetchAllNeededInfo

example - fetchAllNeededInfo.ts

TODO

  • Add type definition to bots/viewer/nextData
  • Use free SMS/email services to log in?

Notes

  • I'm working on one of my project which can integrate any bot like chatgpt by plugin. But I can't find any poe node api, so I try to write this client. Huge thanks to poe-api(ISC License) and poe(MIT License).
  • .graphql files is merge from two repos above and find a new graphql to purge all message.
  • If you meet any problems, please create an issue.
  • I'm not familiar with ts, feel free give suggestions | create pull request.

Thanks

License

MIT

poe-node-api's People

Contributors

ahggg avatar xzunknownzx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

poe-node-api's Issues

Multi-account cookie and .env configuration issues

image

Hello author,
I ran your code and found the following code:

    const {BotNickNameEnum, PoeClient, sleep} = await import("poe-node-api")
    const client = new PoeClient({
        debug: true,
        cookie
    })
    await client.init()

Relevant configurations will be written into the .env configuration file, but if I have multiple account requirements, that is, if there are multiple cookies, it seems conflicting to put these configurations in .env. Can it be based on this requirement? Under optimization, these configurations are directly returned to the user for storage by executing await client.init(), and these variables are passed in when the next message is sent or initialized, thank you!

Error: unable to determine transport target for "pino-pretty"

__dirname: /Users/naozumi/Desktop/maple/node_modules/poe-node-api/dist
Error: unable to determine transport target for "pino-pretty"
at fixTarget (/Users/naozumi/Desktop/maple/node_modules/pino/lib/transport.js:140:13)
at transport (/Users/naozumi/Desktop/maple/node_modules/pino/lib/transport.js:114:22)
at normalizeArgs (/Users/naozumi/Desktop/maple/node_modules/pino/lib/tools.js:311:16)
at Function.pino (/Users/naozumi/Desktop/maple/node_modules/pino/pino.js:87:28)
at new PoeClient (file:///Users/naozumi/Desktop/maple/node_modules/poe-node-api/dist/PoeClient.js:71:28)
at module.exports (/Users/naozumi/Desktop/maple/src/messages/react.js:5:22)

Error: Invalid token or no bots are available.

Error:

Error: Invalid token or no bots are available. Might: network error, try to getDataNext first. Or Viewer dataStructure changed, please create an issue on github

My code:
api.js

import { PoeClient } from "poe-node-api";

const client = new PoeClient({ logLevel: "debug" });

await client.init();

await client.sendMessage(content, "a2", true, (result) => {
  console.log(`${result}`);
});

callApiFunction("Hello this is Amey");

I ran by using node api.js

my package.json dependencies

  "dependencies": {
    "pino-pretty": "^10.0.0",
    "poe-node-api": "^0.0.6"
  }

TypeError: Cannot read properties of undefined (reading 'on')

file:///C:/Users/rowan/Documents/bypassed/node_modules/poe-node-api/dist/PoeClient.js:448
ws.on('close', onClose);
^

TypeError: Cannot read properties of undefined (reading 'on')
at file:///C:/Users/rowan/Documents/bypassed/node_modules/poe-node-api/dist/PoeClient.js:448:16
at new Promise ()
at PoeClient.disConnectWs (file:///C:/Users/rowan/Documents/bypassed/node_modules/poe-node-api/dist/PoeClient.js:443:16)
at PoeClient.sendMessage (file:///C:/Users/rowan/Documents/bypassed/node_modules/poe-node-api/dist/PoeClient.js:162:24)
at sendMsg (file:///C:/Users/rowan/Documents/bypassed/server.js:15:18)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.15.0
PS C:\Users\rowan\Documents\bypassed>

Further development

Will you continue to develop? Is there or will there be an opportunity to save the context of the dialogue and start it not for me alone, but for other people? For example, I want to create a telegram bot through which my team will be able to communicate with the bot individually, that is, without being tied to a single chat.

displayName is not undefined

image

    getDisplayName(botNickName) {
        const displayName = this.displayNames[botNickName] || this.bots[botNickName]?.defaultBotObject?.displayName || (typeof botNickName !== 'string' && DisplayName[botNickName]);
        if (!displayName) {
            this.logger.error(`getDisplayNameByNickName failed, botNickName: ${botNickName}`);
        }
        console.log(`getDisplayNameByNickName, botNickName: ${botNickName}, displayName: ${displayName}`);
        return displayName;
    }

Hello author, now I am using the package to report an error. It seems that the displayName variable has not been obtained as undefined, resulting in url 404 requested later. The previous use is still normal. Is the official rule changed, or the format of the captured string has changed?

Conversations

How to follow a conversation in different accounds

Failed to fetch

Error: Failed to fetch https://poe.com after 5 retries
at file:///home/container/node_modules/poe-node-api/dist/PoeClient.js:108:24
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

mail services

I personally recommend tempmail.lol as mail service

Not working with Typescript

I'm using NestJS with the module, using npm install poe-node-api

import { PoeClient } from 'poe-node-api';
 const client = new PoeClient({ logLevel: 'debug' });

Getting Error

Error [ERR_REQUIRE_ESM]: require() of ES Module PROJECTFOLDER\node_modules\poe-node-api\dist\PoeClient.js from PROJECTFOLDER\dist\s1\s1.service.js not supported.
Instead change the require of PoeClient.js in PROJECTFOLDER\dist\s1\s1.service.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (PROJECTFOLDER\dist\s1\s1.service.js:14:21)
    at Object.<anonymous> (PROJECTFOLDER\dist\s2\s2.service.js:16:21)
    at Object.<anonymous> (PROJECTFOLDER\dist\s2\s2.module.js:12:22)
    at Object.<anonymous> (PROJECTFOLDER\dist\app.module.js:16:21)
    at Object.<anonymous> (PROJECTFOLDER\dist\main.js:6:20)

Any idea why ?

Not working

Error: ```
fetch: https://poe.com, options: {
method: 'GET',
headers: { cookie: 'p-b=5Zcy9-%3D%3D' }
}
fetch: https://poe.com/_next/data/vV4vHhyH3i9fz-iA02t-2/Sage.json, options: {
method: 'GET',
headers: { cookie: 'p-b=5Zcy9-%3D%3D' }
}
fetch: https://poe.com/_next/data/vV4vHhyH3i9fz-iA02t-2/GPT-4.json, options: {
method: 'GET',
headers: { cookie: 'p-b=5Zcy9-%3D%3D' }
}
fetch: https://poe.com/_next/data/vV4vHhyH3i9fz-iA02t-2/Claude+.json, options: {
method: 'GET',
headers: { cookie: 'p-b=5Zcy9-' }
}
fetch: https://poe.com/_next/data/vV4vHhyH3i9fz-iA02t-2/undefined.json, options: {
method: 'GET',
headers: { cookie: 'p-b=5Zcy9-%%3D' }
}
fetch failed: https://poe.com/_next/data/vV4vHhyH3i9fz-iA02t-2/undefined.json, 404, Not Found
retrying https://poe.com/_next/data/vV4vHhyH3i9fz-iA02t-2/undefined.json, 1/5...22
fetch failed: https://poe.com/_next/data/vV4vHhyH3i9fz-iA02t-2/undefined.json, 404, Not Found
retrying https://poe.com/_next/data/vV4vHhyH3i9fz-iA02t-2/undefined.json, 2/5...25
fetch failed: https://poe.com/_next/data/vV4vHhyH3i9fz-iA02t-2/undefined.json, 404, Not Found
retrying https://poe.com/_next/data/vV4vHhyH3i9fz-iA02t-2/undefined.json, 3/5...27
fetch failed: https://poe.com/_next/data/vV4vHhyH3i9fz-iA02t-2/undefined.json, 404, Not Found
retrying https://poe.com/_next/data/vV4vHhyH3i9fz-iA02t-2/undefined.json, 4/5...30
fetch failed: https://poe.com/_next/data/vV4vHhyH3i9fz-iA02t-2/undefined.json, 404, Not Found
retrying https://poe.com/_next/data/vV4vHhyH3i9fz-iA02t-2/undefined.json, 5/5...32
fetch failed: https://poe.com/_next/data/vV4vHhyH3i9fz-iA02t-2/undefined.json, 404, Not Found
Error: Failed to fetch https://poe.com/_next/data/vV4vHhyH3i9fz-iA02t-2/undefined.json after 5 retries
at file:///D:/projects/loick.team/projects/turing/dev/turing/turing-ai-api/node_modules/poe-node-api/dist/PoeClient.js:93:24
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.