question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trigger Routing system for direct application interaction

See original GitHub issue

Rivescript 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:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kirslecommented, Nov 23, 2016

Yes it’s possible. Make sure that you’re actually loading from multiple *.rive files. Every call to loadDirectory(), loadFile(), and stream() 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

const RiveScript = require("rivescript");

let bot = new RiveScript();
bot.setSubroutine("my_func", function(rs, args) {
	return "setSubroutine works! Args: " + JSON.stringify(args);
});

bot.loadDirectory(".", function() {
	bot.sortReplies();

	console.log(bot.reply("username", "test func"));
	console.log(bot.reply("username", "macro test"));
});

macro.rive

> object another_func javascript
	return "Macro works! Args are: " + JSON.stringify(args);
< object

test.rive

+ test _
- Testing: <call>my_func <star></call>

+ macro _
- Testing: <call>another_func <star></call>

Output:

Testing: setSubroutine works! Args: ["func"]
Testing: Macro works! Args are: ["test"]
1reaction
kirslecommented, Jun 19, 2016

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/router

There 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. 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Routing the PXI Backplane Trigger Lines to PFI Channels ...
This routing is using a direct connection. Use a X-series device and work with the DAQmx Connect Terminals VI. Specify the source as...
Read more >
CTI, Call Forward or Direct Placement of Trigger
CTI, Call Forward or Direct Placement of Trigger ... version of UCCX, creating an application trigger creates a CTI Route point (including a...
Read more >
Routed events overview - WPF .NET - Microsoft Learn
The routed event then routes to successive parent elements, invoking their event handlers in turn, until it reaches the element tree root. Most ......
Read more >
Universal Routing 8.1 Reference Manual
Genesys software directs more than 100 million interactions every day, ... Note: A routing strategy must also direct interactions of unknown ...
Read more >
What is call routing? Benefits & How it works - Talkdesk
Call distribution phase. ... After the routing system places the calls in the queue, the next phase is to deliver the calls to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found