working with Databases

2007-03-06
2013-04-22
  • Thiago Tavares

    Thiago Tavares - 2007-03-06

    Hello Everybody!

    I want to know, how is the best way to implement the bot with databases.
    The workflow is like this:
       - The user makes a question to the bot;
       - The bot should searches an answer in the aiml files;

    In this moment I want to:
       - Specify in the aiml (I think) that, the boot should look for the answer in the database, and show the results;
       - Another idea could be, if the bot doesn't find the answers in the aiml, the bot could take a look in the database;

    I'm sharing the idea in order to talk about it with you!

    Thnaks to spend your time!

    Regards,

    Thiago

     
    • Nicholas Tollervey

      Hi Thiago,

      The best strategy would be to implement a custom tag that connected to the database to get the information you need.

      The following example code should get you started (i.e. this is an example that you need to change to meet your requirements and won't work properly unless you do):

      using System;
      using System.Xml;
      using AIMLbot.Utils;
      using System.Data.Sql;

      namespace MyTestNamespace
      {
      [CustomTag]
      public class databasetag : AIMLTagHandler
      {
      public testtag()
      {
      this.inputString = "databasetag";
      }

      protected override string ProcessChange()
      {
      if (this.templateNode.Name.ToLower() == "databasetag")
      {
      // Insert your database specific methods here
      // e.g. connect to database and run "SELECT address FROM users WHERE surname = this.databasetag.InnerText"
      // !!! OBVIOUSLY REMEMBERING TO CHECK FOR SQL INJECTION AND OTHER NASTIES
      return resultOfMyQuery;
      }
      return string.Empty;
      }
      }
      }

      Hope this helps,

      Nicholas

       
    • Thiago Tavares

      Thiago Tavares - 2007-03-07

      Hi Nicholas,

      Thanks a lot, it really works good! :)
      This is an interesting feature that give a big flexible to the bot.

      Cool!

      Thanks a lot again!

      Regards,
      Thiago

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks