Git Product home page Git Product logo

chatopera-sample-node's Introduction

企业聊天机器人-Node.js 端示例程序

本教程介绍如何使用 Chatopera 机器人开发者平台的Node.js SDK与机器人进行集成,阅读本教程需要 20 分钟时间。

获取源码

安装

创建机器人

执行程序

帮助

更多 SDK

开源许可协议

获取源码

git clone https://github.com/chatopera/chatopera-sample-node.git

安装

cd chatopera-sample-node
npm install

创建机器人

登录 Chatopera 聊天机器人平台

点击“立即使用”

第一登录输入“邮箱”和“密码”,点击“回车键”,完成账户创建。

创建聊天机器人

点击“创建机器人”,并填入下面各项:

项目 描述
机器人名称 小松 机器人的名字
描述 机器人示例 机器人的描述
语言 zh_CN 机器人的语言,目前支持中文(zh_CN)和英文(en_US)

【提示】其它项如兜底回复,问候语可以在创建后,设置页面修改。

下载知识库文件

下载知识库示例文件保全作业中常见问题.xlsx,保存文件名为保全作业中常见问题.xlsx

导入知识库

上传知识库文件

选择保全作业中常见问题.xlsx,这时,会显示问答对列表,点击“提交”,在进度条完成后,知识库导入成功。

测试知识库

知识库测试窗口

输入: 保全作业中常见问题

确认得到回复。

获取ClientIdSecret

集成机器人服务的方式是通过 SDK,每个机器人实例需要通过ClientIdSecret初始化,完成认证和授权。打开机器人【设置】页面,拷贝ClientIdSecret

显示Secret

执行程序

假设您已经准备好ClientIdSecret了,进入项目路径然后执行下面命令。

cd chatopera-sample-node
node index.js *ClientId* *Secret*

如果想查看机器人平台返回结果的日志:

cd chatopera-sample-node
DEBUG=chatopera:sample:node node index.js *ClientId* *Secret*

与机器人对话

程序介绍

index.js是主要程序脚本,核心如下:

var Chatopera = require('@chatopera/sdk'); # 引入SDK
var client = new Chatopera(clientId, secret); # 创建机器人实例
client.conversation('用户唯一标识', '用户输入').then( // 返回值为 Promise 类型
    (resp) => {
        resp.string // 机器人回复
    },
    (err) =>  {
        console.log(err) // 异常返回
    }
);

更多接口介绍请访问SDK 文档

帮助

获得命令提示信息。

node index.js --help

更多 SDK

集成面板

开源许可协议

Copyright (2018) 北京华夏春松科技有限公司

Apache License Version 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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.