New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@chatopera/sdk

Package Overview
Dependencies
Maintainers
2
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chatopera/sdk

Official sdk of Chatopera

  • 1.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
96
increased by433.33%
Maintainers
2
Weekly downloads
 
Created
Source

Chatopera开发者平台:809987971, 点击链接加入群聊

Chatopera


Chatopera提供聊天机器人开发者平台,Chatopera SDK用于在Node.js应用中集成聊天机器人服务

安装


npm install @chatopera/sdk --save

使用方法

var Chatbot = require("@chatopera/sdk");

var chatbot = new Chatbot(*ClientId*, *Secret*);

获取ClientId和Secret

点击这里

  • 创建聊天机器人

登录Chatopera控制台后,创建聊天机器人。

  • 获得认证信息

在【设置】页面,获得ClientId和Secret。

快速开始

通过示例程序快速开始使用SDK。

API接口

请先完成注册 Chatopera并创建一个聊天机器人。

说明:

1. 除创建机器人实例外,接口调用都是基于 async/await 方式。
2. 在非正常返回情况下,接口会抛出异常 Error(msg)。
3. 下面各接口的返回值,按正常情况下介绍。

获得聊天机器人实例

var Chatbot = require("@chatopera/sdk");
var chatbot = new Chatbot(*ClientId*, *Secret*);

获得聊天机器人详情

var detail = await chatbot.detail();

返回值

{
  "name": "bar",
  "fallback": "我不明白您的意思。",
  "description": "",
  "welcome": "你好!我是机器人客服。",
  "primaryLanguage": "zh_CN"
}

进行多轮对话

var reply = await chatbot.conversation("张三", "今天北京天气怎么样");

返回值

{
  "state": "default",
  "createdAt": 1540796868205,
  "string": "白天天气晴好,早晚会感觉偏凉,午后舒适、宜人。",
  "topicName": "weather",
  "subReplies": [],
  "service": {
    "provider": "conversation"
  },
  "logic_is_fallback": false,
  "botName": "bar"
}

说明:多轮对话的返回值的含义参考文档中心

进行FAQ对话

var reply = await chatbot.faq("张三", "停效期间的保单是否能办理减保");

返回值

[
  {
    "id": "AWa-Ogcaf3EIFA_CgZ3o",
    "score": 0.747,
    "post": " 停效期间的保单是否能办理减保?",
    "reply": " 停效期间的保单可以办理减保"
  },
  ...
]

说明:返回值为数组,id代表问答对ID,score是相似度分数,reply是回复。在含有多个元素时按score降序排列,score的分数在[0,1]之间,越接近1越相似。

查看用户列表

let users = await chatbot.users();

返回值

[
  {
    "userId": "张三",
    "lasttime": "2018-10-29T07:07:47.812Z",
    "created": "2018-10-29T05:02:13.084Z"
  },
  ...
]

说明: 按最后对话时间将序排列。

查看用户聊天历史

let chats = await chatbot.chats("张三");

返回值

[
  {
    "userId": "张三",
    "created": "2018-10-29T05:29:41.833Z",
    "textMessage": "白天天气晴好,早晚会感觉偏凉,午后舒适、宜人。",
    "direction": "outbound",
    "service": "conversation",
    "confidence": 1
  }
]

说明:按照每条消息的生成时间升序排列。

屏蔽用户

以该用户ID发送给聊天机器人信息时,将不能得到回复,此时回复内容参考文档

await chatbot.mute("张三");

返回值为空

取消屏蔽

将一个用户取消屏蔽。

await chatbot.ummute("张三");

返回值为空

查看用户是否被屏蔽

查看一个用户是否被这个机器人屏蔽了。

let result = await chatbot.ismute("张三"); 

返回值为Boolean

[true|false]

关于各接口返回值的更多描述参考开发者平台文档

license

Apache 2.0

Copyright 2017-2018, 北京华夏春松科技有限公司. 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.

chatoper banner

Keywords

FAQs

Package last updated on 08 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc