For the complete documentation index, see llms.txt. This page is also available as Markdown.

Chat as Search — Technical Implementation Guide

This guide shows how to add a custom search bar (and optional quick-topic buttons) that opens your Satisfi AI agent with the visitor's question already asked. Each step includes an explanation and code.

Step 1: Add the Chat Widget Script

Add this <script> tag to your page. Replace XXXX with the client's popupId from the Satisfi console.

<script id="satisfiScript"
  src="https://chat.satis.fi/popup/embedder?popupId=XXXX">
</script>

Step 2: Create a Search Interface

Build an input field and button so visitors can type a question.

<div class="chat-search">
  <input type="text" id="chatInput" placeholder="Ask us anything..." />
  <button id="chatBtn">Search</button>
</div>

Step 3: Connect the Search to Chat

Use SatisfiApp.Global.chatPopupOpen(query) to open the chat with the visitor's question already asked. The chat API does nothing (and shows no error) until both SatisfiApp.Global and #divSatisfiChat exist, so the script below waits for both and holds any question asked before the chat finishes loading.

<script>
(function () {
  function ready() {
    var g = window.SatisfiApp && window.SatisfiApp.Global;
    return (g && typeof g.chatPopupOpen === "function" &&
            document.getElementById("divSatisfiChat")) ? g : null;
  }

  var pending = null;
  function ask(text) {
    var q = (text || "").trim();
    var g = ready();
    if (!g) { pending = q; return; }       // hold until the chat loads
    if (q) g.chatPopupOpen(q);             // open with the question asked
    else g.chatPopupOpen();                // empty input: just open the chat
  }

  // Flush a held question once the chat is ready, then stop checking.
  var tries = 0, t = setInterval(function () {
    var g = ready();
    if (g && pending !== null) { var q = pending; pending = null; q ? g.chatPopupOpen(q) : g.chatPopupOpen(); }
    if (g || ++tries > 130) clearInterval(t);
  }, 150);

  var input = document.getElementById("chatInput");
  var btn = document.getElementById("chatBtn");
  btn.addEventListener("click", function () { ask(input.value); input.value = ""; });
  input.addEventListener("keydown", function (e) {
    if (e.key === "Enter") { ask(input.value); input.value = ""; }
  });
})();
</script>

Step 4 (Optional): Add Quick-Topic Buttons

Buttons can send a question with one tap.

To send a button straight to a specific response, pass response_name=<name> as hidden text ("1") and the question the visitor should see as the third argument. Replace YOUR_RESPONSE_NAME with the response's name from the Satisfi console.

Step 5 (Optional): Hide the Default Launcher

If the search bar should be the only entry point, hide the floating chat bubble once after the chat is ready (for example, inside the ready() check in Step 3), or hide it with CSS.

API Reference

Call
What it does

chatPopupOpen()

Opens the chat empty

chatPopupOpen(text)

Opens the chat and sends text as the visitor's question

chatPopupOpen(text, "1")

Sends text without showing it as a visitor message (the text box stays visible)

chatPopupOpen(text, "1", displayText)

Sends text hidden and shows displayText in its place

chatPopupClose()

Closes the chat

chatButtonShow() / chatButtonHide()

Shows or hides the floating launcher (call once)

Try every call live on the Popup Injection Demo.

Pre-Launch Checklist

Last updated

Was this helpful?