Added Regular Expression commands, event callbacks with parameters, and more
Added
You can now pass an object containing a RegExp and a callback function to the addCommands() or init() methods. This allows for much more powerful command matching
Example:
var calculateFunction = function(month) { console.log(month); }
var commands = {
// This example will accept any word as the "month"
'calculate :month stats': calculateFunction,
// This example will only accept months which are at the start of a quarter
'calculate :quarter stats': {'regexp': /^calculate (January|April|July|October) stats$/, 'callback': calculateFunction}
}
See https://github.com/TalAter/annyang/tree/master/docs#commands-object for details.
Changed
Some callbacks registered on events will now be fired with parameters.
Example:
annyang.addCallback('resultNoMatch', function(phrases) {
console.log('No command matched. Possible sentences said:');
console.log(phrases);
});
annyang.addCallback('result', function(phrases) {
console.log('Speech recognized. Possible sentences said:');
console.log(phrases);
});
annyang.addCallback('resultMatch', function(said, commandMatched, phrases) {
console.log('Command matched');
console.log('The phrase the user said that matched a command');
console.log(said);
console.log('The command that was matched');
console.log(commandMatched);
console.log('An array of possible alternative phrases the user might\'ve said');
console.log(phrases);
});
See https://github.com/TalAter/annyang/blob/master/docs/#addcallbacktype-callback-context for details.
Changed
In debug mode, adding commands no longer logs a message with the number of commands loaded. Instead it logs individual messages for each command registered along with it's name.
If one of the commands could not be loaded because it wasn't properly formatted, an error message with the name of the command will be logged.
Fixed / Added
Documentation expanded and improved.
Greatly expanded README section on callbacks.
Updated README with all changes made in this version.