Developers
Run it in a sandbox
Your own keys in every sample. Sign in and the code on this page uses your web agent's publishable key.
Sign in
For sites that won't run a third party's code on their pages. In the default install,
widget.js runs on your page. In the sandbox, the messenger runs in a frame on
embed.bindkit.ai, another origin, so the browser keeps it from your page, your cookies and
your storage. It knows only what you send it. It also works with the strict headers the default install
can't, such as 'strict-dynamic' and Trusted Types: see
Security headers.
No script on your page
An iframe, which stays open and fills the size you give it.
<iframe
src="https://embed.bindkit.ai/embed/pk_...?greeting=Hi&suggestions=Where%20is%20my%20order%3F"
title="Support"
style="width: 400px; height: 640px; border: 0"
allow="microphone; clipboard-write"
sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox"
></iframe>
The sandbox attribute also stops the frame navigating your page. Browsers warn that
allow-scripts with allow-same-origin can escape a sandbox. That's only so for a
frame on your own origin, and this one isn't.
Send it data
Put data in the frame's address. Values after the # take the same names, win over the query
and stay out of server logs, so put anything personal there.
| Name | What it sets |
|---|---|
greeting |
What a new conversation opens with. |
suggestions |
A question a new conversation offers. Repeat it for each one. |
language |
The language the messenger is in, such as de. |
page, title |
The address and title of the page the visitor is on, for the agent. Without them it knows your site at most, from the referrer. |
user.id, user.email, user.name |
Who the visitor is. |
user.tags |
Your tag for them. Repeat it for each one. |
user. and any attribute |
Anything else about them, such as user.plan=pro. |
userToken |
A signed user token. It's only read after the #. |
Signed-in users
user. values are what the page says, so anyone can change them. With
identity verification on, the agent ignores them, as it does
user in any install. Who the visitor is then comes only from a signed token, so put their
name and attributes in its claims.
<iframe src="https://embed.bindkit.ai/embed/pk_...#userToken=TOKEN_FROM_YOUR_SERVER" ...></iframe>
Change it once it has loaded
Send the frame a message. It takes identify, configure, open,
close, toggle, ask, reset and remove,
from the page around it and nowhere else.
frame.contentWindow.postMessage(
{ bindkit: 'command', command: ['ask', 'Where is my order?'] },
'https://embed.bindkit.ai'
)
Over the page
The bar, side panel and corner button need a small script to place the frame and pass messages to it. It's
the only BindKit code on your page, and short enough to
read. The integrity hash pins it, so it
can't change unless you change this code. A new version is a new file.
<script
src="https://embed.bindkit.ai/sandbox/v1.js"
integrity="sha384-2VbLCbCIJte2RR8a9Lq71Ho9PAvgYyMsa3YNK9XV0WRM5UX0xjmkqVxlRkBovhn/"
crossorigin="anonymous"
></script>
<script>
BindKit.messenger({
publishableKey: 'pk_...',
userToken: () => fetch('/bindkit-token').then((r) => r.text()),
// Keeps your page's address and title from the agent.
page: false,
})
</script>
The frame is as big as the window and clipped to the messenger, so the rest of your page still takes
clicks. Only your page's BindKit.* calls and its address and title reach the frame. It hears
the shortcut, never what the visitor types.
What's different
| Feature | In the sandbox |
|---|---|
BindKit.knowledgeBase() |
Not available: it draws into your page. |
A component's render |
Ignored, as your page can't draw inside the frame. The component's code from the dashboard draws it, in a frame of its own with no network access. |
A component's onAction |
Runs on your page, with the loader. Its values have to fit in JSON. |
| Your font | The frame can't use your page's fonts, so set one for the agent in the dashboard. |
| Saved conversations | Kept per site, as before, in storage of the frame's own. |