@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