Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including aimlinterpreter with all npm packages installed. Try it out:

var aimlinterpreter = require("aimlinterpreter")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

aimlinterpreter v0.1.7

Module to interpret AIML files in node.js


AIML Interpreter written in node.js

AIMLInterpreter is a module that allows you to parse AIML files and to find the correct answer to a given message.


$ npm install aimlinterpreter


With new AIMLInterpreter(botAttributes) one can create a new interpreter object. botAttributes is an JSON-Object that can contain attributes of the bot one wants to use in AIML files, e.g. ({name: "Bot", age:"42"}).
This object has a function called loadAIMLFilesIntoArray(fileArray) which receives an array of AIML files. This function loads the AIML file into memory.
Furthermore, the object has a function called findAnswerInLoadedAIMLFiles(clientInput, cb) which receives a message and a callback. The callback is called when an answer was found. The callback of findAnswerInLoadedAIMLFiles should look like this: callback(result, wildCardArray, input). Result is the answer from the AIML file and wildCardArray stores the values of all wildcardInputs passed previously from the client. The original input which triggered the answer is given back via input.


AIMLInterpreter = require('./AIMLInterpreter');
var aimlInterpreter = new AIMLInterpreter({name:'WireInterpreter', age:'42'});

var callback = function(answer, wildCardArray, input){ console.log(answer + ' | ' + wildCardArray + ' | ' + input); };

aimlInterpreter.findAnswerInLoadedAIMLFiles('What is your name?', callback); aimlInterpreter.findAnswerInLoadedAIMLFiles('My name is Ben.', callback); aimlInterpreter.findAnswerInLoadedAIMLFiles('What is my name?', callback);

Supported AIML tags:
<bot name="NAME"/>
<get name="NAME"/>
<set name="NAME">TEXT</set>
<srai>PATTERN TEXT</srai>
<condition name="NAME" value="VALUE">TEXT</condition>
<condition><li name="NAME" value="VALUE">TEXT</li><li name="NAME" value="VALUE">TEXT</li><li>TEXT</li></condition>
<condition name="NAME"><li value="VALUE">TEXT</li><li value="VALUE">TEXT</li><li>TEXT</li></condition>


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free