Search code examples
javascriptjquerychatbot

Returning Rendered HTML from Chatbot


I am using the chatbot from liouh (https://github.com/liouh/chat-bot). When I attempt to return a URL, it gives me unrendered/raw HTML instead of a link. How can I return a rendered link given the Google scenario below? Thank you

enter image description here

function chatBot() {
    // current user input
    this.input;

    this.respondTo = function(input) {
        this.input = input.toLowerCase();

        if(this.match('link to google'))
            return "<a href='http://google.com'>Google.com</a>";

        if(this.input == 'noop')
            return;

        return "I dont know the answer to '" + input + "'. You can teach me that via the link at the top of this page.";
    }

    this.match = function(regex) {
        return new RegExp(regex).test(this.input);
    }
}

Solution

  • It looks like in line 54 of index.js you need to change the code from

    line.find('.text').text(text); 
    

    to

    line.find('.text').html(text);
    

    this will append the incoming reply as HTML instead of plain text.