JavaScript API
The script exposes window.digitornChat. You can call it as soon as the tag has
run — calls made before the widget finishes loading are queued and replayed, so
you never have to wait for a "ready" event to use it.
Control the widget
digitornChat.open(); // open the panel
digitornChat.close(); // close it
digitornChat.toggle(); // toggle
digitornChat.isOpen(); // → boolean
digitornChat.destroy(); // remove the widget entirely (for SPA teardown)
Events
const off = digitornChat.on("open", () => console.log("chat opened"));
// events: "open" | "close" | "ready"
off(); // unsubscribe
Tell the agent about the visitor and the page
This is what turns the widget from a generic chatbot into an agent embedded in your app: you tell it who it's talking to and where they are, and it uses that in the conversation.
// Who the visitor is
digitornChat.identify({ name: "Awa", email: "awa@acme.com", id: "u_123" });
// The page and any app state worth knowing
digitornChat.setContext({
page: { url: location.href, title: "Invoice #1024" },
data: { plan: "Pro", cartItems: 3 }
});
identify(user)— shorthand forsetContext({ user }): the visitor's name / email / id (or anything else).identify(null)forgets them, e.g. when they sign out of your site.identify({ token })— a token signed by your server makes the visitor a verified user, the same on every device. See Visitors & verified users. The token goes to Digitorn only, never to the agent.setContext({ user, page, data })— any subset. Anything that isn'tuser/page/datais treated asdata.- The current page is filled in automatically (its URL and title — your own site), so the agent always knows where the visitor is even if you call nothing.
The agent receives this each turn, as context like:
Context from the app that embeds you (about the current visitor): Visitor: Awa
<awa@acme.com>· Current page: Invoice #1024 (…) · App data: plan=Pro; cartItems=3
It's live
Call setContext again whenever things change — the visitor navigates, logs in,
adds to their cart — and the agent sees the updated context on its next reply.
A good pattern in a single-page app is to call it on every route change:
router.afterEach((to) => {
digitornChat.setContext({ page: { url: location.href, title: document.title } });
});
This context is declared by your site, so it's perfect for personalisation and knowing where the visitor is — but it is not proof of identity. The agent is told not to rely on it for sensitive or account-specific actions without verification. For proof, use a signed token.