I learned how to do this from the bluemonday-js project on GitHub. See their README for the background of how this works.
This module should be available via npm if you're brave enough to try it:
npm install rivescript-rsgb
There are a couple of differences in the API to this module versus the native
GoDoc for the RiveScript
Go module for API usage. Briefly, most of the functions you're used to now
begin with a capital letter, as that's the convention for exported functions in
Go. For example,
SetUservar() rather than
Also, only the exported functions of the RiveScript Go module are available to
bot.Debug = true to turn on debug mode.
Instead, use the following functions to configure the bot:
var bot = ; // The constructor takes no parametersbot; // Activate debug modebot; // Enable UTF-8 supportbot; // Change recursion depthbot; // Strict syntax parsing (it's true by default)// To override the Unicode punctuation symbols call this function and pass it// the *string literal* regexp (not a Regexp object; these don't translate well// into Go)bot
var RiveScript =fs = ;var bot = ;// No system calls are supported for gopherjs so LoadDirectory/LoadFile won't// work... we have to use Stream() to input all the RiveScript documents.bot;bot;var username = "local-user";var reply = bot;console;
These steps assume you already have a working Golang development environment.
First, install gopherjs and the source to rivescript-go:
$ go get -u github.com/gopherjs/gopherjs$ go get github.com/aichaos/rivescript-go
Grunt commands (needs
npm install -g grunt-cli):
grunt test: Run the unit tests
grunt clean: Removes the
System calls aren't supported by gopherjs, so the RiveScript module can't access
files from disk. This means
LoadDirectory() calls will fail.
their contents in via
Object macros aren't supported at this time but may be investigated in the future.
The MIT License (MIT) Copyright (c) 2015 Noah Petherbridge Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The official RiveScript website, http://www.rivescript.com/