Hi,
I’ve been trying to create a server version of RiveScript that will allow multi user / multi sessions, but it would seem that RS does not support this. As a workaround, I’ve ame up with this approach.
Everytime a session is created, you call the new_instance procedure.
#!/usr/bin/perl
use strict;
use warnings;
use RiveScript;
my %HASH;
$HASH{session1} = &new;_instance;
$HASH{session2} = &new;_instance;
my $message = "hello there";
my $reply = $HASH{session1}->reply("user", $message);
print $reply;
sub new_instance
{
my $rs = RiveScript->new();
$rs->loadDirectory("./eliza");
$rs->sortReplies();
return $rs;
}
There are two major downsides though. Everytime a new instance is loaded, it will read all the .rs files again. If you have a big bot, this could slow things down due to an I/O hit. Second problem is the amount of memory used, since each instance would effectively be a ful copy (all .rs files, session state, the works) in it’s own variable.
For the next release of RiveScript, it would be good to have an approach where the session state can be defined as an input variable to the reply procedure, so the bot can maintain multi user session state natively.