# 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. > [!NOTE] > > Call methods as `window.qwryai("open")`, with the method name as the first argument. The shorthand `window.qwryai.open()` only works until the widget script has loaded. ## Methods ### open Opens the Chat bubble. ```javascript window.qwryai("open"); ``` ### close Closes the Chat bubble. ```javascript 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. ```javascript 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. ```javascript await window.qwryai("sendMessage", "What are your shipping times?"); ``` > [!NOTE] > > `sendMessage` sends the message; it doesn't only fill the message box. The visitor sees it in the conversation like any message they typed. ### startNewChat Opens the chat and starts a new conversation. The previous one stays in the visitor's history. ```javascript await window.qwryai("startNewChat"); ``` > [!NOTE] > > Your Chat bubble settings and initial messages stay as they are after a new chat starts. ### hideLauncher and showLauncher Hides or shows the floating button. Use them when your page opens the chat from its own button. ```javascript 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. ```javascript 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](/docs/developer-guides/website-integration/identity-verification). ## Examples Combine these methods with [event listeners](/docs/developer-guides/website-integration/chatbot-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: ```javascript 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: ```javascript document.querySelectorAll(".faq-question").forEach((item) => { item.addEventListener("click", () => { window.qwryai("sendMessage", item.dataset.question); }); }); ``` ![On a demo store page with the floating button hidden, clicking a Do you ship to Canada? FAQ link opens the Chat bubble, sends the question and shows the agent's answer.](walkthroughs/faq-send-message.gif) ### Unread Badge on Your Own Button Show the unread count on your own button when the floating one is hidden: ```javascript 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: ```javascript async function onOrderPlaced() { await window.qwryai("startNewChat"); } ``` ### Sign Out on a Shared Device ```javascript 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 `