Skip to content

Support "contextual links" in chatbot message #548

@TamiTakamiya

Description

@TamiTakamiya

Currently, PF chatbot is capable of rendering Markdown outputs from Large Language Model (LLM) and includes static links. However, we would like to introduce a new feature called 'contextual links' for PF Chatbot, which will enable users to click on these links and be taken directly to a specific page within our product UI.

We implement a PoC by updating the HTML anchor ("a") tags dynamically to update its href and onclick elements after PF chatbot completes the rendering. It looks like

  useEffect(() => {
    document?.querySelectorAll("iframe").forEach((item) => {
      const as = item.contentWindow?.document?.body?.querySelectorAll("a");
      as?.forEach(function (element) {
        const link = element.href;
        console.error("PROPOSING LINK FOR " + link);
        // TODO: We can check the original href and see it no host/port is specified, then we can assume it's an internal navigation link.
        if (link.includes("awx")) {
          const pageId = link.substring(link.lastIndexOf("/") + 1);
          console.error("CHANGING LINK FOR " + pageId);
          element.href = "#";
          element.onclick = function (event) {
            console.error("HELLO CLICKED ON " + pageId);
            sendMessage(pageId);
            event.preventDefault();
            event.stopPropagation();
          };
        }
      });
    });
  });

We would like PF chatbot to do these manipulations during parsing a message instead of depending on the post-processing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    PF6Applies to only the PF6 version
    No fields configured for Feature.

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions