I'm currently using Node to make my first bot, but I'm a little bit confused as to how I can make this into reality. The question is, what is the best pattern and name of the pattern I should use for this kind of stuff?
Basically, a person can listen to a subject and the speaker.
var test = person("ask_name","hallo person you are special");
console.log(test); // should return thanks!
var test = person("ask_name","hallo person you are dumb as the bird");
console.log(test); // should return i hate you!
function person(ability, body) {
console.log(ability,body);
var ability_name = "ability_" + ability;
console.log(ability_name,typeof ability_name); // ignore all of this, trying something
if (typeof ability_name) {};
// ability list array
var ability = [];
// Search for ability
// not done
var say_bad = function() {
this.listen_subject = 'ask_name';
this.listen_body = 'you are dumb';
return "i hate you!"
}
var say_good = function() {
this.listen_subject = 'ask_name';
this.listen_body = 'you are special';
return "thanks!"
}
}
Sorry, for not completing the code but this is the furthest I can go.
If you're talking about the conversation logic, chain of responsibility seems like the way to go. That being said, that's only suitable for implementing a response tree. You may have different needs.
The way that could work is: All nodes in the logic tree would have this method;
bool consider(utterence, history);
This method would return true if the node, or one of its subnodes has handled the situation.
I would implement a couple of topic detectors and a generic "I can't come up with a good answer", as well as a bunch of specialized responders.
The logic would be something like:
(weatherDetector considers utterence, history) (determines that topic is weather) (passes on to chain of objects that handle weather conversations)
or
(weatherDetector considers utterence, history) (determines that topic is NOT weather) (passes on to next in chain of topic detectors) (genericFunnyResponder considers utterence, history) (picks a random quirky answer)