static

Integrating with your page

Your website can control your Authava bot with JavaScript. Your page can open and close it from your own buttons, send a message as the visitor, show a tooltip, and let the bot run functions on your page.

This page covers the browser side: your web page talking to the bot. For connecting the bot to your servers and systems, see Full Integration.

Try It Live

The sample integration page shows these controls working with a real bot: buttons that show and hide the bot, send a message, and show a tooltip. View the page source to see the full code.

How Does My Page Get Access to the Bot?

Install the bot as usual with its one-line script (see Any Website (HTML)). When the bot starts up on the page, it fires an AuthavaChatbotReady event. From then on, the bot's controls are available at window["AuthavaChatbot_" + yourId], using your bot's ID from the script tag:

<script>
  // Add the listener before the bot script loads, so you don't miss the event.
  window.addEventListener("AuthavaChatbotReady", () => {
    // The bot's controls are now available.
  });

  // Look up the controls each time you use them, rather than saving a copy.
  function getBot() {
    return window["AuthavaChatbot_" + "{{your_id}}"];
  }
</script>
<script defer src="https://cdn.authava.com/chatbot.js" data-id="{{your_id}}"></script>

The event fires once, when the bot starts up on the page. That can be a moment before the bot's settings finish loading and the chat button appears. Attach your listener before the bot's script tag so it's in place in time.

Look up window["AuthavaChatbot_" + yourId] at the moment you need it. The controls are refreshed as the chat changes, so a saved copy, including event.detail.client, can report out-of-date information, such as whether the chat is open.

How Do I Make a Button Open the Bot?

Call open() on the bot's controls from your button. close() closes it, toggle() switches between the two, and isOpen() tells you whether it's open.

<button id="openBotBtn" disabled>Open Chatbot</button>

<script>
  const botKey = "AuthavaChatbot_" + "{{your_id}}";
  window.addEventListener("AuthavaChatbotReady", () => {
    const btn = document.getElementById("openBotBtn");
    btn.disabled = false; // the bot is ready, so enable the button
    btn.addEventListener("click", () => window[botKey].open());
  });
</script>
<script defer src="https://cdn.authava.com/chatbot.js" data-id="{{your_id}}"></script>

Disabling the button until the bot is ready avoids clicks that would do nothing.

This pairs well with hiding the floating chat button, when you want the bot opened only from your own buttons or links. Ask our team to turn that on.

click_button_opens_bot.png

Can My Page Send a Message to the Bot?

Yes. sendMessage("text") sends a message as if the visitor had typed it, opening the chat if it's closed, and the bot's reply appears in the chat. For example, an "Ask about pricing" button on your pricing page can open the bot with that question already asked:

window["AuthavaChatbot_" + "{{your_id}}"].sendMessage("What are your pricing options?");

Can I Show a Message Next to the Chat Button?

Yes. showTooltip("Questions about this plan? Ask me.") shows a small message bubble next to the closed chat button, and hideTooltip() hides it. The tooltip appears only while the chat window is closed, and it has no effect when the floating chat button is hidden. This is useful for a page-specific nudge, such as on a checkout or pricing page.

Can the Bot Run Something on My Page?

Yes. Your page can register its own JavaScript functions with registerClientFunction("name", fn). The bot can then offer a button in its reply that runs that function, for example to open a specific form, highlight part of the page, or start a checkout step.

Which bot replies offer these buttons is set up by our managed services team.

Can the Bot Recognize a Signed-In User?

Yes. The same JavaScript API is used to pass a signed-in visitor's identity to the bot, so it can give account-specific answers without a second login. This is set up with our managed services team. See Portal Bot and Full Integration.

Frequently Asked Questions

Can I open the Authava chatbot from my own button?

Yes. Listen for the AuthavaChatbotReady event, then call window["AuthavaChatbot_" + yourId].open() from any button or link.

Do I still need the regular install script?

Yes. Keep the one-line script on the page. The JavaScript controls work with it rather than replacing it.

Why does my button do nothing when clicked?

It was probably clicked before the bot was ready. Attach the AuthavaChatbotReady listener before the bot's script loads, and enable your button only once the event fires.

Can I pre-fill a question for the visitor?

Yes. Call sendMessage("your question") on the bot's controls. It sends the message as if the visitor typed it, and the bot replies.

Where can I see a working example?

On the sample integration page. View its source for the full code.