Skip to Content
Assistant Core

Web Widget

Add your assistant to your website as a floating chat window, choose which sites can show it, set how it looks and what it says, and let visitors attach files.

The Web Widget adds your assistant to any website as a floating chat button and window. Visitors chat without signing in, or as the users your website signed in. Assistant Core provides the interface, streamed replies, Markdown, light and dark themes, and a full-screen layout on phones.

Before you begin

  • You have the Assistant Owner role on the assistant.
  • The assistant owner's plan includes Widget Embed. See Plans and pricing. Without it, the Web Widget page shows Upgrade to install the widget.
  • You know each website origin that will show the widget, for example https://www.example.com. An origin is the protocol, hostname, and port when it isn't the default. It has no path, query, or fragment.

Widget replies use the assistant owner's credits. Anyone who can open an allowed website can chat, so watch usage in Dashboard after you go live. See Credits.

Allow your websites

  1. Open the Admin Panel and select the assistant.
  2. Go to Deploy → Web Widget.
  3. On the Install tab, under Allow websites, enter the origin in Website origin and select Add website. Repeat for each site.

Websites save as soon as you add or remove them. If you remove one by mistake, select Undo in the notification to add it back.

Rules for origins:

  • Add every origin separately: production, staging, and preview. https://example.com and https://www.example.com are different origins.
  • Use https://. The hosted service only answers widget requests from HTTPS origins, so http://localhost:3000 does not work. Test on an HTTPS staging or preview URL instead.
  • Several assistants can allow the same origin, for example when different pages of one website use different assistants. The snippet picks the assistant with data-assistant-id.

Install the widget

Under Add the code to your website, pick your platform (HTML, Next.js, WordPress, or Shopify) to see where the code goes, then select Copy code. The button is available after you add at least one website. If someone else edits your website, select Email to a developer to send them the code, your allowed websites, and a link to this guide. The snippet already contains your assistant ID:

<script
  src="https://cdn.assistantcore.com/embed/embed.js"
  data-assistant-id="YOUR_ASSISTANT_ID"
  data-api-base="https://api.assistantcore.com"
  async
></script>

Add it once, near the end of <body> or in your framework's root layout.

<body>
  <!-- Website content -->

  <script
    src="https://cdn.assistantcore.com/embed/embed.js"
    data-assistant-id="YOUR_ASSISTANT_ID"
    data-api-base="https://api.assistantcore.com"
    async
  ></script>
</body>

Script attributes

AttributeRequiredDescription
data-assistant-idYesThe assistant's ID. The copied snippet fills it in.
data-api-baseYes, when loading from the CDNThe Assistant Core API address. Keep the value from the copied snippet.
data-langNoInterface language: en or vi. Without it, the widget uses the page's <html lang>, then the browser language, then English.
data-offset-xNoDistance in pixels from the side edge, 0 to 240. Default 24. Use it to clear another floating button.
data-offset-yNoDistance in pixels from the bottom edge, 0 to 240. Default 24. Use it to clear a cookie banner or bottom bar.
data-hide-launcherNoDon't show the floating chat button. Open the chat from your own button with the JavaScript API below.

Control the widget from your page

After the widget loads, your page can control it, for example from a "Chat with us" button:

AssistantEmbed.open()
AssistantEmbed.open({ message: "I have a question about order #123" }) // fills in the message; the visitor sends it
AssistantEmbed.close()
AssistantEmbed.toggle()
AssistantEmbed.isOpen() // true or false
AssistantEmbed.hideLauncher() // for example on a checkout page
AssistantEmbed.showLauncher()

To react to the chat, for example in your analytics, listen for events:

AssistantEmbed.on("open", () => {})
AssistantEmbed.on("close", () => {})
AssistantEmbed.on("message", ({ text }) => {}) // the visitor sent a message
AssistantEmbed.on("reply", ({ text }) => {}) // the assistant finished a reply, or staff wrote
AssistantEmbed.on("identity_expired", ({ code }) => {}) // the sign-in token was refused; see Sign in your users

off(event, handler) removes a listener.

The API is available once the widget has loaded its configuration, and the widget then fires assistantembed:ready on window. To call it earlier, for example right after the snippet, queue the calls; they run in order once the widget is ready:

<script>
  window.AssistantEmbed = window.AssistantEmbed || []
  AssistantEmbed.push(["open", { message: "Hi!" }])
</script>

Content Security Policy

If your website sends a Content Security Policy, allow the widget in it:

