Trigger Routing system for direct application interaction
See original GitHub issueRivescript is currently very tightly coupled to the macros to give the scripts extra logical functions. I would like if Rivescript is more integrated in the programming side of an application. Rather than emulating logical operations.
Currently i have to use <call> tag for all of the triggers, to let the application generate the responses.
+ trigger 1
- <call>Class method <star1></call>
+ trigger 2
- <call>Class method <star1> <star2></call>
+ trigger 3
- <call>Class method <star1> <star2> <star3></call>
...
Also the macros restrict alot of possibilities for interconnecting classes and methods of an application.
i want trigger to work like a router system of a webapp, that maps to an external “thinks” class/method of the language used.
Example Project directory structure:
Project Bot -
- triggers (holds the .rive documents with route like triggers that map to "thinks" class's and method's)
- thinks (is like the Controllers in a webapp, that holds all the class's and method's that performs all logic to return intelligent responses)
- memories (is like the Models in a webapp that handles storage of user sessions and conversations and logical data sets to form responses)
- bot.js (initializes the bot)
- abilities.txt (abilities of what the bot can do like, greeting, math, play media, web search, date/time, etc...)
Example of common Webapp routing
route("/route", Class.method)
Example: trigger routing in ./triggers/math.rive that maps to methods in ./thinks/math.js parsed * and # variable arguments and RS object are accessable via mapped methods to the ./thinks/math.js module Example: ./triggers/math.rive
[*] what is # * [by|to] # => Math.do()
[*] * # [to|from] # => Math.do()
Example user messages: what is 23 divided by 5 what is 174 added to 257 subtract 47 from 92 add 374 to 539
// the "thinks" directory holds the class/method module that handles the "thinking process".
// Example: ./thinks/math.js
var Brain = require("./brain"),
mathMemory = require("../memories/math"),
User = require("./session"), // user session database handler
//...etc...
Other example: ./triggers/greetings.rive mapped to ./thinks/greetings.js
(hello|hi|hey|howdy|hola|hai|yo) * => Greetings.check()
// Example: ./thinks/greetings.js
var Brain = require("./brain"),
User = require("./session");
var Greetings = {
responses: function() {
greets: ["Hi there :)", "Hello <user>", "Hey"],
hasGreeted: ["We already greeted today", "You like to greet :)"],
byes: ["bye", "goodbye", "farewell <user>"]
},
check: function(){
if(User.hasGreeted){
return Brain.respond(this.responses.hasGreeted)
}else{
return Brain.respond(this.responses.greets)
}
},
//...
}
To give rivescript direct access to the programming language, rather than via macros. Having “thinks” controllers that interconnect with other “thinks” controllers to generate a well processed response. Able to do more complex things. Being able to handle multiple route commands like “get my last note then play a one direction song”. The bot will get the last note and play a random song from one direction
This kind of chatbot system will be awesome!
Can you make this “trigger routing” system please ?
[*] trigger * # (a|b|c) [a|b|c] => Obj.method()
Also in the Golang version, if this type of trigger routing is used, then there is no need to spawn multiple goroutines that macros do There must be a direct way to access external Classes/Objects/methods to the programming language itself
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (5 by maintainers)
Top GitHub Comments
Yes it’s possible. Make sure that you’re actually loading from multiple
*.rive
files. Every call toloadDirectory()
,loadFile()
, andstream()
is additive so all input files are merged into memory, and the order of most things within those files doesn’t matter because the bot will have all the information it needs at reply time.I made this set of example files:
index.js
macro.rive
test.rive
Output:
I thought the idea was interesting so I added a new example to the
eg/
directory that implements my above code ideas: https://github.com/aichaos/rivescript-js/tree/master/eg/routerThere were a couple errors in my example code earlier (like looping through the triggers, and an unreferenced
args
variable), but those are fixed in my working example. 😉