Website Integration
Chat Interface Control
Open, close and reset the Chat bubble from your own code, and swap its floating button for your own
Control the Chat bubble from your page's JavaScript: open and close it, send a message for the visitor, start a new conversation, or hide the floating button and open the chat from your own.
Every method works in two forms:
window.qwryai("open"): works at any time. Calls made before the widget script loads wait in a queue and run once it's ready.window.chatbot.open(): the same methods on an object, available once the widget script has loaded.
Most methods return a promise, so you can await them.
Methods
open
Opens the Chat bubble.
window.qwryai("open");close
Closes the Chat bubble.
window.qwryai("close");toggle and isOpen
window.chatbot.toggle() opens the chat if it's closed and closes it if it's open. window.chatbot.isOpen() returns true while the chat window is open.
if (!window.chatbot.isOpen()) window.chatbot.toggle();sendMessage(text)
Opens the chat and sends text as the visitor's message, so the agent answers it straight away. The promise resolves with the sent message once QwryAI has accepted it, or rejects if it was refused.
await window.qwryai("sendMessage", "What are your shipping times?");startNewChat
Opens the chat and starts a new conversation. The previous one stays in the visitor's history.
await window.qwryai("startNewChat");hideLauncher and showLauncher
Hides or shows the floating button. Use them when your page opens the chat from its own button.
window.qwryai("hideLauncher");
window.qwryai("showLauncher");getUnreadCount and getContact
window.chatbot.getUnreadCount() returns how many agent replies the visitor hasn't seen. window.chatbot.getContact() returns a promise with the visitor's contact (name, email and so on) once the chat has loaded.
const contact = await window.chatbot.getContact();
console.log(contact?.email);logout, reset and shutdown
| Method | What it does |
|---|---|
window.qwryai("logout") | Forgets the signed-in user. The visitor starts over as a new one. |
window.qwryai("reset") | Like logout, and also clears the unread badge and shows the welcome popup again. |
window.qwryai("shutdown") | Logs the visitor out and removes the Chat bubble from the page. Load the embed snippet again to bring it back. |
For signing users in, see Identity verification.
Examples
Combine these methods with event listeners to build chat experiences that fit your site.
Custom Buttons
Open, close and restart the chat from your own UI, and hide the floating button:
window.qwryai("hideLauncher");
document.getElementById("help-button").addEventListener("click", () => {
window.qwryai("open");
});
document.getElementById("close-button").addEventListener("click", () => {
window.qwryai("close");
});
document.getElementById("new-chat-button").addEventListener("click", () => {
window.qwryai("startNewChat");
});Answer FAQ Questions
Turn static FAQ entries into live answers. A click opens the chat and asks the question:
document.querySelectorAll(".faq-question").forEach((item) => {
item.addEventListener("click", () => {
window.qwryai("sendMessage", item.dataset.question);
});
});Unread Badge on Your Own Button
Show the unread count on your own button when the floating one is hidden:
window.addEventListener("load", function wait() {
if (!window.chatbot) return setTimeout(wait, 200);
window.chatbot.on("unreadCountChanged", (count) => {
document.getElementById("help-badge").textContent = count > 0 ? count : "";
});
});Start Fresh After Checkout
Start a new conversation once an order is placed, so the next question doesn't mix with the last one:
async function onOrderPlaced() {
await window.qwryai("startNewChat");
}Sign Out on a Shared Device
document.getElementById("sign-out").addEventListener("click", async () => {
await window.qwryai("logout");
// ...then sign the user out of your site
});Controlling Without the Embed Script
If you embed the agent as a plain <iframe>, window.qwryai doesn't exist. The iframe accepts a smaller set of commands as messages posted to it, such as starting a new chat or sending a message. See the Iframe Developer Guide.
Best Practices
- Don't fight the visitor: if they close the chat, don't reopen it straight away.
- Open at helpful moments: a pricing page or a failed checkout is a better trigger than page load.
- Leave time to read: wait a moment before starting a new chat after an answer.
- Keep one entry point: if you hide the floating button, make sure your own button is easy to find on every page.