Using AIML files with Microsoft Bot Framework

A few days ago, I was pitching Bot Framework to an interested party, when a question came up: “Does the Bot Framework support AIML files? We have a lot of them and we are wondering whether we could use them”. Honestly, I didn’t have a clue what AIML is, so I decided to run a quick search.

Turns out that AIML stands for Artificial Intelligence Markup Language and, as Wikipedia nicely mentions it, it is an XML dialect for creating natural language software agents. AIML was used to power Alice Bot back in 1995 (this was one of the first chat bots available to the public). Moreover, AIML powered a discussion with Captain Kirk of Enterprise (ho there, Star Trek fans!). Alice AIML files are open source, you can find them here.


Let’s take a look at how an AIML file is  written:

  <pattern>WHAT IS YOUR NAME</pattern>
  <template>My name is Michael N.S Evanious.</template>

Pattern is the question asked by the user whereas template is the answer to be responded by the chat bot. So, with input “What is your name”, bot will respond with “My name is Michael N.S Evanious”. As you can imagine, pattern string is case-insensitive. You can also use a pattern like “WHAT IS YOUR *”, in this case the bot will much any input in the wildcard position, like “what is your age”,”what is your shoe number” etc. AIML files can also operate as base for a finite state machine via specific XML tags. They also can contain variables, such as ones provided by the bot or by the user herself. To find more about AIML, you should check ALICE AIML Primer and ALICE documentation.

Parsing AIML on Node.js

If you’re using Bot Builder Node.js SDK, there is a really nice and easy to use npm package that you can use to parse AIML files, called aiml.js, located here on GitHub. Just “npm install aimlinterpreter”. Check how easy it is to use via a simple Promise function:

const AIMLInterpreter = require('AIMLInterpreter');
const builder = require('botbuilder');

const aimlInterpreter = new AIMLInterpreter({ name: 'John', age: '25' });

const aimlPromise = function (question) {
    return new Promise(function (resolve, reject) {
        aimlInterpreter.findAnswerInLoadedAIMLFiles(question, function (answer, wildCardArray, input) {
            return resolve(answer);
//should also handle reject!!! this is demo code only :)

const connector = new builder.ConsoleConnector().listen();
const bot = new builder.UniversalBot(connector);
bot.dialog('/', [
    function (session) {
        builder.Prompts.text(session, 'Hi! Ask me something...');
    function (session, results) {
        aimlPromise(results.response).then(res =&gt; session.send(`Response is ${res}`));

You can also modify the last function in the array to work with async/await JavaScript keywords:

    async function (session, results) {
        let res = await aimlPromise(results.response);

Easy, right?

If you’re using C# Bot Framework SDK, check this project here, should help you roll.

Hope this helps,


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s