DirectiveAdd
script-srchttps://cdn.assistantcore.com/embed/, with the trailing slash. The snippet loads a second file from that folder, so allowing only embed.js blocks the widget. With a nonce-based policy, put your nonce on the snippet's <script> tag instead; the widget passes it on.
connect-srchttps://api.assistantcore.com
img-srchttps://cdn.assistantcore.com https://*.amazonaws.com (avatars, reply images and visitor attachments). Add https: to show website icons beside cited web pages; without it they show a globe icon.
style-srcNothing in current browsers: the widget's styles are constructed stylesheets. Safari before 16.4 needs 'unsafe-inline'.
trusted-typesassistant-embed, if you enforce Trusted Types.

Customize appearance and messages

On the Appearance tab, choose how the widget looks and what it says before a visitor types. The preview beside the fields follows your changes. Switch it between Closed (the chat button and greeting bubble), Welcome (what a visitor sees on opening it), and Chat (a sample reply in your brand color); it also switches on its own to show the field you're editing. Select Save when you're done. A dot on the tab means changes aren't saved yet.

SettingWhat it does
Primary colorThe color of the chat button, the visitor's messages, and links. It's the same setting as the brand color in the assistant's Settings, so it also changes your assistant's chat page. Needs White Labeling on the owner's plan.
ThemeLight (default), Dark, or Match device, which follows each visitor's light or dark setting. Pick the one that suits your website.
PositionBottom right (default) or Bottom left.
Greeting bubbleA short message beside the chat button, shown once per visit after about 5 seconds. A visitor who closes it doesn't see it again. It never shows on phones. Leave Greeting message empty to use the default greeting in each visitor's language.
Conversation startersUp to 4 questions on the welcome screen, up to 80 characters each. A visitor taps one to send it. There are none until you add them.
Message box placeholderThe hint text in the message box. Leave it empty to use the default in each visitor's language.
Privacy policy linkA Privacy link in the widget footer. It must start with https://.

Text you enter is shown as written, whatever the visitor's language. The name and avatar come from Settings.

Allow visitor attachments (optional)

By default, visitors can send text only. To let them attach files, turn on Visitor attachments on the Visitors & security tab. The setting saves as soon as you switch it.

LimitValue
File typesImages (PNG, JPEG, GIF, WebP, HEIC), PDF, Word (.docx), PowerPoint (.pptx), Excel (.xlsx, .xls), OpenDocument text, EPUB, RTF, CSV, text, Markdown, JSON, HTML, XML
File size10 MB per image, 25 MB per other file
Files per message5
Upload rate20 files per hour per visitor, 60 per hour per network address
StorageVisitor files are deleted after 30 days

Audio and video files are not accepted in the widget.

Sign in your users (optional)

If people sign in to your website, you can tell the widget who they are. Their conversation then follows them to every browser and device, it starts empty for the next person on a shared computer, and staff see their name, email and your user ID in Conversations.

  1. Under Signed-in visitors on the Visitors & security tab, select Create signing key and add the key to your server's settings, for example as ASSISTANT_WIDGET_SECRET. Keep it on your server only: anyone with the key can sign in to the widget as any of your users.
  2. On your server, sign a token for the signed-in user with HS256. sub (your user ID, up to 255 characters) and exp are required; name and email are optional.
import jwt from "jsonwebtoken"

const token = jwt.sign(
  { sub: String(user.id), name: user.name, email: user.email },
  process.env.ASSISTANT_WIDGET_SECRET,
  { algorithm: "HS256", expiresIn: "1h" },
)
  1. Hand the token to the widget on every page the user sees while signed in, and reset it when they sign out:

    <script>
      window.AssistantEmbed = window.AssistantEmbed || []
      AssistantEmbed.push(["identify", { token: "TOKEN_FROM_YOUR_SERVER" }])
      // When the user signs out:
      // AssistantEmbed.push(["reset"])
    </script>

The widget keeps the token in memory only. When a token expires, the widget tells the visitor their session expired and fires identity_expired; get a new token from your server and call identify again, and the visitor's Retry goes through:

AssistantEmbed.push(["on", "identity_expired", async () => {
  const { token } = await fetch("/api/assistant-token").then((r) => r.json())
  AssistantEmbed.identify({ token })
}])

reset() also forgets the browser's visitor ID, so the next person starts as a new visitor.

To let only signed-in users chat, turn on Only signed-in users can chat. The widget then stays hidden until your page calls identify.

Replace key makes a new key; tokens signed with the old one stop working at once, so update your server straight after. Turn off deletes the key, and everyone chats as an anonymous visitor again; tokens your site still sends are ignored.

Limit replies per day (optional)

Anyone who can open an allowed website can use the widget, and every reply uses your credits. To cap what a busy or abusive day can cost, set Daily reply limit on the Visitors & security tab. It counts replies from all visitors together and resets at midnight, Vietnam time. Once it's reached, the widget hides for new page views, and visitors with the chat open see that the assistant will be back tomorrow. Leave it empty for no limit.

