Website Integration
Iframe Developer Guide
Embed your agent inline with a plain iframe, and talk to it with postMessage
The iframe runs the same chat as the Chat bubble, built into your page instead of floating over it. The Chat bubble's script is a wrapper that creates this same iframe and posts messages to it. With a plain iframe there's no window.qwryai, so your page talks to the chat with postMessage, in both directions.
When to use the iframe
Use the iframe when:
- The chat sits inside your page, such as a help center section, a dashboard panel or a full-page chat.
- You want the chat always visible, with no button to click.
- Your platform blocks third-party scripts but allows iframes.
- You show the chat in a mobile app's WebView. See Mobile apps.
Use the Chat bubble when you want a floating button, the full JavaScript API and client-side Actions.
Quick start
- Copy the iframe code
In your agent, open Channels, select Manage on the Chat bubble card, open Deploy and choose Website iframe. Select Copy under Iframe setup.
Deploy › Website iframe › Iframe setup. - Add it to your page, with an id
Paste the code where the chat should appear. Give it an
idso your code can find it, and size it to your layout. Keepallow="microphone"if visitors use voice or dictation.<iframe id="qwryai-chat" src="https://www.qwryai.com/embed/YOUR_EMBED_KEY" width="400" height="600" frameborder="0" title="Chatbot" allow="microphone" > </iframe> - Listen to the chat
Add a script after the iframe to log the agent's replies:
const QWRYAI_ORIGIN = "https://www.qwryai.com"; window.addEventListener("message", (event) => { if (event.origin !== QWRYAI_ORIGIN) return; if (event.data?.type === "NEW_MESSAGE") { console.log("Agent replied:", event.data.message.content); } }); - Test it
Load the page and send a message in the chat.
Send commands to the iframe
Post commands to the iframe's window, targeting QwryAI's origin:
const chat = document.getElementById("qwryai-chat");
const QWRYAI_ORIGIN = "https://www.qwryai.com";
function sendToChat(message) {
chat.contentWindow.postMessage(message, QWRYAI_ORIGIN);
}Timing
The chat listens once it has loaded. Wait for the iframe's load event before you post:
chat.addEventListener("load", () => {
sendToChat({ type: "WIDGET_START_NEW_CHAT" });
});Who may send commands
The iframe only accepts commands from pages allowed to embed it:
- With Specific domains off, the page that embeds the iframe is allowed.
- With Specific domains on, the page's origin must be in the list.
A command from any other origin is refused with WIDGET_IDENTIFY_ERROR and the code INVALID_ORIGIN.
Common tasks
Identify a logged-in user
Send the JWT your server signed with the identity secret. See Identity verification for creating the token.
const { token } = await fetch("/api/qwryai-token", { credentials: "include" }).then((r) => r.json());
sendToChat({ type: "WIDGET_SET_USER", payload: { token } });The chat answers with WIDGET_IDENTIFIED, whose payload.success says whether the token was accepted.
Start a new conversation from a button
document.getElementById("new-chat").addEventListener("click", () => {
sendToChat({ type: "WIDGET_START_NEW_CHAT" });
});The chat answers with WIDGET_NEW_CHAT_STARTED.
Ask a question for the user
sendToChat({ type: "WIDGET_SEND_MESSAGE", text: "What are your opening hours?", requestId: "faq-1" });The chat answers with MESSAGE_SENT and the same requestId once the message is accepted, or MESSAGE_SEND_ERROR if it was refused.
Match your page's theme
sendToChat({ type: "WIDGET_SET_THEME", theme: "dark" }); // "light" or "dark"Log the user out
sendToChat({ type: "WIDGET_LOGOUT" });The chat answers with WIDGET_LOGGED_OUT.
Read the visitor's contact
sendToChat({ type: "WIDGET_GET_CONTACT" });
// The chat answers with { type: "WIDGET_CONTACT", payload: { success: true, contact } }Track messages in analytics
window.addEventListener("message", (event) => {
if (event.origin !== QWRYAI_ORIGIN) return;
if (event.data?.type === "MESSAGE_SENT") analytics.track("Chat message sent");
if (event.data?.type === "NEW_MESSAGE") analytics.track("Chat reply received");
});Feature support
Works in the iframe
- Chatting with your agent, including voice and dictation when
allow="microphone"is set. - Identifying users with a signed token, logging out and starting a new conversation.
- Sending messages for the visitor, switching the theme and reading the visitor's contact.
MESSAGE_SENTandNEW_MESSAGEevents for your analytics.
Embed script only
These need the Chat bubble script, because they run through window.qwryai on your page:
- Client-side custom Actions and custom forms.
- The welcome popup and the floating button.
window.chatbot.on()event listeners,open,closeand the unread count.
Messages you can send
type | Fields | What it does | Reply |
|---|---|---|---|
WIDGET_SET_USER | payload: { token }, or { email, name, phone, externalUserId, accountId, customAttributes } | Identifies the visitor. A token is verified; other details are taken as given and need an email, externalUserId or accountId. | WIDGET_IDENTIFIED |
WIDGET_LOGOUT | none | Forgets the visitor. | WIDGET_LOGGED_OUT |
WIDGET_START_NEW_CHAT | none | Starts a new conversation. | WIDGET_NEW_CHAT_STARTED |
WIDGET_SEND_MESSAGE | text, optional requestId | Sends text as the visitor's message. | MESSAGE_SENT or MESSAGE_SEND_ERROR |
WIDGET_SET_THEME | theme: "light" or "dark" | Switches the chat's theme. | none |
WIDGET_GET_CONTACT | none | Asks for the visitor's contact. | WIDGET_CONTACT |
Events you receive
type | Data | When |
|---|---|---|
MESSAGE_SENT | message: { conversationId, messageId, sender, content }, requestId | The visitor's message was accepted. |
NEW_MESSAGE | message: the reply, with content, sender and senderName | A reply arrived from the agent or a teammate. |
WIDGET_IDENTIFIED | payload: { success, contact } or { success: false, error } | After WIDGET_SET_USER. |
WIDGET_IDENTIFY_ERROR | payload: { code, error } | A command came from an origin that isn't allowed. |
URL parameters
Add msg to the iframe's address to send a first message as soon as the chat connects:
<iframe src="https://www.qwryai.com/embed/YOUR_EMBED_KEY?msg=Do%20you%20ship%20to%20Canada%3F" ...></iframe>Complete examples
<iframe
id="qwryai-chat"
src="https://www.qwryai.com/embed/YOUR_EMBED_KEY"
width="400"
height="600"
frameborder="0"
title="Chatbot"
allow="microphone"
> </iframe>
<button id="new-chat">New conversation</button>
<script>
const chat = document.getElementById("qwryai-chat");
const QWRYAI_ORIGIN = "https://www.qwryai.com";
const send = (message) => chat.contentWindow.postMessage(message, QWRYAI_ORIGIN);
chat.addEventListener("load", async () => {
const { token } = await fetch("/api/qwryai-token", { credentials: "include" }).then((r) => r.json());
send({ type: "WIDGET_SET_USER", payload: { token } });
});
document.getElementById("new-chat").addEventListener("click", () => {
send({ type: "WIDGET_START_NEW_CHAT" });
});
window.addEventListener("message", (event) => {
if (event.origin !== QWRYAI_ORIGIN) return;
if (event.data?.type === "NEW_MESSAGE") console.log("Reply:", event.data.message.content);
});
</script>import { useEffect, useRef } from "react";
const QWRYAI_ORIGIN = "https://www.qwryai.com";
export function SupportChat({ token }) {
const frame = useRef(null);
const send = (message) => frame.current?.contentWindow?.postMessage(message, QWRYAI_ORIGIN);
useEffect(() => {
const onMessage = (event) => {
if (event.origin !== QWRYAI_ORIGIN) return;
if (event.data?.type === "WIDGET_IDENTIFIED" && !event.data.payload?.success) {
console.warn("Sign-in failed", event.data.payload?.error);
}
};
window.addEventListener("message", onMessage);
return () => window.removeEventListener("message", onMessage);
}, []);
return (
<iframe
ref={frame}
src="https://www.qwryai.com/embed/YOUR_EMBED_KEY"
width="400"
height="600"
title="Chatbot"
allow="microphone"
onLoad={() => token && send({ type: "WIDGET_SET_USER", payload: { token } })}
/>
);
}Mobile apps
Open the iframe's address, https://www.qwryai.com/embed/YOUR_EMBED_KEY, in a WebView to show the whole chat in your Android or iOS app. For a native chat screen of your own, use the mobile SDKs instead.
Security
Origins
Always post to https://www.qwryai.com, never "*", and check event.origin on every message you receive.
Allowed domains
With Specific domains on, only the sites in the list can show the iframe, and only they can send it commands.
Secrets and data
Never put your identity secret or API keys in page code. Sign identity tokens on your server.
Iframe attributes
Keep allow="microphone" only if you use voice or dictation. Keep the src exactly as copied: its key identifies your agent.
Troubleshooting
See the iframe's console
In your browser's developer tools, switch the console's context to the iframe to see the chat's own logs.
Common problems
The iframe is blank or refuses to load
If Specific domains is on, add your site's address to the list. Check that the src is exactly as copied.
Commands do nothing
Wait for the iframe's load event before you post, and post to https://www.qwryai.com, not "*".
You receive INVALID_ORIGIN
Your page's origin isn't allowed to send commands. Add it under Specific domains.
The user isn't identified
Check the error in WIDGET_IDENTIFIED, and sign a fresh token with the current identity secret. Tokens need user_id and an exp in the future.
Custom Actions or forms don't run
They need the Chat bubble script. See Feature support.