Chat Widget embed
Angular
Add the Assistrio AI chat widget to an Angular app: paste the install code once in src/index.html, outside app-root, and control it from components.
Angular builds one page, src/index.html, so the code goes there once — outside <app-root>.
Get your install code
- 1
Open Deploy › Chat Widget
In Assistrio, open your agent, click Deploy in the top bar, and pick Chat Widget.
- 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
Copy Snippet
Under Install code, click Copy Snippet. Replace the placeholder code below with yours — it has your real
agentId.
<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
Open src/index.html
It's the page Angular renders your app into.
- 2
Paste the code
Put the
<link>in<head>and the two<script>tags just before</body>, after<app-root>. - 3
Build
Run
ng buildand deploy as usual. Angular keeps the tags as they are.
To call the JavaScript API from a component, declare it once: declare global { interface Window { AssistrioChat?: { open(): void; close(): void; mount(c?: object): void; unmount(): void } } }. For server-side rendering (Angular SSR), the same index.html is used, so nothing else changes.
src/index.html, outside <app-root>.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()returnstrue. - 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 (missingagentId, 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.
// 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 Angular. 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 Angular app: add the code to src/index.html, after <app-root>, not inside a component. - 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:
- 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.
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;| Directive | Why the widget needs it |
|---|---|
script-src | The widget script, assistrio-chat.js. |
style-src | The stylesheet, plus the <style> tags the widget puts inside its own shadow root (hence 'unsafe-inline'). |
connect-src | chat.assistrio.com for chat, file uploads, voice, and analytics; widget.assistrio.com for a small location check when the chat starts. |
img-src | Your 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-src | Voice messages: recorded ones play from blob:, sent ones from Assistrio's file storage. |
frame-src | Only 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.
