Skip to content

Install the widget

The widget is the chat button that puts your assistant on your website. It sits in the corner of the page. When a visitor selects it, a chat window opens and they can ask questions. You do not build or design anything. You paste a short piece of code into your page, and the widget does the rest.

If someone else looks after your website, send them this page. They can finish the job in a few minutes.

You need two things from the dashboard:

  • A connection key. This is a short code, starting with pk_, that tells Aiden which assistant and location the widget belongs to. It is safe to put in your page, because anyone can see it. See Connection keys and allowed website addresses.
  • Your website’s address on the allowed list. When you use the connection key in the browser, as the snippets on this page do, Aiden only starts a chat on websites you have approved. If your address is not on the list, the widget stays hidden on your site.

This is the simplest route. Paste the snippet just before the closing </body> tag of every page where the assistant should appear. That tag marks the end of the page’s content. Replace pk_... with your connection key.

<script src="https://widget.aidenvoice.com/v0/widget.iife.js"></script>
<script>
window.whooAidenWidget.init({
publishableKey: 'pk_...',
})
</script>

What the snippet does: the first line downloads the widget. The lines after it start the widget with your key.

  • The widget needs the page to be loaded before it starts. Placing the snippet at the end of the page does that. If you must put it in the page’s head, call init() from a DOMContentLoaded handler, which runs once the page is ready.
  • If your website uses a security setting called a Content Security Policy, it may block the snippet. See Allow the widget in your Content Security Policy.
  • The address contains /v0/. That part chooses which version of the widget you get. See Versions to understand it and to lock in an exact version.

Use this route if your website is built by a developer with a bundler, a tool that packs the site’s code together. Install the package:

Terminal window
pnpm add @aiden-voice/widget
Terminal window
npm install @aiden-voice/widget

Then start the widget from your own code:

import { init } from '@aiden-voice/widget'
init({
publishableKey: 'pk_...',
})

Both routes call the same init() function and give the same result. With the code snippet it is window.whooAidenWidget.init. With npm it is import { init } from '@aiden-voice/widget'. Every option is listed in the Configuration reference.

A session is the private link between a visitor’s chat and Aiden. Every call to init() must use exactly one of these two options:

  • publishableKey. The widget asks Aiden for a session by itself when the page loads. Aiden agrees only if the page’s website address is on the key’s allowed list. Choose this if you do not have your own server. It is the usual choice.
  • sessionToken. Your own server asks Aiden for a session, using a secret key that stays on your server. Your server then hands the page a short-lived token, and the widget uses it. Also pass getSessionToken, so the widget can get a new token when the first one runs out. Choose this only if your site has its own backend and you want to keep the secret key there. See Use a session token from your own backend.

A session lasts about 30 minutes. With publishableKey, the widget renews it by itself when a visitor chats after that, and the conversation carries on. From widget version 0.10.8, the widget also keeps the session for the rest of the visit in that browser tab: on the next pages, the chat button appears straight away, without asking Aiden for a new session, as long as more than 5 minutes of it are left.

If you pass both options, or neither, init() stops with an error straight away. The widget never needs a secret key in the visitor’s browser.

You can set the widget’s color, inkColor (text color), accentColor (link color) and name. Aiden also holds its own versions of these, set in the dashboard. The widget picks each one in this order:

  1. If you pass a value to init(), the widget uses it.
  2. If you leave it out, the widget uses the one set in Aiden.
  3. If neither exists, the widget uses its built-in default.

A color the widget cannot use counts as if you had not passed it. In publishableKey mode the widget receives Aiden’s settings together with the session. In sessionToken mode it fetches them using the token. If you pass all four values in sessionToken mode, it skips that step. If the fetch fails for an ordinary reason, such as a network problem, the widget keeps your values and the defaults, and carries on. The one exception is Aiden refusing the token itself. Then the widget does not appear, as described in Errors, unless you pass getSessionToken and it supplies a token Aiden accepts. That works for a token refused as invalid or expired (a 401), but not for one refused outright (a 403). The same goes for a token whose own expiry time has already passed: the widget does not appear unless getSessionToken replaces it.

  • The chat button appears in the bottom-right corner once the widget has finished starting up, which normally takes a moment. Use position to move it to the bottom-left.
  • The chat window opens when a visitor selects the button. It closes with the Close chat button or the Escape key.
  • The widget speaks your page’s language. Its buttons, labels and messages follow the lang setting on your page’s <html> element, in one of 11 languages, or English. Use the language option to choose one yourself. See Language options.
  • Conversations survive a page reload, as long as the visitor stays in the same browser tab. The widget keeps only a reference number for the conversation in the tab’s temporary storage, and nothing else. After a reload the window opens empty, because the earlier messages are not shown again. But the assistant still remembers them, so the next message carries on the same conversation. To start fresh, the visitor selects New conversation. That button appears once the window has at least one message in it. Closing the tab also ends the conversation.

init() gives you back a handle. Call its unmount() method to take the widget off the page:

const widget = init({ publishableKey: 'pk_...' })
widget.unmount()