@nistrix/chat

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

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

中文使用文档
文档目录8 节
  1. 安装
  2. 拿一把钥匙
  3. 使用它
  4. React Native
  5. 错误
  6. 预订页面和引导表单
  7. 测试环境
  8. 开发

@nistrix /聊天

Nistrix为您自己的网站或应用程序的聊天:您的访问者在您设计的屏幕上与您的Nistrix代理和团队交谈。它运行在浏览器和React Native中,没有其他依赖。

它使用 可发布的关键 (nx_pk_live_...,或者 nx_pk_test_... 在您的测试环境中)。这不是什么秘密:它只能打开一个聊天频道的访客聊天,来自你在上面列出的网站和应用程序。永远不要放秘钥nx_sk_, nx_rk_)在一个网站或应用程序。

安装

npm install @nistrix/chat

每个Nistrix计划都有SDK和可发布的密钥,没有附加组件。

拿一把钥匙

在Nistrix, 集成→API和MCP→应用程序中的Nistrix→可发布密钥:选择聊天频道,列出你的网站(https://shop.example)和应用程式(com.shop.app),并复制密钥。

使用它

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

原生应用没有起源,所以它们给自己命名为 appId (键上列出的包id或包名):

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

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

错误

电话把 ChatError 使用HTTP status 和API的 code例如: origin-not-allowed (将网站或应用程序添加到密钥中)或 rate-limited.

预订页面和引导表单

NistrixIntents 使用相同的键来显示空闲时间、请求约会、发送线索以及将敏感值转换为数据令牌。预定或引导是意图(nx_int_(10分钟),您的后端使用密钥进行确认,除非密钥自己进行确认。

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 } });

测试环境

一、 nx_pk_test_ 沙盒中的钥匙也是如此;对话、预订和潜在客户都落在了沙盒里 test 是 true.

开发

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 和提交记录判断。