in Development

Artificial Intelligence, bot and Live Messenger Add-In

In my company we use the Windows Live Messenger as a powerful communication tool between all the employees; the problem is that this “instant availability” can be misused. What I mean is that since it’s easier to write a question in a chat window than write a mail or make a phone call, you trend to ask in the messenger before any other option. The result is that I’m being asked lot of times during the day for questions that could be checked in our Intranet or any other place. A typical conversation could be:

A: Hello Jose

Jose: Hello A

A: How are you?

Jose: Fine, you?

A: Fine too. How is going with the project?

Jose: It is going as planned. You can check it in the Project site.

A: Thanks. I will take a look.

Jose: You are welcome.

This Friday I was joking with some colleagues that we should do a Bot as an add-in for the Messenger, so it answers in our place and we don’t need to stop developing. At night when going out I accidentally meet Miguel, who told me about the existence of AIML (Artificial Intelligence Markup Language), something totally unknown for me. The conversation came up without I said anything about the bot … I thought that this was too much coincidence, so I couldn’t resist anymore the idea of creating the add-in.

I took a look to the Artificial Intelligence Foundation where you can find all kind of documentation about the AIML. This language is based on XML and the main thing you need to know is that represents “units of knowledge”. Each unit of knowledge it’s composed by a “pattern” that matches the user inputs or sends to the bots, and a “template” that contains the response for the user. This is represented with the next tags:


The above unit of knowledge will allow answering “Hi” to a user saying “Hello”.

This “simple” language it’s really powerful, since it supports wildcards, contexts, group knowledge by topic, you can also create your custom tags to perform actions … Really, it’s pretty amazing, just take a look to the documentation or even better chat a bit with ALICE.

Looking a bit more in the website I saw that there is a C# 2.0 implementation of the AIML interpreter that you can download from SourceForge.

Having all this, the work is done. We only need to create the add-in for the Live Messenger that is extremely easy using its API.

First of all you need to create a class library and reference the MessengerClient.dll. You can found it in the installation folder of the Messenger. In order Live Messenger can load the Add-in, it’s very important that you name the assembly with the same name as the class implementing the IMessengerAddIn interface. i.e. I called my class AddIn and it is contained in the namespace MessengerBot, so the assembly must be called MessengerBot.AddIn.dll.

Another thing to consider is that the Add-in runs in a sandbox environment with restricted permissions. Since our bot will need to load some files from the local disk, like the configuration file and the AIML files containing the “brain” of our bot, we need to avoid that limitation. To do it just strong name / sign your add-in and the AIMLbot, and then place both assemblies in the GAC.

Take a look to the necessary code to have your own add-in bot.

  using System;
  using System.Collections.Generic;
  using System.Text;
  using Microsoft.Messenger;
  using AIMLbot;
  using System.IO;
  namespace MessengerBot
      public class AddIn : IMessengerAddIn
          private MessengerClient messenger;
          private Bot bot;
          public void Initialize(MessengerClient messenger)
              this.messenger = messenger;
              messenger.AddInProperties.Creator = “Jose Fco Bonnin”;
              messenger.AddInProperties.Description = “Allows chatting with your contacts when you don’t want to chat”;
              messenger.AddInProperties.FriendlyName = “MessengerBot”;
              messenger.AddInProperties.Url = new Uri(““);
              bot = new Bot(); 

              //Loads the file containing the settings of the bot
              bot.loadSettings(Path.Combine(Environment.CurrentDirectory, “Settings.xml”));
              AIMLbot.Utils.AIMLLoader loader = new AIMLbot.Utils.AIMLLoader(bot);
              bot.isAcceptingUserInput = false;
              //Loads all the files with aiml extension that are in the folder
              loader.loadAIML(Path.Combine(Environment.CurrentDirectory, “Aiml”));
              bot.isAcceptingUserInput = true;
              messenger.IncomingTextMessage += new EventHandler<IncomingTextMessageEventArgs>(messenger_IncomingTextMessage);
          void messenger_IncomingTextMessage(object sender, IncomingTextMessageEventArgs e)
              Request request = new Request(e.TextMessage, new AIMLbot.User(e.UserFrom.FriendlyName,,;
              Result ret = bot.Chat(request);
              messenger.SendTextMessage(ret.Output, e.UserFrom);

Thanks to the work of the guys from ALICE and AIMLBot we have created our add-in just with a few lines of code. Now we only need to teach our bot.

The only downside this has is that when you chat, your interlocutor will see the one who speaks is the add-in MessengerBot instead of you. But in any case was so funny to build and play with it.

  • Related Content by Tag