# @nistrix/chat 中文文档

规范地址：https://npmcn.com/package/%40nistrix/chat/

版本：0\.1\.3
npm 元数据更新时间：2026-11-01T23:29:31.017Z
中文译文更新时间：2026-11-02T00:34:55.742Z
软件包许可：MIT

本文由上游 README 机器翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40nistrix/chat
原文对照：https://npmcn.com/package/%40nistrix/chat/?lang=original
项目主页：https://github.com/nistrix-ltda/nistrix-chat-sdk#readme
源码仓库：https://github.com/nistrix-ltda/nistrix-chat-sdk

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：23.5 kB，9 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2026-11-01T17:23:55.729Z
- 最新版本发布：2026-11-01T23:29:30.834Z
- 已发布版本数：5（近 12 个月 5 个）

## 中文简介

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

## 安装

```sh
npm install @nistrix/chat
```

也可以使用：`pnpm add @nistrix/chat`、`yarn add @nistrix/chat`、`bun add @nistrix/chat`

## README

# @nistrix /聊天

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

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

## 安装

```bash
npm install @nistrix/chat
```

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

## 拿一把钥匙

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

## 使用它

```ts
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或包名）：

```ts
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分钟），您的后端使用密钥进行确认，除非密钥自己进行确认。

```ts
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`.

## 开发

```bash
pnpm install
pnpm test
pnpm build
```

## 常见问题

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

