Get started with AIML C# programming (I): Just say hello to the robot

08 Mar

In this series of articles, I am about to keep a note on my recent trials to program AIML using C#. AIML, or Artificial Intelligence Markup Language, is an XML dialect for creating natural language software agents. With AIML, you can design your own soft robot with ease!

  • Create a library project and add a class called CuteRobot. The reason for create a library is to reuse such robot code later. You may however directly put it in the main application as you like.
public class CuteRobot
    const string UserId = "CityU.Scm.David";
    private Bot AimlBot;
    private User myUser;

    public CuteRobot()
        AimlBot = new Bot();
        myUser = new User(UserId, AimlBot);

    // Loads all the AIML files in the \AIML folder         
    public void Initialize()
        AimlBot.isAcceptingUserInput = false;
        AimlBot.isAcceptingUserInput = true;

    // Given an input string, finds a response using AIMLbot lib
    public String getOutput(String input)
        Request r = new Request(input, myUser, AimlBot);
        Result res = AimlBot.Chat(r);
        return (res.Output);

  • You need:
    • Add a reference to the AIMLbot.dll to the project
    • You need also to copy the aiml and config folders to the bin folder of the library project


  • Create a console application, add reference to the above library project, in the Main class:

class Program
    static CuteRobot bot;
    static void Main(string[] args)
        bot = new CuteRobot();
        string input = "Hello, what is your name";
        var output = bot.getOutput(input);

Also copy the aiml and config folders to the bin folder of the console application’s bin folder. Now run the application, you might see:


Ha! It worked! When you ask “hello, what is your name?”, the robot answers: “Hello there. My name is Unknown”! Smart? Cool?

Even though it is weird that the robot says his name is “Unknown”, it worked! In the next blog, I will focus on how to customize the robot’s name and other attributes.

Happy coding!


Posted by on March 8, 2014 in AI, Programming


Tags: , , , , , , , , ,

5 responses to “Get started with AIML C# programming (I): Just say hello to the robot

  1. Ravindra

    September 16, 2015 at 5:19 pm


    I am using AIML and when I am writing a console app its working fine. But when I am using AIML for writing API and when I am deploying, I am unable to loadSetting of AIML. The error I get is unable to find Specified file even though that file exists. I have been trying to solve this since past many days. Can you please help me.

    Thanks in advance.

  2. Michael

    February 6, 2016 at 8:26 pm

    Hello,i have some question about AIML.Does it work only with english?if no,how to change language of the massages?

  3. 2k16 coins

    May 11, 2016 at 9:33 am

    You have the best web sites


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

%d bloggers like this: