LexResponse output does not understand HTML data

拈花ヽ惹草 提交于 2019-12-02 04:56:37

Your code is correct and output is also correct.
However the console window is not able to render the HTML part of your result.

The client on which you will deploy the chatbot, is responsible for rendering the output. For example, if you respond with a ResponseCard, console or website will not be able to render it correctly but it will be displayed correctly on Facebook and Slack. So, if you integrate your chatbot on some website it will show the links in your output correctly as you desired.

You can try to integrate your chatbot with Slack or Facebook first, to see the rendering of output.

Hope it helps.

After further trial and error, I managed to get a solution that works for me.

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;
    }

By making the LexResponse an Inner HTML, it fixed the markup of the text and thus the link can be seen everytime.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!