@nistrix/chat

中文文档
0.1.3发布于 2026/11/02MITTypeScriptES Module零依赖

Nistrix chat for customers' sites and apps: visitors talk to the organization's agents and team with a publishable key (nx_pk_). Runs in browsers and React Native.

原始使用文档
文档目录8 节
  1. Install
  2. Get a key
  3. Use it
  4. React Native
  5. Errors
  6. Booking pages and lead forms
  7. Test environment
  8. Develop

@nistrix/chat

The Nistrix chat for your own site or app: your visitors talk to your Nistrix agents and team, in a screen you design. It runs in browsers and in React Native, with no other dependency.

It uses a publishable key (nx_pk_live_..., or nx_pk_test_... in your test environment). It is not a secret: it can only open visitor chats on one chat channel, from the sites and apps you listed on it. Never put a secret key (nx_sk_, nx_rk_) in a site or app.

Install

npm install @nistrix/chat

The SDK and publishable keys are on every Nistrix plan, with no add-on.

Get a key

In Nistrix, Integrations → API and MCP → Nistrix in your apps → Publishable keys: choose the chat channel, list your sites (https://shop.example) and apps (com.shop.app), and copy the key.

Use it

import { NistrixChat } from "@nistrix/chat";

const chat = new NistrixChat({
  publishableKey: "nx_pk_live_...",
  storage: window.localStorage, // keeps the visitor between visits
});

const history = await chat.messages();
await chat.send("Hi, can I book a time?", { name: "Bia" });

const stop = chat.subscribe((messages) => render(messages)); // the agent or team wrote
// later: stop();

React Native

Native apps have no origin, so they name themselves with appId (the bundle id or package name listed on the key):

import AsyncStorage from "@react-native-async-storage/async-storage";

const chat = new NistrixChat({
  publishableKey: "nx_pk_live_...",
  appId: "com.shop.app",
  storage: AsyncStorage,
});

Errors

Calls throw ChatError with the HTTP status and the API's code, for example origin-not-allowed (add the site or app to the key) or rate-limited.

Booking pages and lead forms

NistrixIntents uses the same key to show free times, ask for appointments, send leads, and turn sensitive values into data tokens. A booking or a lead is an intent (nx_int_, ten minutes) that your backend confirms with a secret key, unless the key confirms it on its own.

import { NistrixIntents } from "@nistrix/chat";

const nistrix = new NistrixIntents({ publishableKey: "nx_pk_live_..." });

const [slot] = await nistrix.slots({ service: "Cleaning", from: "2026-12-08" });
const booking = await nistrix.book({ start: slot.localStart, name: "Bia", phone: "92991234567" });

const cpf = await nistrix.tokenize("cpf", "529.982.247-25"); // nx_tok_..., never the value
const lead = await nistrix.submitLead({ phone: "92991234567", fields: { cpf: cpf.token } });

Test environment

A nx_pk_test_ key from your sandbox works the same way; conversations, bookings, and leads land in the sandbox, and test is true.

Develop

pnpm install
pnpm test
pnpm build

版本与发布记录

@nistrix/chat 共发布 5 个版本,首次发布于 2026/11/02;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.1.3latest2026/11/021 天前
0.1.22026/11/021 天前
0.1.12026/11/021 天前
0.1.02026/11/021 天前
0.0.0-stage2026/11/021 天前

关于 @nistrix/chat 的常见问题

@nistrix/chat 是什么?

Nistrix为客户的网站和应用程序提供聊天功能:访问者通过可发布的密钥(nx_pk_)与该组织的代理和团队交谈。在浏览器和React Native中运行。

如何安装 @nistrix/chat?

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

@nistrix/chat 支持 TypeScript 吗?

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

@nistrix/chat 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@nistrix/chat 可以商用吗?

@nistrix/chat 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@nistrix/chat 还在维护吗?

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