rivescript - A command line frontend to the Perl RiveScript interpreter.

- NAME
- SYNOPSIS
- DESCRIPTION
- OPTIONS
- USAGE

- Interactive Mode
- JSON Mode

- Standard Input or Data
- End of Message

- TCP Mode

- SEE ALSO
- AUTHOR
- LICENSE

# NAME

rivescript - A command line frontend to the Perl RiveScript interpreter.

# SYNOPSIS

      $ rivescript [options] [path to RiveScript documents]

# DESCRIPTION

This is a command line front-end to the RiveScript interpreter. This script obsoletes the old `rsdemo`, and can also be used non-interactively by third party programs. To that end, it supports a variety of input/output and session handling methods.

If no RiveScript document path is given, it will default to the example brain that ships with the RiveScript module, which is based on the Eliza bot.

# OPTIONS

--debug, -d

  Enables debug mode. This will print all debug data from RiveScript to your terminal. If you'd like it to log to a file instead, use the `--log` option instead of `--debug`.

--log FILE

  Enables debug mode and prints the debug output to `FILE` instead of to your terminal.

--json, -j

  Runs `rivescript` in JSON mode, for running the script in a non-interactive way (for example, to use RiveScript in a programming language that doesn't have a native RiveScript library). See JSON Mode for details.

--data JSON_DATA

  When using the `--json` option, you can provide the JSON input message as a command line argument with the `--data` option. If not provided, then the JSON data will be read from standard input instead. This option is helpful, therefore, if you don't want to open a two-way pipe, but rather pass the message as a command line argument and just read the response from standard output. See JSON Mode for more details.

--listen, -l [ADDRESS:]PORT

  Runs `rivescript` in TCP mode, for running the script as a server daemon. If an address isn't specified, it will bind to `localhost`. See TCP Mode for details.

--strict, --nostrict

  Enables strict mode for the RiveScript parser. It's enabled by default, use `--nostrict` to disable it. Strict mode prevents the parser from continuing when it finds a syntax error in the RiveScript documents.

--depth=50

  Override the default recursion depth limit. This controls how many times RiveScript will recursively follow redirects to other replies. The default is `50`.

--help

  Displays this documentation in your terminal.

# USAGE

## Interactive Mode

This is the default mode used when you run `rivescript` without specifying another mode. This mode behaves similarly to the old `rsdemo` script and lets you chat one-on-one with your RiveScript bot.

This mode can be used to test your RiveScript bot. Example:

      $ rivescript /path/to/rs/files

## JSON Mode

This mode should be used when calling from a third party program. In this mode, data that enters and leaves the script are encoded in JSON.

Example:

      $ rivescript --json /path/to/rs/files

The format for incoming JSON data is as follows:

      {
        "username": "localuser",
        "message":  "Hello bot!",
        "vars": {
          "name": "Aiden"
        }
      }

Here, `username` is a unique name for the user, `message` is their message to the bot, and `vars` is a hash of any user variables your program might be keeping track of (such as the user's name and age).

The response from `rivescript` will look like the following:

      {
        "status": "ok",
        "reply":  "Hello, human!",
        "vars": {
          "name": "Aiden"
        }
      }

Here, `status` will be `"ok"` or `"error"`, `reply` is the bot's response to your message, and `vars` is a hash of the current variables for the user (so that your program can save them somewhere).

### Standard Input or Data

By default, JSON mode will read from standard input to receive your JSON message. As an alternative to this, you can provide the `--data` option to `rivescript` to present the incoming JSON data as a command line argument.

This may be helpful if you don't want to open a two-way pipe to `rivescript`, and would rather pass your input as a command line argument and simply read the response from standard output.

Example:

      $ rivescript --json --data '{"username": "localuser", "message": "hello" }' \
        /path/to/rs/files

This will cause `rivescript` to print its JSON response to standard output and exit. You can't have a stateful session using this method.

### End of Message

There are two ways you can use the JSON mode: "fire and forget," or keep a stateful session open.

In "fire and forget," you open the program, print your JSON input and send the EOF signal, and then `rivescript` sends you the JSON response and exits.

In a stateful session mode, you must send the text `__END__` on a line by itself after you finish sending your JSON data. Then `rivescript` will process it, return its JSON response and then also say `__END__` at the end.

Example:

      {
        "username": "localuser",
        "message": "Hello bot!",
        "vars": {}
      }
      __END__

And the response:

      {
        "status": "ok",
        "reply": "Hello, human!",
        "vars": {}
      }
      __END__

This way you can reuse the same pipe to send and receive multiple messages.

## TCP Mode

TCP Mode will make `rivescript` listen on a TCP socket for incoming connections. This way you can connect to it from a different program (for example, a CGI script or a program written in a different language).

Example:

      $ rivescript --listen localhost:2001

TCP Mode behaves similarly to JSON Mode; the biggest difference is that it will read and write using a TCP socket instead of standard input and output. Unlike JSON Mode, however, TCP Mode always runs in a stateful way (the JSON messages must end with the text "`__END__`" on a line by itself). See End of Message.

If the `__END__` line isn't found after 20 lines of text are read from the client, it will give up and send the client an error message (encoded in JSON) and disconnect it.

# SEE ALSO

RiveScript, the Perl RiveScript interpreter.

# AUTHOR

Noah Petherbridge, http://www.kirsle.net

# LICENSE

      RiveScript - Rendering Intelligence Very Easily
      Copyright (C) 2012 Noah Petherbridge

      This program is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published by
      the Free Software Foundation; either version 2 of the License, or
      (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA