AI Zone Admin Forum Add your forum

NEWS: survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

using calls and variables

Hi,  I have two questions about the usage of variables and calls.
Take this example:

// array of “simple” variables
! array vars =  age gender boyfriend girlfriend color location

+ my (@vars) is *
- <set <star1>=<star2>>I’ll remember that your <star1> is <star2>.<call>setvars</call>

> object setvars javascript
< object
// end

How do I send the variables to the call?

I’d like to make this setvars() function show the user that a new variable and value was created.
For example, ‘age = 25’ appears on screen when I input ‘my age is 25’. I’m hoping the answer is simple like setvars(<star1>,<star2>); This would help me achieve things like ‘search google for *’ and the bot opens a window with the results.

The obvious next question is, how do I get a variable from outside the bot?

I’d love for this to be a two way street, where the bot can retrieve the variable from the page. It would know my variable and value before I set it with (@vars) and open up new possibilities. It seems I’m missing two pretty important functions of this bot if this is indeed possible.

Thanks Noah, the creator of rivescript (and everyone since eliza).
You’ve made something super complex so easy to use and play with.


  [ # 1 ]

Objects in RiveScript are functions, themselves. They receive two parameters: `rs` (the reference to the main RiveScript object), and `args` (an array of parameters, or rather, the arguments passed to the <call> separated by spaces).

// array of “simple” variables
! array vars =  age gender boyfriend girlfriend color location

my (@varsis *
- <
set <star1>=<star2>>I’ll remember that your <star1is <star2>.
^ <
call>setvars <star1></call>

object setvars javascript
var name args[0];
value rs.getUservar(rs.currentUser(), name);
name "=" value;

Think of the object as being equivalent to this (which it is, internally):

JSRiveObjects._objects["setvars"= function(rsargs{
var name args[0];
value rs.getUservar(rs.currentUser(), name);
name "=" value;

As for how to get user variables out of the bot from the JavaScript side: use the getUservars() and setUservars() functions.

// Get all variables for a user
var data rs.getUservars("user-id");

// Set a user variable

// Set many variables at once

// or use the `data` var from ^ above and set ALL those
// variables

  [ # 2 ]

Aha! It seems almost too easy.
While I chew on this, thanks again.


  login or register to react