Search code examples
javascriptnode.jschatchatbotaiml

How to use AIML with Node.js?


How do I use AIML (Artificial Intelligence Markup Language) with Node.js? I am building a chatbot using JavaScript and Node.js for which I need AIML. How do i use it? I have tried using the AIML Interpreter but I am facing problems while accessing the AIML libraries and tags in my Server.js file. Error which i get sometimes when i input chat and do not get a response from the bot.


Solution

  • hope this would be helpful.

    Installation

    npm install aiml
    

    Parameters

    authorData - (required) message author metadata (name, age, etc.).
    message - (required) just message.
    callback - (required) classic js callback, nothing special: ).
    

    Sample

    var aiml = require('aiml')
    
    aiml.parseFile('sample.aiml', function(err, topics){
      var engine = new aiml.AiEngine('Default', topics, {name: 'Jonny'});
      var responce = engine.reply({name: 'Billy'}, "Hi, dude", function(err, responce){
        console.log(responce);
      });
    });
    

    I assume that you already know basic concepts of AIML and the file structure.