Chat Widget embed

Astro

Add the Assistrio AI chat widget to an Astro site in your base layout, using is:inline so Astro doesn't bundle the scripts, with View Transitions tips.

Add the code once in the layout every page uses (usually src/layouts/Layout.astro). Add is:inline to both <script> tags — otherwise Astro bundles and moves them, and the config may run too late.

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

src/layouts/Layout.astro
---
const { title } = Astro.props;
---
<html lang="en">
  <head>
    <title>{title}</title>
    <link rel="stylesheet" href="https://widget.assistrio.com/assistrio-chat.css" />
  </head>
  <body>
    <slot />
    <script is:inline>
      window.AssistrioChatConfig = {
        agentId: "YOUR_AGENT_ID",
        apiBaseUrl: "https://chat.assistrio.com",
        position: "right"
      };
    </script>
    <script is:inline src="https://widget.assistrio.com/assistrio-chat.js" async></script>
  </body>
</html>

Note

Using View Transitions (<ClientRouter />)? Keep the scripts in the shared layout, not in individual pages, and add transition:persist to both <script> tags so Astro keeps them between pages instead of running them again.

src/layouts/Layout.astroAstrois:inline on both
1 <body>
2 <slot />
3 <script is:inline>window.AssistrioChatConfig = { agentId: "…" };</script>
4 <script is:inline src="…/assistrio-chat.js" async></script>
5 </body>
6</html>
Astro: both scripts with is:inline, in the base layout.

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 Astro. 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 an Astro site: add the code once in the base layout (src/layouts/Layout.astro), and add is:inline to both <script> tags.
- 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.