Chat Widget embed

React & Vite

Add the Assistrio AI chat widget to a React app built with Vite or Create React App: paste it in index.html, or load it once from a component.

In a single-page React app — Vite, Create React App, and apps made with Lovable or Bolt — add the code to index.html, not inside a React component, so it loads once for the whole site.

Get your install code

  1. 1

    Open Deploy › Chat Widget

    In Assistrio, open your agent, click Deploy in the top bar, and pick Chat Widget.

  2. 2

    Allow your domains

    Under Allowed websites, add the domain your app runs on in production (and a staging domain, if you test there). See Allowed websites.

  3. 3

    Copy Snippet

    Under Install code, click Copy Snippet. Replace the placeholder code below with yours — it has your real agentId.

Your install code looks like this
<link rel="stylesheet" href="https://widget.assistrio.com/assistrio-chat.css" />
<script>
  window.AssistrioChatConfig = {
    agentId: "YOUR_AGENT_ID",
    apiBaseUrl: "https://chat.assistrio.com",
    position: "right"
  };
</script>
<script src="https://widget.assistrio.com/assistrio-chat.js" async></script>

Add it to your app

  1. 1

    Open index.html

    Vite: index.html in the project root. Create React App: public/index.html.

  2. 2

    Paste the code

    Put the <link> in <head> and the two <script> tags just before </body>, after your app's own script.

  3. 3

    Build and deploy

    Run your usual build (npm run build) and deploy.

Can't edit index.html? Load it from a component

Some setups (micro-frontends, embedded apps) can't touch the HTML. Then load it once from a component near the root — the effect guards against loading twice (including React Strict Mode's double run in development).

src/AssistrioChat.tsx
import { useEffect } from "react";

export function AssistrioChat() {
  useEffect(() => {
    if (document.getElementById("assistrio-chat-js")) return; // already loaded
    window.AssistrioChatConfig = {
      agentId: "YOUR_AGENT_ID",
      apiBaseUrl: "https://chat.assistrio.com",
      position: "right",
    };
    const css = document.createElement("link");
    css.rel = "stylesheet";
    css.href = "https://widget.assistrio.com/assistrio-chat.css";
    document.head.appendChild(css);
    const js = document.createElement("script");
    js.id = "assistrio-chat-js";
    js.src = "https://widget.assistrio.com/assistrio-chat.js";
    js.async = true;
    document.body.appendChild(js);
  }, []);
  return null;
}

// In App.tsx, once: <AssistrioChat />

Using TypeScript? Add the Window types from the JavaScript API so window.AssistrioChatConfig type-checks.

index.htmlReact · Viteindex.html, not a component
1 <body>
2 <div id="root"></div>
3 <script type="module" src="/src/main.tsx"></script>
4 <script>window.AssistrioChatConfig = { agentId: "…" };</script>
5 <script src="…/assistrio-chat.js" async></script>
6 </body>
7</html>
Vite: the code in index.html, after your app's script — not in App.tsx.

Client-side routing

Load the code once for the whole app — not inside a page component, and don't re-run it on navigation. To hide it on some routes, call window.AssistrioChat?.unmount() and mount() — see the JavaScript API.

Local development

The chat only loads on your allowed websites, so it stays hidden on localhost — that's expected. Test on a preview or staging domain you've added (each agent can have up to 3), or test the agent itself in the Playground.

Check it works

  • Deploy, open your site on an allowed domain, and look for the launcher at the bottom right. Send “Hi”.
  • In the browser console, window.AssistrioChat?.isMounted() returns true.
  • Navigate between a few pages: there's still exactly one launcher.
  • Nothing? Look for an [Assistrio Chat] warning in the console — it names the problem (missing agentId, website not allowed, and so on). See Troubleshooting.

Pass a signed-in user

After a user signs in, pass their userId and userHash so the agent knows who they are. The hash is HMAC-SHA256 of the user ID with your agent's secret key, made on your server — never put the key in browser code. See Identity verification.

