Connection keys and allowed website addresses
Two things decide whether the widget appears on your website: a connection key and an allowed list of website addresses. The key tells Aiden which assistant and location the widget belongs to. The list tells Aiden which websites may show it. Think of the key as a name badge and the list as the guest list: When the widget starts the chat from the visitor’s browser, Aiden only opens a chat when the badge is valid and the page’s address is on the list.
Some sites run their own server and start the chat from there with a secret key. Those sites skip the guest list. See Use a session token from your own backend.
Two kinds of key
Section titled “Two kinds of key”- The publishable key starts with
pk_. It names the location and is meant to be visible in your page’s code, so it is safe to put in your HTML or JavaScript. When the widget uses it in the browser, Aiden only starts a chat if the page’s website address is on the allowed list. - The secret key starts with
sk_. It is only for your own server. Never put it in a web page, in a script that visitors download, or in a mobile app, because anyone could copy it. The widget never asks for it and never sees it.
Create a connection key
Section titled “Create a connection key”Each location in your assistant has its own key.
- Open your assistant in the dashboard and select Locations.
- Find the location where the assistant will appear. A location without a key shows Not connected yet.
- Select Generate connection key.
When the key exists, the location shows a Connected badge. Right after you generate or replace a key, the dashboard also shows one extra value with the note “Copy it now, it won’t be shown again.” That value is the secret key. It disappears when you save a website address, turn the connection off, or leave or reload the page. Most sites never need it. Keep it only if your own server will start chat sessions, as described below.
Find your publishable key
Section titled “Find your publishable key”On the Locations page, open Advanced: technical details in the location’s card. It shows:
- Embed code, a read-only box that includes your key.
- Your publishable key, as plain text in the same section.
Copy the key value that starts with pk_ and use it as publishableKey in the code from Install the widget.
You can also use the whole snippet instead. The Embed code box holds the same code as Install the widget, with your key already filled in. The Copy code to send to my website person button copies it, so you can send it to whoever looks after your website. The button is in the same location card.
Allow your website address
Section titled “Allow your website address”A new key starts with an empty list, so no website is allowed yet. The dashboard reminds you: “Add your website address below before connecting, or the chat widget won’t load there.” The reminder disappears once the list has an address. Sites that use a session token from their own backend do not need the list.
To add an address, open Advanced: technical details in the location’s card, type the address into Add a website address, and select Save. To remove one, select the X button next to it. The list updates straight away, and the change applies the next time a page loads the widget. From widget version 0.10.8, a visitor who is already on your site keeps the session the widget started for them as they move between pages, for up to 30 minutes. For them, a removed address takes effect at whichever comes first: the first page they open with 5 minutes or less of that session left (the widget then asks Aiden for a new session, and Aiden refuses it), or a message that Aiden refuses.
Aiden compares addresses letter for letter, so each address must match what the visitor’s browser shows. The dashboard does not check or correct what you type. It accepts a mistake without complaint, and the widget then fails to load. Follow these rules:
- Include the scheme, for example
https://example.com. The scheme is thehttps://part at the start. - Include the port if it is not the usual one for that scheme, for example
http://localhost:3000. - Do not add a page path or a slash at the end. Write
https://example.com, nothttps://example.com/shop/. - Treat each variation as a separate address.
https://example.com,https://www.example.comandhttp://example.comare three different addresses, and wildcards such as*.example.comdo not work. Add every one that serves a page with the widget on it. - Test or staging versions of your site have their own addresses, so add them too.
If an address is missing, the chat button does not appear and the browser’s developer console shows an error. See Troubleshooting.
Replace or turn off a key
Section titled “Replace or turn off a key”- Replace key creates a new publishable key and a new secret key. The old ones stop working for new chats at once, so every site that uses the old publishable key needs the new one. A visitor who already has a chat open can keep chatting for up to 30 minutes, until their session runs out. From widget version 0.10.8, that also holds as they move between pages of your site in the same browser tab.
- Turn off connection stops the widget working on your website until you generate a key again. The same short delay applies to chats already open. When you generate a key again for that location, it gets fresh keys and keeps its allowed website addresses. The old keys do not come back.
Both actions ask you to confirm first.
Use a session token from your own backend
Section titled “Use a session token from your own backend”This route is for sites that have their own server and a developer to maintain it. Here your server starts the chat session instead of the visitor’s browser. The secret key stays on your server, and the allowed website list is not checked, because the request never comes from a visitor’s browser.
-
Your server sends the publishable key and the secret key to Aiden:
Terminal window curl -X POST https://api.aidenvoice.com/api/v1/widget/identify-session \-H 'Content-Type: application/json' \-d '{"publishable_key": "pk_...", "secret_key": "sk_..."}' -
Aiden answers with a short-lived session token in the
tokenfield of the response. If the two keys do not belong together, Aiden answers with a 404 error instead. -
Your server hands that token to the page, for example by writing it into the page when the server builds it.
-
The page gives the token to the widget:
init({sessionToken: tokenFromYourServer,})
A session token expires after about 30 minutes. A visitor can keep a page open much longer than that before using the chat, so give the widget a way to get a new token: pass getSessionToken, a function that asks your server for a fresh one. The widget calls it only when it needs to, when the current token has run out or is about to, or when Aiden refuses it as invalid or expired (a 401), and the conversation carries on. It is not called for a token Aiden refuses outright (a 403):
init({ sessionToken: tokenFromYourServer, getSessionToken: async () => { const response = await fetch('/your-session-endpoint', { method: 'POST' }) return (await response.json()).token },})Your endpoint gets the token the same way as in step 1. Without getSessionToken, a visitor who sends a message after the token has run out sees “This chat session has expired. Reload the page to continue.”, and their message goes back into the message box. The same happens when getSessionToken returns an empty or already expired token. When it throws an error or takes longer than 15 seconds, the visitor sees “Something went wrong, please try again.” instead, and their next message asks getSessionToken again.
If the page is given a token that has already expired, the widget asks getSessionToken for a new one before it starts. It does the same when Aiden refuses the token as invalid or expired (a 401). The chat button does not appear only when no usable token can be had: without getSessionToken, when it returns an empty or expired token or one Aiden also refuses, or when Aiden refuses the token outright (a 403, which a new token would not fix). For a token that has already expired when the page starts, the button also stays hidden when getSessionToken throws an error or takes longer than 15 seconds. The widget reads the expiry time itself and does not check the token’s signature. See Errors for the details.
With publishableKey, the widget renews its own session the same way, with nothing to set up.
Each call to identify-session also counts against the key’s daily limit on new sessions. The limit is currently 1,000 new sessions per key per day, and the widget’s own session requests, including its renewals with publishableKey, count toward the same total. From widget version 0.10.8, the widget reuses its session on the following pages of a visit in the same browser tab, while more than 5 minutes of it are left, so a visitor who views several pages uses about one session per 25 minutes of browsing, not one per page. A page opened with 5 minutes or less left asks for a new session, which counts toward the limit and is refused once the limit is reached. Renewals happen only when the widget needs a session, never on a timer: when someone uses the chat and the session has run out or is about to, or when Aiden refuses it as expired. When the limit is reached, further calls fail with a 429 error and the message “Session mint quota exceeded”. On a busy site, do not ask for a token on every page view. Keep one token on your server and give it to pages for a while. Then ask for a new one well before the old one expires, for example after 15 minutes, so every visitor gets a token with plenty of time left.
Pass either publishableKey or sessionToken to init(), never both.
Related pages
Section titled “Related pages”- Install the widget for the full code
- Concepts for how assistants, locations and keys fit together
