@botpoison/node

中文文档
0.3.1发布于 2026/11/05TypeScriptESM + CJS零依赖近 30 天下载 3354

Botpoison for Node.js: verify Challenge solutions and classify form messages as spam or clean with Classify, from your server. No dependencies.

原始使用文档
文档目录7 节
  1. Challenge
  2. Classify
  3. Models
  4. Errors
  5. Timeout
  6. Testing
  7. Documentation

@botpoison/node

The server library for Botpoison. It does two jobs:

  • Challenge: verify the solution a form sends, so a submission from a script that skipped the puzzle is turned away. The browser side is @botpoison/browser.
  • Classify: send a form's message and get back spam or clean with a score, which catches the spam people type by hand. The model runs in Botpoison's own AWS account in Ireland, and Classify does not store the message to answer it.

It needs Node 18 or later and has no dependencies. Keys come from a project on botpoison.com, which is free to start, and one project's secret key works with both products.

npm install @botpoison/node

Challenge

const Botpoison = require("@botpoison/node");
// or: import Botpoison from "@botpoison/node";

const botpoison = new Botpoison({
  secretKey: process.env.BOTPOISON_SECRET_KEY,
});

const { ok } = await botpoison.verify(req.body._botpoison);
if (!ok) {
  return res.status(403).end();
}

verify rejects when Botpoison cannot be reached, and answers ok: false with the message Internal server error when the fault is on Botpoison's side. Decide what your form does with those submissions, and never accept one for a missing _botpoison, which is what every bot sends. verify sets no timeout of its own, so wrap it in one. See the library reference.

Classify

Labels a form submission spam or clean, with a score.

const botpoison = new Botpoison({
  secretKey: process.env.BOTPOISON_SECRET_KEY,
});

// The whole form, as your server received it.
const result = await botpoison.classify(req.body, { model: "spam-standard" });
// { label: "clean", score: 0.04, model: "spam-standard" }

if (result.label === "spam") {
  // drop it
}

label is Botpoison's recommended cut on score: spam from 0.8, clean below it, so the two never disagree. Acting on label is the default.

score is for custom thresholds and review queues. It runs from 0 to 1 and is not a probability. Two points on it stay fixed as the model is updated. The spam label flags about 1 in 1,000 good messages at 0.8, and about 1 in 100 good messages score 0.5 or more, which makes 0.5 a common place to start holding messages for a person. Both rates count all the traffic in our reference set together; a single site's own rates are usually several times higher, so log the score while you tune:

if (result.label === "spam") {
  // drop it
} else if (result.score >= 0.5) {
  // hold it for a person
}

A form with nothing written in it, such as an email-only sign-up, answers clean with a score of 0 unless the model is very confident it is spam.

The first argument is the content: a string for a single message box, or an object with one entry per form field. Send the whole form when you have it: the name, email and other fields are signals too. Values may be strings, numbers, booleans or lists of those; a nested object is refused. Fields whose name starts with _ are ignored, so form controls such as _redirect can stay in. A submission may hold up to 100 fields and 20,000 characters.

await botpoison.classify("Hi, do you ship to Belgium?", {
  model: "spam-standard",
});

The second argument is required, with model and an optional timeout.

Models

model names the model to classify with. spam-standard is the only model today. Botpoison updates it in place, and result.model names the model that answered. An unknown model is rejected with a 400 that lists the valid ones.

Errors

classify rejects with a Botpoison.ClassifyError, whose code says what failed:

codeMeaning
httpThe API answered with an error. status and message say why.
timeoutNo answer arrived in time.
networkThe request failed before an answer arrived.
invalid_responseThe API answered 200 with a body that is not a classification.

body holds the parsed response body when there is one. A 503 means classification is temporarily unavailable; decide whether your form fails open or closed rather than retrying in a loop.

let result;
try {
  result = await botpoison.classify(message, { model: "spam-standard" });
} catch (error) {
  if (!(error instanceof Botpoison.ClassifyError)) throw error;
  // Fail open: accept the submission unclassified, or queue it for later.
  result = undefined;
}

TypeScript users can import the types: ClassifyContent, ClassifyFields, ClassifyFieldValue, ClassifyOptions, ClassifyResult, ClassifyLabel, ClassifyError and ClassifyErrorCode.

Timeout

The call is abandoned 8000 ms after it starts by default, however the time is spent. Override it per call:

await botpoison.classify(content, { model: "spam-standard", timeout: 3000 });

Testing

Use the secret key test. Content containing botpoison-test-spam is labelled spam with a score of 1, botpoison-test-review is clean with a score of 0.6, and botpoison-test-unavailable answers 503. Anything else is clean with a score of 0.

Documentation

版本与发布记录

@botpoison/node 共发布 16 个版本,首次发布于 2021/01/23;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.3.1latest2026/11/053 天前
0.3.02026/10/1821 天前
0.2.02026/10/1821 天前
0.1.122026/08/312 个月前
0.1.112026/07/303 个月前
0.1.102021/10/215 年前

关于 @botpoison/node 的常见问题

@botpoison/node 是什么?

Botpoison for Node.js: verify Challenge solutions and classify form messages as spam or clean with Classify, from your server. No dependencies.

如何安装 @botpoison/node?

在项目目录运行 npm install @botpoison/node,或使用 pnpm add / yarn add / bun add。

@botpoison/node 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@botpoison/node 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@botpoison/node 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@botpoison/node 可以商用吗?

@botpoison/node 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@botpoison/node 的下载量有多少?

根据 npm 官方下载统计,@botpoison/node 在 2026/10/09 – 2026/11/07 这 30 天内被下载 3,354 次,日均约 112 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@botpoison/node 还在维护吗?

最新版本 0.3.1 发布于 2026/11/05(3 天前);至今共发布 16 个版本,其中过去 12 个月发布了 5 个;首次发布于 2021/01/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。