RIVESCRIPT(1p)

πŸ“¦
version 2.0.4 Β· 2 versions
  • 2.0.4 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 2.0.3 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– RIVESCRIPT πŸ’–

okay bestie, so this is the manual page for rivescript β€” a command line frontend to the Perl RiveScript interpreter β€” and it lives in the User Contributed Perl Documentation corner of your system, section 1p. pull up a chair, we're gonna go through it together 🫢


✨ NAME ✨

rivescript β€” a command line frontend to the Perl RiveScript interpreter. that's it, that's the whole vibe πŸ’…


🌸 SYNOPSIS 🌸

$ rivescript [options] [path to RiveScript documents]

πŸ¦‹ DESCRIPTION πŸ¦‹

so this is a command line front-end to the RiveScript interpreter, and honestly? she's iconic. this script obsoletes the old rsdemo, and it can also be used non-interactively by third party programs. which is a fancy way of saying: it supports a whole variety of input/output and session handling methods, so you can slot her into whatever setup you've got going on ✨

and if you're like "bestie I don't have a path to give you" β€” no worries. 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. classic. a legend. πŸ’–


πŸ‘‘ OPTIONS πŸ‘‘

  • --debug, -d β€” turns on debug mode. this prints ALL the debug data from RiveScript straight to your terminal. and if you'd rather it log to a file instead? use the --log option instead of --debug, not me having opinions πŸ’…
  • --log FILE β€” enables debug mode and prints the debug output to FILE instead of to your terminal. it's giving "I want the receipts, just not on my screen" πŸ“
  • --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 the details, iykyk. πŸ”₯
  • --data JSON_DATA β€” when you're using the --json option, you can provide the JSON input message as a command line argument with the --data option. if you don't provide it, then the JSON data will be read from standard input instead. so this option is helpful 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, bestie πŸŽ€
  • --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. she's hosting, periodt 🌐
  • --strict, --nostrict β€” enables strict mode for the RiveScript parser. it's enabled by default, so use --nostrict to disable it. strict mode prevents the parser from continuing when it finds a syntax error in the RiveScript documents. so basically she stops and goes "no ❀️" instead of powering through the mess.
  • --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. don't go infinite on her, okay? πŸŒ€
  • --utf8, -u β€” use the UTF-8 option in RiveScript. this allows triggers to contain foreign characters and relaxes the filtering of user messages. this is not enabled by default! so if you want the global energy, you gotta opt in 🌍✨
  • --help β€” displays this documentation in your terminal. hi, you are here πŸ“

🌈 USAGE 🌈

πŸ’¬ Interactive Mode πŸ’¬

this is the default mode used when you run rivescript without specifying another mode. it behaves similarly to the old rsdemo script and lets you chat one-on-one with your RiveScript bot. just you and her. main character energy fr fr πŸ’–

and like, 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. very structured. very demure. ✨

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). she's keeping notes, okay? πŸ““

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). bestie, she's handing your data back to you so you don't lose it πŸ’Ύ

🌸 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. lowkey the chillest way to do it.

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. and heads up β€” you can't have a stateful session using this method. it's giving "blink and she's gone" πŸ’€

πŸŽ€ End of Message πŸŽ€

there are two ways you can use the JSON mode: "fire and forget," or keep a stateful session open. pick your fighter ✨

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. one message, one reply, done, no strings attached πŸ¦‹

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. she says it back. communication. it's a whole thing πŸ’…

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. recycling queen 🌈

🌐 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). she's branching out, networking era πŸ”₯

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". no fire-and-forget here, she wants the full conversation 🫢

⚠️ and 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. so like, don't ghost her for more than 20 lines, bestie. she WILL hang up 😭

πŸ”— SEE ALSO πŸ”—

RiveScript, the Perl RiveScript interpreter. that's her. that's the one. go look πŸ‘€


πŸ’œ 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

and that's the whole page, bestie πŸ’– this one's from perl v5.36.0, dated 2022-12-23, and it lives under RIVESCRIPT(1p) β€” go forth and chat with your bot, you've got this πŸŒŸπŸ‘‘πŸ¦‹

πŸ“¦ where this page comes from