{"id":13407503,"url":"https://github.com/aichaos/rivescript-js","last_synced_at":"2026-01-11T13:49:41.509Z","repository":{"id":4152658,"uuid":"5266682","full_name":"aichaos/rivescript-js","owner":"aichaos","description":" A RiveScript interpreter for JavaScript. RiveScript is a scripting language for chatterbots.","archived":false,"fork":false,"pushed_at":"2023-02-28T00:24:14.000Z","size":2351,"stargazers_count":378,"open_issues_count":63,"forks_count":145,"subscribers_count":29,"default_branch":"master","last_synced_at":"2024-10-07T09:05:55.744Z","etag":null,"topics":["ai","artificial-intelligence","bots","chatbot","chatbots","rivescript"],"latest_commit_sha":null,"homepage":"https://www.rivescript.com/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aichaos.png","metadata":{"files":{"readme":"README.md","changelog":"Changes.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2012-08-02T00:44:01.000Z","updated_at":"2024-10-02T15:05:02.000Z","dependencies_parsed_at":"2023-07-05T17:15:20.987Z","dependency_job_id":null,"html_url":"https://github.com/aichaos/rivescript-js","commit_stats":{"total_commits":325,"total_committers":33,"mean_commits":9.848484848484848,"dds":0.4553846153846154,"last_synced_commit":"c4093756c7b29e9a153f9e6a4f6da59361576635"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aichaos%2Frivescript-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aichaos%2Frivescript-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aichaos%2Frivescript-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aichaos%2Frivescript-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aichaos","download_url":"https://codeload.github.com/aichaos/rivescript-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243447055,"owners_count":20292448,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","artificial-intelligence","bots","chatbot","chatbots","rivescript"],"created_at":"2024-07-30T20:00:41.235Z","updated_at":"2025-03-14T12:31:07.271Z","avatar_url":"https://github.com/aichaos.png","language":"JavaScript","readme":"# RiveScript-JS\n\n[![Build Status](https://travis-ci.org/aichaos/rivescript-js.svg?branch=master)](https://travis-ci.org/aichaos/rivescript-js)\n\n## INTRODUCTION\n\nThis is a RiveScript interpreter library for JavaScript. RiveScript is a\nscripting language for chatterbots, making it easy to write trigger/response\npairs for building up a bot's intelligence.\n\nThis library can be used both in a web browser or as a Node module.\nSee the `eg/` folder for examples.\n\n## NOTICE: CHANGES IN v2.0.0\n\nRiveScript v2.0.0 comes with a **massive** refactor of the codebase to\nimplement modern Async/Await features all throughout. The refactor now\nallows features like \"storing user variables directly in Redis\" or\n\"using asynchronous macros in conditionals\"\n\nBut it necessarily had to break some backwards compatibility -- slightly!\n-- by turning previously synchronous functions like `reply()` into\nasync ones that return Promises like `replyAsync()` did.\n\nSee the [Upgrading-v2](https://github.com/aichaos/rivescript-js/blob/master/Upgrading-v2.md) document for information on the changes\nand how to fix your code for the new version.\n\n## INSTALLATION\n\nFor nodejs and other similar JavaScript engines, you can install this module in your project through npm:\n\n```bash\n$ npm install rivescript\n```\n\nFor the web you can use the unpkg:\n\n```html\n\u003cscript src=\"https://unpkg.com/rivescript@latest/dist/rivescript.min.js\"\u003e\u003c/script\u003e\n```\n\nThe git repository for this project includes ES2015+ source code. For\nES5 builds targeting older browsers and Node versions, check the\n[Releases](https://github.com/aichaos/rivescript-js/releases) tab. The compiled\ndistribution includes a `lib/` directory with ES5 sources to use with\nnode \u003c= 6, and a `dist/` directory containing a \"browserified\" script that can be\nused on a web page.\n\nTo use on the web, just load `dist/rivescript.min.js` with a `\u003cscript\u003e` tag\nlike usual.\n\n## USAGE\n\n```javascript\nvar bot = new RiveScript();\n\n// Load a directory full of RiveScript documents (.rive files). This is for\n// Node.JS only: it doesn't work on the web!\nbot.loadDirectory(\"brain\").then(loading_done).catch(loading_error);\n\n// Load an individual file.\nbot.loadFile(\"brain/testsuite.rive\").then(loading_done).catch(loading_error);\n\n// Load a list of files all at once (the best alternative to loadDirectory\n// for the web!)\nbot.loadFile([\n  \"brain/begin.rive\",\n  \"brain/admin.rive\",\n  \"brain/clients.rive\"\n]).then(loading_done).catch(loading_error);\n\n// All file loading operations are asynchronous, so you need handlers\n// to catch when they've finished. If you use loadDirectory (or loadFile\n// with multiple file names), the success function is called only when ALL\n// the files have finished loading.\nfunction loading_done() {\n  console.log(\"Bot has finished loading!\");\n\n  // Now the replies must be sorted!\n  bot.sortReplies();\n\n  // And now we're free to get a reply from the brain!\n\n  // RiveScript remembers user data by their username and can tell\n  // multiple users apart.\n  let username = \"local-user\";\n\n  // NOTE: the API has changed in v2.0.0 and returns a Promise now.\n  bot.reply(username, \"Hello, bot!\").then(function(reply) {\n    console.log(\"The bot says: \" + reply);\n  });\n}\n\n// It's good to catch errors too!\nfunction loading_error(error, filename, lineno) {\n  console.log(\"Error when loading files: \" + error);\n}\n```\n\n### Interactive shell\nThe 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).\n- If you installed RiveScript locally via npm (with `npm install rivescript`), you can start the shell using **npx** while in your project folder. Example:\n    ```bash\n    $ npx riveshell /path/to/brain\n    ```\n- If you installed RiveScript globally via npm (with `npm install -g rivescript`), you can start the shell from anywhere. Example:\n    ```bash\n    $ riveshell /path/to/brain\n    ```\n- 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 :\n    ```bash\n    $ node shell.js /eg/brain\n    ```\n\nOnce inside the shell you can chat with the bot using the RiveScript files in\nthat directory. For simple debugging you can type `/eval` to run single lines\nof JavaScript code. See `/help` for more.\n\nThe shell accepts a few command line parameters:\n\n* `--debug`: enables verbose debug logging.\n* `--watch`: watch the reply folder for changes and automatically reload the\n  bot when files are modified.\n* `--utf8`: enables UTF-8 mode.\n* `--case`: enable case-sensitive user messages.\n\n\n## DOCUMENTATION\n\nThere is generated Markdown and HTML documentation of the modules in the\n[docs](https://github.com/aichaos/rivescript-js/tree/master/docs) folder.\nThe main module is at [rivescript](https://github.com/aichaos/rivescript-js/blob/master/docs/rivescript.md).\n\nAlso check out the [**RiveScript Community Wiki**](https://github.com/aichaos/rivescript/wiki)\nfor common design patterns and tips \u0026 tricks for RiveScript.\n\n## EXAMPLES\n\nThere are examples available in the\n[eg/](https://github.com/aichaos/rivescript-js/tree/master/eg) directory of\nthis project on GitHub that show how to interface with a RiveScript bot in\na variety of ways--such as through a web browser or a telnet server--and other\ncode snippets and useful tricks.\n\n## RIVESCRIPT PLAYGROUND\n\nFor testing and sharing RiveScript snippets that use the JavaScript\nimplementation, check out the [RiveScript Playground](https://play.rivescript.com/).\n\nIt's a JSFiddle style web app for playing with RiveScript in your web browser\nand sharing code with others.\n\n\u003chttps://play.rivescript.com/\u003e\n\n## UTF-8 SUPPORT\n\nVersion 1.0.5 adds **experimental** support for UTF-8 in RiveScript documents.\nIt is disabled by default. Enable it by passing a `true` value for the `utf8`\noption in the constructor.\n\nBy default (without UTF-8 mode on), triggers may only contain basic ASCII\ncharacters (no foreign characters), and the user's message is stripped of all\ncharacters except letters, numbers and spaces. This means that, for example,\nyou can't capture a user's e-mail address in a RiveScript reply, because of the\n@ and . characters.\n\nWhen UTF-8 mode is enabled, these restrictions are lifted. Triggers are only\nlimited to not contain certain metacharacters like the backslash, and the user's\nmessage is only stripped of backslashes and HTML angled brackets (to protect\nfrom obvious XSS if you use RiveScript in a web application). Additionally,\ncommon punctuation characters are stripped out, with the default set being\n`/[.,!?;:]/g`. This can be overridden by providing a new `RegExp` object as the\n`rs.unicodePunctuation` attribute. Example:\n\n```javascript\n// Make a new bot with UTF-8 mode enabled.\nvar bot = new RiveScript({utf8: true});\n\n// Override the punctuation characters that get stripped from the\n// user's message.\nbot.unicodePunctuation = new RegExp(/[.,!?;:]/g);\n```\n\nThe `\u003cstar\u003e` tags in RiveScript will capture the user's \"raw\" input, so you\ncan write replies to get the user's e-mail address or store foreign characters\nin their name.\n\nThis has so far only been tested when run under Node. When served through a\nweb server, take extra care that your server sends the correct content encoding\nwith the RiveScript source files (`Content-Type: text/plain; charset=utf-8`).\n\nOne caveat to watch out for in UTF-8 mode is that punctuation characters are not\nremoved from a user's message, so if they include commas or exclamation marks\nit can impact the matching ability of your triggers (you should *absolutely\nnot* write an explicit punctuation mark on your trigger's side. Triggers should\nNOT contain symbols like `?` or `,` even with UTF-8 mode enabled, and while that\nmay work right now, a future update will probably rigidly enforce this).\n\n## BUILDING\n\nI use npm run scripts to handle various build tasks.\n\n* `npm run build` - Compiles the ES2015+ sources from `src/` with Babel and\n  outputs them into `lib/`\n* `npm run test` - Builds the source with Babel per above, builds the ES2015+\n  test scripts in `test/` and outputs them into `test.babel/` and then runs\n  `nodeunit` on it.\n* `npm run dist` - Produces a full distributable build. Source is built with\n  Babel and then handed off to webpack and uglify for browser builds.\n* `npm run webpack` - Creates `dist/rivescript.js` from the ES2015+ sources\n  directly from `src/` (using `babel-loader`). This command is independent from\n  `npm run build` and could be run without leaving any ES5 code sitting around.\n* `npm run uglify` - Minifies `dist/rivescript.js` to `dist/rivescript.min.js`\n* `npm run clean` - Clean up all the build files.\n\nIf your local Node version is \u003e= 7 (supports Async/Await), you can run the\nES2015+ sources directly without needing to run any npm scripts. For that\npurpose, I have a Makefile.\n\n* `make setup` - sets up the dev environment, installs dependencies, etc.\n* `make run` - runs `shell.js` pointed at the example brain. This script runs\n  natively on the ES2015+ sources, no build steps needed.\n* `make test` - runs `nodeunit` on the ES2015+ test sources directly without\n  building them as `npm run test` would.\n\n### Error \"digital envelope routines::unsupported\"\n\nI ran into this on Fedora 37/node 18.7.0; the answer from https://github.com/webpack/webpack/issues/14532 is to:\n\n```bash\nexport NODE_OPTIONS=--openssl-legacy-provider\n```\n\n## PUBLISHING\n\nSteps for the npm maintainer of this module:\n\n1. Increment the version number in `package.json` and `src/rivescript.js`\n2. Add a change log notice to `Changes.md`\n3. Run `npm run dist` to build the ES5 sources and run unit tests.\n4. Test a local installation from a different directory\n   (`npm install ../rivescript-js`)\n5. `npm login` if it's the first time on a new system, and `npm publish` to\n   publish the module to NPM.\n6. Create compiled zip and tarballs for GitHub releases:\n  * Copy git repo to a new folder.\n  * `rm -rf .git node_modules` to remove cruft from the new folder.\n  * `zip -r rivescript-js-VERSION.zip rivescript-js`\n  * `tar -czvf rivescript-js-VERSION.tar.gz rivescript-js`\n\n## LICENSE\n\n```\nThe MIT License (MIT)\n\nCopyright (c) 2020 Noah Petherbridge\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n\n## SEE ALSO\n\nThe official RiveScript website, http://www.rivescript.com/\n","funding_links":[],"categories":["Tools","JavaScript"],"sub_categories":["Libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faichaos%2Frivescript-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faichaos%2Frivescript-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faichaos%2Frivescript-js/lists"}