/// <summary>
        /// Recursively evaluates the template nodes returned from the bot
        /// </summary>
        /// <param name="node">the node to evaluate</param>
        /// <param name="query">the query that produced this node</param>
        /// <param name="request">the request from the user</param>
        /// <param name="result">the result to be sent to the user</param>
        /// <param name="user">the user who originated the request</param>
        /// <returns>the output string</returns>
        private string ProcessNode(XmlNode node, SubQuery query, Request request, Result result, User user)
        {
            // check for timeout (to avoid infinite loops)
            if (request.StartedOn.AddMilliseconds(request.Bot.TimeOut) < DateTime.Now)
            {
                request.Bot.WriteToLog("WARNING! Request timeout. User: "******" raw input: \"" + request.RawInput + "\" processing template: \"" + query.Template + "\"");
                request.HasTimedOut = true;
                return(string.Empty);
            }

            // process the node
            string tagName = node.Name.ToLower();

            if (tagName == "template")
            {
                StringBuilder templateResult = new StringBuilder();
                if (node.HasChildNodes)
                {
                    // recursively check
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        templateResult.Append(ProcessNode(childNode, query, request, result, user));
                    }
                }
                return(templateResult.ToString());
            }
            else
            {
                AIMLTagHandler tagHandler = null;
                tagHandler = getBespokeTags(user, query, request, result, node);
                if (Equals(null, tagHandler))
                {
                    switch (tagName)
                    {
                    case "bot":
                        tagHandler = new AIMLTagHandlers.Bot(this, user, query, request, result, node);
                        break;

                    case "condition":
                        tagHandler = new AIMLTagHandlers.Condition(this, user, query, request, result, node);
                        break;

                    case "date":
                        tagHandler = new AIMLTagHandlers.Date(this, user, query, request, result, node);
                        break;

                    case "formal":
                        tagHandler = new AIMLTagHandlers.Formal(this, user, query, request, result, node);
                        break;

                    case "gender":
                        tagHandler = new AIMLTagHandlers.Gender(this, user, query, request, result, node);
                        break;

                    case "get":
                        tagHandler = new AIMLTagHandlers.Get(this, user, query, request, result, node);
                        break;

                    case "gossip":
                        tagHandler = new AIMLTagHandlers.Gossip(this, user, query, request, result, node);
                        break;

                    case "id":
                        tagHandler = new AIMLTagHandlers.Id(this, user, query, request, result, node);
                        break;

                    case "input":
                        tagHandler = new AIMLTagHandlers.Input(this, user, query, request, result, node);
                        break;

                    case "javascript":
                        tagHandler = new AIMLTagHandlers.Javascript(this, user, query, request, result, node);
                        break;

                    case "learn":
                        tagHandler = new AIMLTagHandlers.Learn(this, user, query, request, result, node);
                        break;

                    case "lowercase":
                        tagHandler = new AIMLTagHandlers.Lowercase(this, user, query, request, result, node);
                        break;

                    case "person":
                        tagHandler = new AIMLTagHandlers.Person(this, user, query, request, result, node);
                        break;

                    case "person2":
                        tagHandler = new AIMLTagHandlers.Person2(this, user, query, request, result, node);
                        break;

                    case "random":
                        tagHandler = new AIMLTagHandlers.Random(this, user, query, request, result, node);
                        break;

                    case "sentence":
                        tagHandler = new AIMLTagHandlers.Sentence(this, user, query, request, result, node);
                        break;

                    case "set":
                        tagHandler = new AIMLTagHandlers.Set(this, user, query, request, result, node);
                        break;

                    case "size":
                        tagHandler = new AIMLTagHandlers.Size(this, user, query, request, result, node);
                        break;

                    case "sr":
                        tagHandler = new AIMLTagHandlers.Sr(this, user, query, request, result, node);
                        break;

                    case "srai":
                        tagHandler = new AIMLTagHandlers.Srai(this, user, query, request, result, node);
                        break;

                    case "star":
                        tagHandler = new AIMLTagHandlers.Star(this, user, query, request, result, node);
                        break;

                    case "system":
                        tagHandler = new AIMLTagHandlers.System(this, user, query, request, result, node);
                        break;

                    case "that":
                        tagHandler = new AIMLTagHandlers.That(this, user, query, request, result, node);
                        break;

                    case "thatstar":
                        tagHandler = new AIMLTagHandlers.ThatStar(this, user, query, request, result, node);
                        break;

                    case "think":
                        tagHandler = new AIMLTagHandlers.Think(this, user, query, request, result, node);
                        break;

                    case "topicstar":
                        tagHandler = new AIMLTagHandlers.TopicStar(this, user, query, request, result, node);
                        break;

                    case "uppercase":
                        tagHandler = new AIMLTagHandlers.Uppercase(this, user, query, request, result, node);
                        break;

                    case "version":
                        tagHandler = new AIMLTagHandlers.Version(this, user, query, request, result, node);
                        break;

                    default:
                        tagHandler = null;
                        break;
                    }
                }
                if (Equals(null, tagHandler))
                {
                    return(node.InnerText);
                }
                else
                {
                    if (tagHandler.IsRecursive)
                    {
                        if (node.HasChildNodes)
                        {
                            // recursively check
                            foreach (XmlNode childNode in node.ChildNodes)
                            {
                                if (childNode.NodeType != XmlNodeType.Text)
                                {
                                    childNode.InnerXml = ProcessNode(childNode, query, request, result, user);
                                }
                            }
                        }
                        return(tagHandler.Transform());
                    }
                    else
                    {
                        string  resultNodeInnerXML = tagHandler.Transform();
                        XmlNode resultNode         = AIMLTagHandler.GetNode("<node>" + resultNodeInnerXML + "</node>");
                        if (resultNode.HasChildNodes)
                        {
                            StringBuilder recursiveResult = new StringBuilder();
                            // recursively check
                            foreach (XmlNode childNode in resultNode.ChildNodes)
                            {
                                recursiveResult.Append(ProcessNode(childNode, query, request, result, user));
                            }
                            return(recursiveResult.ToString());
                        }
                        else
                        {
                            return(resultNode.InnerXml);
                        }
                    }
                }
            }
        }
 protected override string ProcessChange()
 {
     Bot.WriteToLog("The javascript tag is not implemented in this bot");
     return(string.Empty);
 }