JiteshGaikwad/Chatbot-Widget

How to add HTML link as a Bot Response.

Closed this issue · 0 comments

Could you please let me know how to add HTML as the bot response in this widget?

I have created html_attachment file, similar to pdf_attachment file, and modified the code wherever required. But I'm not getting any response.

For reference:


HTML Attachment

  • sending response from domain.yml
    responses:
      utter_html:
        - text: "Here is the HTML link."
          custom: 
            payload: html_attachment
            title: "HTML Title"
            url: "URL to HTML link"
    
  • sending response from actions.py
      data = {
        "payload":"html_attachment",
        "title": "HTML Title",
        "url": "URL to HTML link"
      }
    dispatcher.utter_message(json_message=data)
    
    

Also, created a file html_link.js:

/**

  • renders html link on to the chat screen

  • @param {Object} html_data json object
    */
    function renderhtmllink(html_data) {
    const { url: html_url } = html_data.custom;
    const { title: html_title } = html_data.custom;
    const html_attachment = <div class="html_attachment"><div class="row"><div class="col s3 html_icon"> <i class="fa fa-file-pdf-o" aria-hidden="true"></i></div><div class="col s9 html_link"><a href="${html_url}" target="_blank"> ${html_title} </a></div></div></div>;

    $(".chats").append(html_attachment);
    scrollToBottomOfResults();
    }


Added the above changes in chat.js as well:

// check if the custom payload type is "html_attachment"
if (payload === "html_attachment") {
renderhtmllink(response[i]);
return;

Please let me know if i am missing anything here. Appreciate your help. Thanks in Advance :)