Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering HTML in Amazon lex response from Lambda

I am new to Amazon Lex. I am trying to return a hyperlink as part of the "content" response from Lambda function to the Amazon Lex. Basically I have doing the following:

    var message = {
        'contentType': 'PlainText', 
        'content': 'We offer x,y,z. For more information, visit our <a href="www.xyz.com">website</a>'
    }

This returns the whole response as a string whereas I am expecting the html part to be rendered before displaying on the chatbot. I don't want to use a responseCard below my response. Is that possible to include hyperlink in the content returned? Thanks

like image 385
Anoop Avatar asked Dec 20 '25 09:12

Anoop


2 Answers

PLEASE NOTE THAT THIS IS FOR RENDERING THE CONVERSATION ON A HTML PAGE

I had this same issue when I was developing a HTML page to render the chat between an user and the chatbot. I managed to solve it using the following Javascript Function:

function showResponse(lexResponse) {

    var conversationDiv = document.getElementById('conversation');
    var responsePara = document.createElement("P");
    responsePara.className = 'lexResponse';
    if (lexResponse.message) {
        var message = lexResponse.message.replace(/"/g, '\'');
        responsePara.innerHTML = message;               
        responsePara.appendChild(document.createElement('br'));
    }           
    conversationDiv.appendChild(responsePara);
    conversationDiv.scrollTop = conversationDiv.scrollHeight;
}

For Reference, you can refer to the question I asked regarding this same issue: LexResponse output does not understand HTML data

like image 128
Arun Balasubramaniam Avatar answered Dec 21 '25 23:12

Arun Balasubramaniam


Rendering of the content is the job of client. The test console window of Lex does not support hyperlinks rendering.
However if you deploy your chatbot to some channel like facebook or slack, it will work just fine.

like image 35
sid8491 Avatar answered Dec 22 '25 00:12

sid8491



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!