What visitors see

The widget uses settings you already manage elsewhere:

  • Name, description, and avatar come from the assistant's Settings. The brand color is the Primary color, set on the Appearance tab or in Settings; the logo comes from Settings. Both need White Labeling on the owner's plan. If the brand color is too light or too dark to read as text, the widget uses a darker or lighter shade of it for links and outlines.
  • The footer shows your Privacy link (when set) and Powered by Assistant Core. The credit is hidden when the owner is on Pro or higher.
  • History. The last conversation is restored when the visitor returns in the same browser. New conversation starts over.
  • The page they're on. Each message tells the assistant the page's address and title, so "how much is this?" on a product page needs no explaining. The address is sent without its query string or fragment.
  • Feedback. Visitors can mark a reply Helpful or Not helpful. After Not helpful they can pick what went wrong (incorrect, didn't answer the question, missing details, too long, wanted a person, or something else) and add a comment. Ratings count toward Positive feedback on the dashboard; the reason and comment show on the reply in Conversations.
  • Result cards. When a tool returns a result card, the widget draws the full card with its image and buttons.

Widget conversations appear in Conversations with the Widget channel. To limit which tools the assistant can use in the widget, set where each tool runs in Tools. See Tools and MCP.

Talking to staff

When you turn on Staff handoff, the assistant in the widget can pass the conversation to your team, and staff answer the visitor from Conversations.

  • Who answers. The top of the chat shows Waiting for our team, then the staff member's name once they write. A note in the conversation marks when staff join and when the assistant answers again.
  • Visitor messages go to staff instead of the assistant until the assistant answers again.
  • Staff messages show within a few seconds while the chat is open. While it is closed, the chat button shows an unread badge. Visitors who left the page see them when they come back in the same browser.
  • Contact email. Once staff have the conversation, the visitor can leave an email (optional). Staff see it in the conversation; the widget sends the visitor no email.

Privacy

The widget stores a random visitor ID, the last conversation (with any email the visitor left for staff), and whether the greeting was shown or closed in the visitor's browser (local and session storage). The visitor ID and conversation are stored only once the visitor sends a message. It sends messages, attachments, the page's address and title, and any email the visitor leaves for staff to your assistant. For signed-in users, it also sends the token your server signed, with the user ID, name and email in it. Before you publish:

  • Make sure your privacy notice covers this use of data, and add its address as the Privacy policy link.
  • Check consent requirements in the markets where you operate.

Verify the installation

The page header shows where the widget stands: Not set up until you allow a website, Waiting for first chat after that, and Live once a conversation has come in through the widget. Under Check that it works on the Install tab, select Check again after you send a test message; it then shows how many widget conversations there are and when the latest one was.

  1. Open the site from an origin you allowed.
  2. Confirm that the chat button appears in the corner you chose.
  3. Send a test message and confirm that the reply streams in.
  4. Find the conversation in Conversations under the Widget channel.

Troubleshooting

SymptomCause and fix
The chat button doesn't appearThe widget shows nothing when it cannot load the assistant. Open the browser console: missing data-assistant-id means the attribute is missing; could not load assistant config means the origin isn't saved, the page isn't on HTTPS, the assistant is inactive, or the ID is wrong; the assistant is not taking messages right now means the owner is out of credits or the plan no longer includes Widget Embed, and the widget comes back once there are credits again.
Console shows a CORS errorThe page's origin is not in Allow websites. Check www, protocol, and port, then add the exact origin.
Console shows a Content Security Policy errorAllow the widget as in Content Security Policy. script-src must allow the https://cdn.assistantcore.com/embed/ folder, not just embed.js.
The chat button doesn't appear for some visitorsOnly signed-in users can chat is on and the page didn't call identify, or the daily reply limit is reached.
"Your session has expired. Refresh the page or sign in again to continue."The token your page handed over expired or wasn't signed with the current key. Handle identity_expired and hand over a fresh token.
"The assistant has answered all it can for today. Please come back tomorrow."The Daily reply limit is reached. Raise or clear it, or wait until midnight (Vietnam time).
"This feature is not available on the current plan."The owner's plan no longer includes Widget Embed. Upgrade the plan.
"The assistant can't reply right now. Please try again later."The assistant owner has run out of credits. Top up credits or upgrade the plan. See Credits.
"You've reached the message limit. Please try again later."The visitor is sending messages too fast. Wait a moment, then send again.
The paperclip button is missingTurn on Visitor attachments, then reload the website.
"Too many uploads. Please try again later."The visitor reached the hourly upload limit.

Last updated on