-
Notifications
You must be signed in to change notification settings - Fork 181
/
helloWorld.js
44 lines (31 loc) · 1.11 KB
/
helloWorld.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(function () {
"use strict";
var nools = require("../index");
var Message = function (message) {
this.message = message;
};
var flow = nools.flow("Hello World", function (flow) {
//find any message that starts with hello
this.rule("Hello", [Message, "m", "m.message =~ /^hello(\\s*world)?$/"], function (facts) {
facts.m.message = facts.m.message + " goodbye";
this.modify(facts.m);
});
//find all messages then end in goodbye
this.rule("Goodbye", [Message, "m", "m.message =~ /.*goodbye$/"], function (facts) {
console.log(facts.m.message);
});
});
var session = flow.getSession();
//assert your different messages
session.assert(new Message("goodbye"));
session.assert(new Message("hello"));
session.assert(new Message("hello world"));
session.match();
//same as above getSession will assert the passed in objects
var session2 = flow.getSession(
new Message("goodbye"),
new Message("hello"),
new Message("hello world")
);
session2.match();
})();