百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

rivescript-js

> DevOps
开源

JavaScript 的 RiveScript 解释器。RiveScript 是一个用于聊天机器人的脚本语言。

384 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

JavaScript 的 RiveScript 解释器。RiveScript 是一个用于聊天机器人的脚本语言。

RiveScript-JS

INTRODUCTION

This is a RiveScript interpreter library for JavaScript. RiveScript is a scripting language for chatterbots, making it easy to write trigger/response pairs for building up a bot's intelligence.

This library can be used both in a web browser or as a Node module. See the eg/ folder for examples.

NOTICE: CHANGES IN v2.0.0

RiveScript v2.0.0 comes with a massive refactor of the codebase to implement modern Async/Await features all throughout. The refactor now allows features like "storing user variables directly in Redis" or "using asynchronous macros in conditionals"

But it necessarily had to break some backwards compatibility -- slightly! -- by turning previously synchronous functions like reply() into async ones that return Promises like replyAsync() did.

See the Upgrading-v2 document for information on the changes and how to fix your code for the new version.

INSTALLATION

For nodejs and other similar JavaScript engines, you can install this module in your project through npm:

bash
$ npm install rivescript

For the web you can use the unpkg:

xml

The git repository for this project includes ES2015+ source code. For ES5 builds targeting older browsers and Node versions, check the Releases tab. The compiled distribution includes a lib/ directory with ES5 sources to use with node ` tag like usual.

USAGE

…

Interactive shell

The distribution of RiveScript.js includes an interactive command-line shell called riveshell for testing your RiveScript bot. It takes as argument the path (relative or absolute) to the "brain" - the folder that contains your RiveScript documents (.rive files).

  • If you installed RiveScript locally via npm (with npm install rivescript), you can start the shell using npx while in your project folder. Example:
    bash
    $ npx riveshell /path/to/brain
  • If you installed RiveScript globally via npm (with npm install -g rivescript), you can start the shell from anywhere. Example:
    bash
    $ riveshell /path/to/brain
  • If you cloned the repository from GitHub, you can start the shell directly from shell.js at the root of the project, using node. Example using the default brain that comes in the eg/ folder :
    bash
    $ node shell.js /eg/brain

Once inside the shell you can chat with the bot using the RiveScript files in that directory. For simple debugging you can type /eval to run single lines of JavaScript code. See /help for more.

The shell accepts a few command line parameters:

  • --debug: enables verbose debug logging.
  • --watch: watch the reply folder for changes and automatically reload the bot when files are modified.
  • --utf8: enables UTF-8 mode.
  • --case: enable case-sensitive user messages.

DOCUMENTATION

There is generated Markdown and HTML documentation of the modules in the docs folder. The main module is at rivescript.

Also check out the RiveScript Community Wiki for common design patterns and tips & tricks for RiveScript.

EXAMPLES

There are examples available in the eg/ directory of this project on GitHub that show how to interface with a RiveScript bot in a variety of ways--such as through a web browser or a telnet server--and other code snippets and useful tricks.

RIVESCRIPT PLAYGROUND

For testing and sharing RiveScript snippets that use the JavaScript implementation, check out the RiveScript Playground.

It's a JSFiddle style web app for playing with RiveScript in your web browser and sharing code with others.

UTF-8 SUPPORT

Version 1.0.5 adds experimental support for UTF-8 in RiveScript documents. It is disabled by default. Enable it by passing a true value for the utf8 option in the constructor.

By default (without UTF-8 mode on), triggers may only contain basic ASCII characters (no foreign characters), and the user's message is stripped of all characters except letters, numbers and spaces. This means that, for example, you can't capture a user's e-mail address in a RiveScript reply, because of the @ and . characters.

When UTF-8 mode is enabled, these restrictions are lifted. Triggers are only limited to not contain certain metacharacters like the backslash, and the user's message is only stripped of backslashes and HTML angled brackets (to protect from obvious XSS if you use RiveScript in a web application). Additionally, common punctuation characters are stripped out, with the default set being /[.,!?;:]/g. This can be overridden by providing a new RegExp object as the rs.unicodePunctuation attribute. Example:

javascript
// Make a new bot with UTF-8 mode enabled.
var bot = new RiveScript({utf8: true});

// Override the punctuation characters that get stripped from the
// user's message.
bot.unicodePunctuation = new RegExp(/[.,!?;:]/g);

The `` tags in RiveScript will capture the user's "raw" input, so you can write replies to get the user's e-mail address or store foreign characters in their name.

This has so far only been tested when run under Node. When served through a web server, take extra care that your server sends the correct content encoding with the RiveScript source files (Content-Type: text/plain; charset=utf-8).

One caveat to watch out for in UTF-8 mode is that punctuation characters are not removed from a user's message, so if they include commas or exclamation marks it can impact the matching ability of your triggers (you should absolutely not write an explicit punctuation mark on your trigger's side. Triggers should NOT contain symbols like ? or , even with UTF-8 mode enabled, and while that may work right now, a future update will probably rigidly enforce this).

BUILDING

I use npm run scripts to handle various build tasks.

  • npm run build - Compiles the ES2015+ sources from src/ with Babel and outputs them into lib/
  • npm run test - Builds the source with Babel per above, builds the ES2015+ test scripts in test/ and outputs them into test.babel/ and then runs nodeunit on it.
  • npm run dist - Produces a full distributable build. Source is built with Babel and then handed off to webpack and uglify for browser builds.
  • npm run webpack - Creates dist/rivescript.js from the ES2015+ sources directly from src/ (using babel-loader). This command is independent from npm run build and could be run without leaving any ES5 code sitting around.
  • npm run uglify - Minifies dist/rivescript.js to dist/rivescript.min.js
  • npm run clean - Clean up all the build files.

If your local Node version is >= 7 (supports Async/Await), you can run the ES2015+ sources directly without needing to run any npm scripts. For that purpose, I have a Makefile.

  • make setup - sets up the dev environment, installs dependencies, etc.
  • make run - runs shell.js pointed at the example brain. This script runs natively on the ES2015+ sources, no build steps needed.
  • make test - runs nodeunit on the ES2015+ test sources directly without building them as npm run test would.

Error "digital envelope routines::unsupported"

I ran into this on Fedora 37/node 18.7.0; the answer from https://github.com/webpack/webpack/issues/14532 is to:

bash
export NODE_OPTIONS=--openssl-legacy-provider

PUBLISHING

Steps for the npm maintainer of this module:

  1. Increment the version number in package.json and src/rivescript.js
  2. Add a change log notice to Changes.md
  3. Run npm run dist to build the ES5 sources and run unit tests.
  4. Test a local installation from a different directory (npm install ../rivescript-js)
  5. npm login if it's the first time on a new system, and npm publish to publish the module to NPM.
  6. Create compiled zip and tarballs for GitHub releases:
  • Copy git repo to a new folder.
  • rm -rf .git node_modules to remove cruft from the new folder.
  • zip -r rivescript-js-VERSION.zip rivescript-js
  • tar -czvf rivescript-js-VERSION.tar.gz rivescript-js

LICENSE

…

SEE ALSO

The official RiveScript website, http://www.rivescript.com/

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptaiartificial-intelligencebotschatbot

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类DevOps
定价开源

> 相关工具

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理