Server route + browser
// Your server (Express shown): sign the signed-in user's ID.
import crypto from "node:crypto";

app.get("/api/assistrio-identity", requireUser, (req, res) => {
  const userId = String(req.user.id);
  const userHash = crypto
    .createHmac("sha256", process.env.ASSISTRIO_SECRET_KEY)
    .update(userId)
    .digest("hex");
  res.json({ userId, userHash });
});

// After sign-in: ask your server for the signature, then reload the widget as that user.
const { userId, userHash } = await fetch("/api/assistrio-identity").then((r) => r.json());
window.AssistrioChat?.mount({ userId, userHash });

// After sign-out: back to a guest chat.
window.AssistrioChat?.mount({ userId: undefined, userHash: undefined });

Install with AI

Using Claude Code, Cursor, GitHub Copilot, Windsurf, or another coding assistant? Pick it, copy the prompt, paste it into the tool, then paste your install code where it says. It's written for React & Vite. Tip: Deploy › Chat Widget › Install with AI in Assistrio gives the same picker with your code and websites already filled in.

AI tool you use

Add the "Assistrio" AI Chat Widget to my website.

What to do:
- This is a React app: add the code to index.html, not inside a React component, so it loads once for the whole site.
- Put the <link> tag in <head> and the <script> tags just before </body>.
- Add it only once. Don't add it twice or load it again on each page change.
- Paste the code exactly as it is. Don't change the agentId or the URLs.

How to check it works:
- Open the website: a Chat Widget shows at the bottom right.
- Send it a message like "Hi": the agent answers.
- If it doesn't show, check the code is on the page and look for an [Assistrio Chat] message in the browser console.

The code:
[Paste your install code from Assistrio › Deploy › Chat Widget › Copy Snippet here]

Replace the last line with your install code from Deploy › Chat Widget › Copy Snippet. In Assistrio, Install with AI fills it in for you.

Signing in users too? Add this line under What to do:

Extra line — signed-in users
- Identity verification is on: on the server, for each signed-in user, set userId to their id and userHash to HMAC-SHA256(userId) in hex, made with the secret key read from an environment variable named ASSISTRIO_SECRET_KEY. For visitors who aren't signed in, leave both out. Never put the secret key in browser code.

Content Security Policy

If your site sends a Content-Security-Policy header, add these sources to it. They're everything the Chat Widget and Center Stage load. The inline config <script> also needs to be allowed (with a nonce or hash), or move it into a file you serve yourself.

CSP sources to add
script-src  https://widget.assistrio.com;
style-src   https://widget.assistrio.com 'unsafe-inline';
connect-src https://widget.assistrio.com https://chat.assistrio.com;
img-src     https: data: blob:;
media-src   https://assistrio-public-assets.s3.us-east-1.amazonaws.com blob:;
frame-src   https://calendly.com;
DirectiveWhy the widget needs it
script-srcThe widget script, assistrio-chat.js.
style-srcThe stylesheet, plus the <style> tags the widget puts inside its own shadow root (hence 'unsafe-inline').
connect-srcchat.assistrio.com for chat, file uploads, voice, and analytics; widget.assistrio.com for a small location check when the chat starts.
img-srcYour agent's avatar and uploaded files, product photos from your store's own image host (like cdn.shopify.com), and previews of files a visitor attaches (blob:).
media-srcVoice messages: recorded ones play from blob:, sent ones from Assistrio's file storage.
frame-srcOnly if you use a Calendly booking action: the booking page opens inside the chat. Cal.com times show in the chat itself, with no frame.

Note

Using voice messages or dictation? Your site must also allow the microphone (no Permissions-Policy: microphone=() header). For the iframe, keep allow="clipboard-write; microphone" on the tag.

Next steps

Was this page helpful?

Need help? Contact support — we reply within one to two business days.