@chatopera/node-alchemist
v1.0.6
Published
Node.js SDK for alchemist
Downloads
20
Readme
Chatopera Alchemist SDK for Node.js
Chatopera Front Desk Service / Chatopera 前台服务
Welcome
npm install @chatopera/node-alchemist
Usage
var Alchemist = require("@chatopera/node-alchemist");
const client = new Alchemist(YOUR_SERVER_IP, YOUR_SERVER_PORT);
await client.connect(); // 建立连接
| key | value |
| ------------------ | ------------------------------------- |
| YOUR_SERVER_IP
| alchemist 服务 IP,比如 "localhost"
|
| YOUR_SERVER_PORT
| alchemist 服务端口,比如 9000
|
chat
对话接口
resp = await client.chat({
message: {
channel: "node",
channel_id: "sdk",
user_id: "test002",
type: "textMessage",
payload: "老婆聊天轻浮"
}
})
- request
| key | value |
| ---------- | -------------------------------------------------------- |
| channel | 渠道,比如 "gzh" 代表微信公众号 |
| channel_id | 渠道 ID,比如 "gzh_xxx",对应渠道的标识 |
| user_id | 用户唯一标识 |
| type | textMessage
代表文本消息,imageMessage
图片消息, etc. |
| payload | 传递消息内容,字符串 |
- response[Promise]
{
"rc": 0,
"message": {
"channel": "node",
"channel_id": "sdk",
"user_id": "test002",
"createdate": "1585195702.748119",
"type": "textMessage",
"payload": "你和老婆的感情怎样呢?",
"is_question": true,
"is_knowledge": false,
"is_fallback": false
},
"error": null
}
返回值为 json 格式,其中rc
为 0 代表正常返回;rc
不为 0 为异常返回,异常原因见error
。
正常返回下, message
代表机器人回复。
| key | value | | ------------ | ------------------ | | channel | 请求的渠道 | | channel_id | 渠道标识 | | user_id | 用户标识 | | createdate | 消息创建 timestamp | | type | 返回的消息类型 | | payload | 消息内容 | | is_question | 是不是追问 | | is_knowledge | 有没有知识性 | | is_fallback | 是不是兜底 |
close
该client
在connect
成功后,建立与alchemist
服务端的长连接,如果需要结束连接,释放资源,使用close
接口。
client.close();
Copyright
Copyright 2020 Chatopera Inc. https://www.chatopera.com. All rights reserved. This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited.