AI Zone Admin Forum Add your forum

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

execute action with rivescript
 
 

Is it possible the let chatbot perform an action based on certain results he returns?

I was thinking of puttng a JSON string into the rive file:

+ (hello|hi|hey|howdy|hola|hai|yo[*]
{"id":1"txt""How are you?"

And then parse it back into a JS object.

var reply rs.reply("soandso"text);
replyJSON.parse(reply); 

Then according to the id it executes an action that I want. Is there a better way to do it (with rivescript or maybe with another language)?

 

 
  [ # 1 ]

I’ve heard of people coming up with their own OOB (“out of band”) solutions for RiveScript, one of which had them writing code like this:

// This line is put in one time per file at the top of each file
local concat newline

+ (hello|hi|hey|howdy|hola|hai|yo[*]
Hi there!
imagehello.png
id1
whateverdata 

And then you could parse it back out, like

var reply rs.reply(usernamemessage);
var 
lines reply.split("\n");
var 
data {};
for (var 
1lines.lengthi++) {
    
var parts lines[i].split(":");
    
data[parts[0].trim()parts[1].trim();

The first line in the RS makes it so every ^continue command gets put in with a “\n” line break in front, and then the JS code splits the result by line breaks and parses all the extra metadata lines into an object.

 

 
  login or register to react