I am creating a (nodejs) chat bot, that reads messages and should act upon them. Due to its nature, the easy way to select which command should be executed is by multiple if else statements that execute a directive (a command), to which I pass a callback function.
Is there a better way? Any way to use a yaml or any other type of xml like config file to assign the route/controller?
Here is a code example. Full project here
var main = require('./Directives/default');
if (workingMsgBody.indexOf("help") > -1) {
main.help(function(data) {
outputChannel.sendOutput(msg.medium, data);
});
//multiple elseif statements follow
module.exports.help = function(callback) {
callback('blah blah');
}
Aucun commentaire:
Enregistrer un commentaire